Adding USER_LEFT message to protobuf

This commit is contained in:
David Négrier 2020-09-24 16:11:47 +02:00
parent 2dad601311
commit 0c4c43f88c
3 changed files with 25 additions and 5 deletions

View File

@ -27,7 +27,7 @@ import {
SetPlayerDetailsMessage, SetPlayerDetailsMessage,
SubMessage, SubMessage,
UserMovedMessage, UserMovedMessage,
BatchMessage, GroupUpdateMessage, PointMessage, GroupDeleteMessage, UserJoinedMessage BatchMessage, GroupUpdateMessage, PointMessage, GroupDeleteMessage, UserJoinedMessage, UserLeftMessage
} 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;
@ -580,8 +580,7 @@ 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);
clientListener.emit(SocketIoEvent.USER_LEFT, clientUser.userId); this.emitUserLeftEvent(clientListener, clientUser.userId);
//console.log("Sending USER_LEFT event");
} else if (thing instanceof Group) { } else if (thing instanceof Group) {
this.emitDeleteGroupEvent(clientListener, thing.getId()); this.emitDeleteGroupEvent(clientListener, thing.getId());
} else { } else {
@ -629,6 +628,17 @@ export class IoSocketController {
emitInBatch(client, SocketIoEvent.GROUP_DELETE, subMessage); emitInBatch(client, SocketIoEvent.GROUP_DELETE, subMessage);
} }
private emitUserLeftEvent(socket: Socket, userId: number): void {
const userLeftMessage = new UserLeftMessage();
userLeftMessage.setUserid(userId);
const subMessage = new SubMessage();
subMessage.setUserleftmessage(userLeftMessage);
const client : ExSocketInterface = socket as ExSocketInterface;
emitInBatch(client, SocketIoEvent.USER_LEFT, subMessage);
}
/** /**
* *
* @param socket * @param socket

View File

@ -4,7 +4,7 @@ import {MessageUI} from "./Logger/MessageUI";
import { import {
BatchMessage, GroupDeleteMessage, GroupUpdateMessage, BatchMessage, GroupDeleteMessage, GroupUpdateMessage,
PositionMessage, PositionMessage,
SetPlayerDetailsMessage, UserJoinedMessage, UserMovedMessage, SetPlayerDetailsMessage, UserJoinedMessage, UserLeftMessage, UserMovedMessage,
UserMovesMessage, UserMovesMessage,
ViewportMessage ViewportMessage
} from "./Messages/generated/messages_pb" } from "./Messages/generated/messages_pb"
@ -170,6 +170,9 @@ export class Connection implements Connection {
} else if (message.hasUserjoinedmessage()) { } else if (message.hasUserjoinedmessage()) {
event = EventMessage.JOIN_ROOM; event = EventMessage.JOIN_ROOM;
payload = message.getUserjoinedmessage(); payload = message.getUserjoinedmessage();
} else if (message.hasUserleftmessage()) {
event = EventMessage.USER_LEFT;
payload = message.getUserleftmessage();
} else { } else {
throw new Error('Unexpected batch message type'); throw new Error('Unexpected batch message type');
} }
@ -320,7 +323,9 @@ export class Connection implements Connection {
} }
public onUserLeft(callback: (userId: number) => void): void { public onUserLeft(callback: (userId: number) => void): void {
this.socket.on(EventMessage.USER_LEFT, callback); this.onBatchMessage(EventMessage.USER_LEFT, (message: UserLeftMessage) => {
callback(message.getUserid());
});
} }
public onGroupUpdatedOrCreated(callback: (groupCreateUpdateMessage: GroupCreatedUpdatedMessageInterface) => void): void { public onGroupUpdatedOrCreated(callback: (groupCreateUpdateMessage: GroupCreatedUpdatedMessageInterface) => void): void {

View File

@ -53,6 +53,7 @@ message SubMessage {
GroupUpdateMessage groupUpdateMessage = 2; GroupUpdateMessage groupUpdateMessage = 2;
GroupDeleteMessage groupDeleteMessage = 3; GroupDeleteMessage groupDeleteMessage = 3;
UserJoinedMessage userJoinedMessage = 4; UserJoinedMessage userJoinedMessage = 4;
UserLeftMessage userLeftMessage = 5;
} }
} }
@ -76,3 +77,7 @@ message UserJoinedMessage {
repeated string characterLayers = 3; repeated string characterLayers = 3;
PositionMessage position = 4; PositionMessage position = 4;
} }
message UserLeftMessage {
int32 userId = 1;
}