Create webrtc connexion between two player
This commit is contained in:
parent
0f2e21e88e
commit
5b62ac39fb
13 changed files with 769 additions and 8 deletions
|
@ -74,6 +74,36 @@ export class IoSocketController{
|
|||
let rooms = (this.Io.sockets.adapter.rooms as ExtRoomsInterface)
|
||||
rooms.refreshUserPosition(rooms, this.Io);
|
||||
});
|
||||
|
||||
socket.on('webrtc-room', (message : string) => {
|
||||
let data = JSON.parse(message);
|
||||
socket.join(data.roomId);
|
||||
(socket as ExSocketInterface).roomId = data.roomId;
|
||||
|
||||
//if two persone in room share
|
||||
if(this.Io.sockets.adapter.rooms[data.roomId].length < 2) {
|
||||
return;
|
||||
}
|
||||
let clients : Array<any> = Object.values(this.Io.sockets.sockets);
|
||||
|
||||
//send start at one client to initialise offer webrtc
|
||||
clients[0].emit('webrtc-start');
|
||||
});
|
||||
|
||||
socket.on('video-offer', (message : string) => {
|
||||
let data : any = JSON.parse(message);
|
||||
socket.to(data.roomId).emit('video-offer', message);
|
||||
});
|
||||
|
||||
socket.on('video-answer', (message : string) => {
|
||||
let data : any = JSON.parse(message);
|
||||
socket.to(data.roomId).emit('video-answer', message);
|
||||
});
|
||||
|
||||
socket.on('ice-candidate', (message : string) => {
|
||||
let data : any = JSON.parse(message);
|
||||
socket.to(data.roomId).emit('ice-candidate', message);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue