Switching SetViewport to protobuf
This commit is contained in:
parent
24a6cd7f8e
commit
ac80850335
@ -19,7 +19,6 @@ import {isWebRtcSignalMessageInterface} from "../Model/Websocket/WebRtcSignalMes
|
|||||||
import {UserInGroupInterface} from "../Model/Websocket/UserInGroupInterface";
|
import {UserInGroupInterface} from "../Model/Websocket/UserInGroupInterface";
|
||||||
import {isItemEventMessageInterface} from "../Model/Websocket/ItemEventMessage";
|
import {isItemEventMessageInterface} from "../Model/Websocket/ItemEventMessage";
|
||||||
import {uuid} from 'uuidv4';
|
import {uuid} from 'uuidv4';
|
||||||
import {isViewport} from "../Model/Websocket/ViewportMessage";
|
|
||||||
import {GroupUpdateInterface} from "_Model/Websocket/GroupUpdateInterface";
|
import {GroupUpdateInterface} from "_Model/Websocket/GroupUpdateInterface";
|
||||||
import {Movable} from "../Model/Movable";
|
import {Movable} from "../Model/Movable";
|
||||||
import {
|
import {
|
||||||
@ -33,7 +32,7 @@ import {
|
|||||||
GroupDeleteMessage,
|
GroupDeleteMessage,
|
||||||
UserJoinedMessage,
|
UserJoinedMessage,
|
||||||
UserLeftMessage,
|
UserLeftMessage,
|
||||||
ItemEventMessage
|
ItemEventMessage, ViewportMessage
|
||||||
} from "../Messages/generated/messages_pb";
|
} from "../Messages/generated/messages_pb";
|
||||||
import {UserMovesMessage} from "../Messages/generated/messages_pb";
|
import {UserMovesMessage} from "../Messages/generated/messages_pb";
|
||||||
import Direction = PositionMessage.Direction;
|
import Direction = PositionMessage.Direction;
|
||||||
@ -264,15 +263,17 @@ export class IoSocketController {
|
|||||||
|
|
||||||
socket.on(SocketIoEvent.SET_VIEWPORT, (message: unknown): void => {
|
socket.on(SocketIoEvent.SET_VIEWPORT, (message: unknown): void => {
|
||||||
try {
|
try {
|
||||||
//console.log('SET_VIEWPORT')
|
if (!(message instanceof Buffer)) {
|
||||||
if (!isViewport(message)) {
|
socket.emit(SocketIoEvent.MESSAGE_ERROR, {message: 'Invalid SET_VIEWPORT message. Expecting binary buffer.'});
|
||||||
socket.emit(SocketIoEvent.MESSAGE_ERROR, {message: 'Invalid SET_VIEWPORT message.'});
|
console.warn('Invalid SET_VIEWPORT message received (expecting binary buffer): ', message);
|
||||||
console.warn('Invalid SET_VIEWPORT message received: ', message);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const viewportMessage = ViewportMessage.deserializeBinary(new Uint8Array(message as ArrayBuffer));
|
||||||
|
const viewport = viewportMessage.toObject();
|
||||||
|
|
||||||
const Client = (socket as ExSocketInterface);
|
const Client = (socket as ExSocketInterface);
|
||||||
Client.viewport = message;
|
Client.viewport = viewport;
|
||||||
|
|
||||||
const world = this.Worlds.get(Client.roomId);
|
const world = this.Worlds.get(Client.roomId);
|
||||||
if (!world) {
|
if (!world) {
|
||||||
|
@ -289,7 +289,13 @@ export class Connection implements Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public setViewport(viewport: ViewportInterface): void {
|
public setViewport(viewport: ViewportInterface): void {
|
||||||
this.socket.emit(EventMessage.SET_VIEWPORT, viewport);
|
const viewportMessage = new ViewportMessage();
|
||||||
|
viewportMessage.setTop(Math.round(viewport.top));
|
||||||
|
viewportMessage.setBottom(Math.round(viewport.bottom));
|
||||||
|
viewportMessage.setLeft(Math.round(viewport.left));
|
||||||
|
viewportMessage.setRight(Math.round(viewport.right));
|
||||||
|
|
||||||
|
this.socket.emit(EventMessage.SET_VIEWPORT, viewportMessage.serializeBinary().buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public onUserJoins(callback: (message: MessageUserJoined) => void): void {
|
public onUserJoins(callback: (message: MessageUserJoined) => void): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user