Connect and Disconnect event.
This commit is contained in:
parent
8357f9b8c2
commit
372f938bbb
@ -25,6 +25,7 @@ enum SockerIoEvent {
|
||||
export class IoSocketController {
|
||||
Io: socketIO.Server;
|
||||
World: World;
|
||||
|
||||
constructor(server: http.Server) {
|
||||
this.Io = socketIO(server);
|
||||
|
||||
@ -125,9 +126,7 @@ export class IoSocketController{
|
||||
|
||||
socket.on(SockerIoEvent.DISCONNECT, () => {
|
||||
let Client = (socket as ExSocketInterface);
|
||||
socket.broadcast.emit(SockerIoEvent.WEBRTC_DISCONNECT, JSON.stringify({
|
||||
userId: Client.userId
|
||||
}));
|
||||
this.sendDisconnectedEvent(Client);
|
||||
|
||||
//refresh position of all user in all rooms in real time
|
||||
this.refreshUserPosition();
|
||||
@ -164,6 +163,17 @@ export class IoSocketController{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Client: ExSocketInterface
|
||||
*/
|
||||
sendDisconnectedEvent(Client: ExSocketInterface) {
|
||||
Client.broadcast.emit(SockerIoEvent.WEBRTC_DISCONNECT, JSON.stringify({
|
||||
userId: Client.userId
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param socket
|
||||
@ -243,6 +253,7 @@ export class IoSocketController{
|
||||
]
|
||||
**/
|
||||
seTimeOutInProgress: any = null;
|
||||
|
||||
shareUsersPosition() {
|
||||
if (this.seTimeOutInProgress) {
|
||||
clearTimeout(this.seTimeOutInProgress);
|
||||
@ -265,27 +276,20 @@ export class IoSocketController{
|
||||
}
|
||||
|
||||
//connected user
|
||||
connectedUser(user1 : string, user2 : string, group : Group) {
|
||||
if(!group){
|
||||
connectedUser(userId: string, group: Group) {
|
||||
let Client = this.searchClientById(userId);
|
||||
if (!Client) {
|
||||
return;
|
||||
}
|
||||
/* TODO manager room and group user to enter and leave */
|
||||
let clients: Array<any> = Object.values(this.Io.sockets.sockets);
|
||||
let User1 = clients.find((user: ExSocketInterface) => user.userId === user1);
|
||||
let User2 = clients.find((user: ExSocketInterface) => user.userId === user2);
|
||||
|
||||
if (User1) {
|
||||
this.joinWebRtcRoom(User1, group.getId());
|
||||
}
|
||||
if (User2) {
|
||||
this.joinWebRtcRoom(User2, group.getId());
|
||||
}
|
||||
this.joinWebRtcRoom(Client, group.getId());
|
||||
}
|
||||
|
||||
//connected user
|
||||
disConnectedUser(user1 : string, user2 : string, group : Group){
|
||||
console.log("disConnectedUser => user1", user1);
|
||||
console.log("disConnectedUser => user2", user2);
|
||||
console.log("group", group);
|
||||
disConnectedUser(userId: string, group: Group) {
|
||||
let Client = this.searchClientById(userId);
|
||||
if (!Client) {
|
||||
return;
|
||||
}
|
||||
this.sendDisconnectedEvent(Client)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user