send group userIds to players

This commit is contained in:
Hanusiak Piotr 2022-02-28 13:47:08 +01:00
parent 8d8857011e
commit 724dbc8efa
6 changed files with 44 additions and 4 deletions

View File

@ -147,9 +147,9 @@ export class Group implements Movable {
join(user: User): void {
// Broadcast on the right event
this.connectCallback(user, this);
this.users.add(user);
user.group = this;
this.connectCallback(user, this);
}
leave(user: User): void {

View File

@ -38,6 +38,7 @@ import {
SubToPusherRoomMessage,
SetPlayerDetailsMessage,
PlayerDetailsUpdatedMessage,
GroupUsersUpdateMessage,
} from "../Messages/generated/messages_pb";
import { User, UserSocket } from "../Model/User";
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
@ -265,8 +266,14 @@ export class SocketManager {
if (roomPromise === undefined) {
roomPromise = GameRoom.create(
roomId,
(user: User, group: Group) => this.joinWebRtcRoom(user, group),
(user: User, group: Group) => this.disConnectedUser(user, group),
(user: User, group: Group) => {
this.joinWebRtcRoom(user, group);
this.sendGroupUsersUpdateToGroupMembers(group);
},
(user: User, group: Group) => {
this.disConnectedUser(user, group);
this.sendGroupUsersUpdateToGroupMembers(group);
},
MINIMUM_DISTANCE,
GROUP_RADIUS,
(thing: Movable, fromZone: Zone | null, listener: ZoneSocket) =>
@ -438,6 +445,19 @@ export class SocketManager {
return undefined;
}
private sendGroupUsersUpdateToGroupMembers(group: Group) {
const groupUserUpdateMessage = new GroupUsersUpdateMessage();
groupUserUpdateMessage.setGroupid(group.getId());
groupUserUpdateMessage.setUseridsList(group.getUsers().map((user) => user.id));
const clientMessage = new ServerToClientMessage();
clientMessage.setGroupusersupdatemessage(groupUserUpdateMessage);
group.getUsers().forEach((currentUser: User) => {
currentUser.socket.write(clientMessage);
});
}
private joinWebRtcRoom(user: User, group: Group) {
for (const otherUser of group.getUsers()) {
if (user === otherUser) {

View File

@ -47,6 +47,11 @@ export interface GroupCreatedUpdatedMessageInterface {
groupSize: number;
}
export interface GroupUsersUpdateMessageInterface {
groupId: number;
userIds: number[];
}
export interface WebRtcDisconnectMessageInterface {
userId: number;
}

View File

@ -5,6 +5,7 @@ import type { UserSimplePeerInterface } from "../WebRtc/SimplePeer";
import { ProtobufClientUtils } from "../Network/ProtobufClientUtils";
import type {
GroupCreatedUpdatedMessageInterface,
GroupUsersUpdateMessageInterface,
MessageUserJoined,
PlayGlobalMessageInterface,
PositionInterface,
@ -97,6 +98,9 @@ export class RoomConnection implements RoomConnection {
private readonly _groupUpdateMessageStream = new Subject<GroupCreatedUpdatedMessageInterface>();
public readonly groupUpdateMessageStream = this._groupUpdateMessageStream.asObservable();
private readonly _groupUsersUpdateMessageStream = new Subject<GroupUsersUpdateMessageInterface>();
public readonly groupUsersUpdateMessageStream = this._groupUsersUpdateMessageStream.asObservable();
private readonly _groupDeleteMessageStream = new Subject<GroupDeleteMessageTsProto>();
public readonly groupDeleteMessageStream = this._groupDeleteMessageStream.asObservable();
@ -398,6 +402,12 @@ export class RoomConnection implements RoomConnection {
this._sendJitsiJwtMessageStream.next(message.sendJitsiJwtMessage);
break;
}
case "groupUsersUpdateMessage": {
console.log("GOT GROUP USERS UPDATE MESSAGE");
console.log(message.groupUsersUpdateMessage);
this._groupUsersUpdateMessageStream.next(message.groupUsersUpdateMessage);
break;
}
case "sendUserMessage": {
adminMessagesService.onSendusermessage(message.sendUserMessage);
break;

View File

@ -1976,7 +1976,6 @@ ${escapedMessage}
}
private doShareGroupPosition(groupPositionMessage: GroupCreatedUpdatedMessageInterface) {
console.log(groupPositionMessage);
//delete previous group
this.doDeleteGroup(groupPositionMessage.groupId);

View File

@ -215,6 +215,11 @@ message ItemStateMessage {
string stateJson = 2;
}
message GroupUsersUpdateMessage {
int32 groupId = 1;
repeated int32 userIds = 2;
}
message RoomJoinedMessage {
//repeated UserJoinedMessage user = 1;
//repeated GroupUpdateMessage group = 2;
@ -310,6 +315,7 @@ message ServerToClientMessage {
FollowRequestMessage followRequestMessage = 21;
FollowConfirmationMessage followConfirmationMessage = 22;
FollowAbortMessage followAbortMessage = 23;
GroupUsersUpdateMessage groupUsersUpdateMessage = 24;
}
}