Adding JOIN_ROOM message in protobuf
This commit is contained in:
parent
72806b3ca0
commit
2dad601311
@ -27,7 +27,7 @@ import {
|
|||||||
SetPlayerDetailsMessage,
|
SetPlayerDetailsMessage,
|
||||||
SubMessage,
|
SubMessage,
|
||||||
UserMovedMessage,
|
UserMovedMessage,
|
||||||
BatchMessage, GroupUpdateMessage, PointMessage, GroupDeleteMessage
|
BatchMessage, GroupUpdateMessage, PointMessage, GroupDeleteMessage, UserJoinedMessage
|
||||||
} 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;
|
||||||
@ -541,9 +541,17 @@ export class IoSocketController {
|
|||||||
const clientListener = this.searchClientByIdOrFail(listener.id);
|
const clientListener = this.searchClientByIdOrFail(listener.id);
|
||||||
if (thing instanceof User) {
|
if (thing instanceof User) {
|
||||||
const clientUser = this.searchClientByIdOrFail(thing.id);
|
const clientUser = this.searchClientByIdOrFail(thing.id);
|
||||||
const messageUserJoined = new MessageUserJoined(clientUser.userId, clientUser.name, clientUser.characterLayers, clientUser.position);
|
|
||||||
|
|
||||||
clientListener.emit(SocketIoEvent.JOIN_ROOM, messageUserJoined);
|
const userJoinedMessage = new UserJoinedMessage();
|
||||||
|
userJoinedMessage.setUserid(clientUser.userId);
|
||||||
|
userJoinedMessage.setName(clientUser.name);
|
||||||
|
userJoinedMessage.setCharacterlayersList(clientUser.characterLayers);
|
||||||
|
userJoinedMessage.setPosition(ProtobufUtils.toPositionMessage(clientUser.position));
|
||||||
|
|
||||||
|
const subMessage = new SubMessage();
|
||||||
|
subMessage.setUserjoinedmessage(userJoinedMessage);
|
||||||
|
|
||||||
|
emitInBatch(clientListener, SocketIoEvent.JOIN_ROOM, subMessage);
|
||||||
} else if (thing instanceof Group) {
|
} else if (thing instanceof Group) {
|
||||||
this.emitCreateUpdateGroupEvent(clientListener, thing);
|
this.emitCreateUpdateGroupEvent(clientListener, thing);
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,7 +4,7 @@ import {MessageUI} from "./Logger/MessageUI";
|
|||||||
import {
|
import {
|
||||||
BatchMessage, GroupDeleteMessage, GroupUpdateMessage,
|
BatchMessage, GroupDeleteMessage, GroupUpdateMessage,
|
||||||
PositionMessage,
|
PositionMessage,
|
||||||
SetPlayerDetailsMessage, UserMovedMessage,
|
SetPlayerDetailsMessage, UserJoinedMessage, UserMovedMessage,
|
||||||
UserMovesMessage,
|
UserMovesMessage,
|
||||||
ViewportMessage
|
ViewportMessage
|
||||||
} from "./Messages/generated/messages_pb"
|
} from "./Messages/generated/messages_pb"
|
||||||
@ -15,6 +15,7 @@ import {PlayerAnimationNames} from "./Phaser/Player/Animation";
|
|||||||
import {UserSimplePeerInterface} from "./WebRtc/SimplePeer";
|
import {UserSimplePeerInterface} from "./WebRtc/SimplePeer";
|
||||||
import {SignalData} from "simple-peer";
|
import {SignalData} from "simple-peer";
|
||||||
import Direction = PositionMessage.Direction;
|
import Direction = PositionMessage.Direction;
|
||||||
|
import {ProtobufClientUtils} from "./Network/ProtobufClientUtils";
|
||||||
|
|
||||||
enum EventMessage{
|
enum EventMessage{
|
||||||
WEBRTC_SIGNAL = "webrtc-signal",
|
WEBRTC_SIGNAL = "webrtc-signal",
|
||||||
@ -166,6 +167,9 @@ export class Connection implements Connection {
|
|||||||
} else if (message.hasGroupdeletemessage()) {
|
} else if (message.hasGroupdeletemessage()) {
|
||||||
event = EventMessage.GROUP_DELETE;
|
event = EventMessage.GROUP_DELETE;
|
||||||
payload = message.getGroupdeletemessage();
|
payload = message.getGroupdeletemessage();
|
||||||
|
} else if (message.hasUserjoinedmessage()) {
|
||||||
|
event = EventMessage.JOIN_ROOM;
|
||||||
|
payload = message.getUserjoinedmessage();
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Unexpected batch message type');
|
throw new Error('Unexpected batch message type');
|
||||||
}
|
}
|
||||||
@ -283,7 +287,19 @@ export class Connection implements Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onUserJoins(callback: (message: MessageUserJoined) => void): void {
|
public onUserJoins(callback: (message: MessageUserJoined) => void): void {
|
||||||
this.socket.on(EventMessage.JOIN_ROOM, callback);
|
this.onBatchMessage(EventMessage.JOIN_ROOM, (message: UserJoinedMessage) => {
|
||||||
|
const position = message.getPosition();
|
||||||
|
if (position === undefined) {
|
||||||
|
throw new Error('Invalid JOIN_ROOM message');
|
||||||
|
}
|
||||||
|
const messageUserJoined: MessageUserJoined = {
|
||||||
|
userId: message.getUserid(),
|
||||||
|
name: message.getName(),
|
||||||
|
characterLayers: message.getCharacterlayersList(),
|
||||||
|
position: ProtobufClientUtils.toPointInterface(position)
|
||||||
|
}
|
||||||
|
callback(messageUserJoined);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public onUserMoved(callback: (message: UserMovedMessage) => void): void {
|
public onUserMoved(callback: (message: UserMovedMessage) => void): void {
|
||||||
|
@ -52,6 +52,7 @@ message SubMessage {
|
|||||||
UserMovedMessage userMovedMessage = 1;
|
UserMovedMessage userMovedMessage = 1;
|
||||||
GroupUpdateMessage groupUpdateMessage = 2;
|
GroupUpdateMessage groupUpdateMessage = 2;
|
||||||
GroupDeleteMessage groupDeleteMessage = 3;
|
GroupDeleteMessage groupDeleteMessage = 3;
|
||||||
|
UserJoinedMessage userJoinedMessage = 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,3 +69,10 @@ message GroupUpdateMessage {
|
|||||||
message GroupDeleteMessage {
|
message GroupDeleteMessage {
|
||||||
int32 groupId = 1;
|
int32 groupId = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message UserJoinedMessage {
|
||||||
|
int32 userId = 1;
|
||||||
|
string name = 2;
|
||||||
|
repeated string characterLayers = 3;
|
||||||
|
PositionMessage position = 4;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user