Add io socket message to share user position.
- Add message 'user-position' to share position in a room. - Change JoinRoomMessage to MessageUserPosition to have all data to share position and user information - Fix error alias to build
This commit is contained in:
parent
63dc515c5b
commit
4e1115725b
1
back/.gitignore
vendored
1
back/.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
/dist/
|
||||||
/node_modules/
|
/node_modules/
|
||||||
/dist/bundle.js
|
/dist/bundle.js
|
||||||
/yarn-error.log
|
/yarn-error.log
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import socketIO = require('socket.io');
|
import socketIO = require('socket.io');
|
||||||
import {Socket} from "socket.io";
|
import {Socket} from "socket.io";
|
||||||
import * as http from "http";
|
import * as http from "http";
|
||||||
import {JoinRoomMessage} from "@Model/Websocket/JoinRoomMessage";
|
import {MessageUserPosition} from "@Model/Websocket/MessageUserPosition";
|
||||||
|
|
||||||
export class IoSocketController{
|
export class IoSocketController{
|
||||||
Io: socketIO.Server;
|
Io: socketIO.Server;
|
||||||
@ -21,8 +21,14 @@ export class IoSocketController{
|
|||||||
positionXUser: user x position map
|
positionXUser: user x position map
|
||||||
positionYUser: user y position on map
|
positionYUser: user y position on map
|
||||||
*/
|
*/
|
||||||
socket.on('join-room', (message : JoinRoomMessage) => {
|
socket.on('join-room', (message : MessageUserPosition) => {
|
||||||
socket.join(message.roomId);
|
socket.join(message.roomId);
|
||||||
|
// sending to all clients in room except sender
|
||||||
|
socket.to(message.roomId).emit('join-room', message.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('user-position', (message : MessageUserPosition) => {
|
||||||
|
// sending to all clients in room except sender
|
||||||
socket.to(message.roomId).emit('join-room', message.toString());
|
socket.to(message.roomId).emit('join-room', message.toString());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
export class JoinRoomMessage {
|
|
||||||
userId: string;
|
|
||||||
roomId: string;
|
|
||||||
positionXUser: string;
|
|
||||||
positionYUser: string;
|
|
||||||
|
|
||||||
constructor(message: string) {
|
|
||||||
let data = JSON.parse(message);
|
|
||||||
this.userId = data.userId;
|
|
||||||
this.roomId = data.roomId;
|
|
||||||
this.positionXUser = data.positionXUser;
|
|
||||||
this.positionYUser = data.positionYUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
toString(){
|
|
||||||
return JSON.stringify({
|
|
||||||
userId: this.userId,
|
|
||||||
roomId: this.roomId,
|
|
||||||
positionXUser: this.positionXUser,
|
|
||||||
positionYUser: this.positionYUser
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
17
back/src/Model/Websocket/Message.ts
Normal file
17
back/src/Model/Websocket/Message.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export class Message {
|
||||||
|
userId: string;
|
||||||
|
roomId: string;
|
||||||
|
|
||||||
|
constructor(message: string) {
|
||||||
|
let data = JSON.parse(message);
|
||||||
|
this.userId = data.userId;
|
||||||
|
this.roomId = data.roomId;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson() {
|
||||||
|
return {
|
||||||
|
userId: this.userId,
|
||||||
|
roomId: this.roomId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
back/src/Model/Websocket/MessageUserPosition.ts
Normal file
24
back/src/Model/Websocket/MessageUserPosition.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import {Message} from "./Message";
|
||||||
|
|
||||||
|
export class MessageUserPosition extends Message{
|
||||||
|
positionXUser: string;
|
||||||
|
positionYUser: string;
|
||||||
|
|
||||||
|
constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
let data = JSON.parse(message);
|
||||||
|
this.positionXUser = data.positionXUser;
|
||||||
|
this.positionYUser = data.positionYUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return JSON.stringify(
|
||||||
|
Object.assign(
|
||||||
|
super.toJson(),
|
||||||
|
{
|
||||||
|
positionXUser: this.positionXUser,
|
||||||
|
positionYUser: this.positionYUser
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -40,12 +40,11 @@
|
|||||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||||
|
|
||||||
/* Module Resolution Options */
|
/* Module Resolution Options */
|
||||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */
|
||||||
"baseUrl": "src",
|
|
||||||
"paths": {
|
"paths": {
|
||||||
"@Controller": ["Controller/*"],
|
"@Controller/*": ["src/Controller/*"],
|
||||||
"@Model": ["Model/*"]
|
"@Model/*": ["src/Model/*"]
|
||||||
}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||||
|
Loading…
Reference in New Issue
Block a user