Create backend
- NodeJs - Express - Socket.io - Eslint - TypeScript
This commit is contained in:
parent
c0e75ae07e
commit
ba335aa33d
10 changed files with 2277 additions and 0 deletions
30
back/src/Controller/IoSocketController.ts
Normal file
30
back/src/Controller/IoSocketController.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import socketIO = require('socket.io');
|
||||
import {Socket} from "socket.io";
|
||||
import * as http from "http";
|
||||
import {JoinRoomMessage} from "@Model/Websocket/JoinRoomMessage";
|
||||
|
||||
export class IoSocketController{
|
||||
Io: socketIO.Server;
|
||||
constructor(server : http.Server) {
|
||||
this.Io = socketIO(server);
|
||||
this.ioConnection();
|
||||
}
|
||||
|
||||
ioConnection() {
|
||||
this.Io.on('connection', (socket: Socket) => {
|
||||
//TODO check token access
|
||||
|
||||
/*join-rom event permit to join one room.
|
||||
message :
|
||||
userId : user identification
|
||||
roomId: room identification
|
||||
positionXUser: user x position map
|
||||
positionYUser: user y position on map
|
||||
*/
|
||||
socket.on('join-room', (message : JoinRoomMessage) => {
|
||||
socket.join(message.roomId);
|
||||
socket.to(message.roomId).emit('join-room', message.toString());
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue