Nextrek
Diff Revisions
1124
vs
1125
for /socketIO/index.js
|
@@ -60,19 +60,18 @@ |
60 |
60 |
|
const ROLES = Chat.ROLES; |
61 |
61 |
|
const DEFAULT_ROOMS = Chat.DEFAULT_ROOMS; |
62 |
62 |
|
let event = ''; |
63 |
|
- |
|
64 |
|
- |
const buf = crypto.randomBytes(64); |
65 |
|
- |
const uniqID = buf.toString('hex'); |
66 |
|
- |
|
|
63 |
+ |
|
67 |
64 |
|
event = Chat.event(EVENTS.CONNECTION.OPEN); |
68 |
65 |
|
io.emit(event.type, event.data); |
69 |
|
- |
|
70 |
|
- |
|
|
66 |
+ |
|
|
67 |
+ |
|
71 |
68 |
|
// create user and send updates |
72 |
69 |
|
socket.on(EVENTS.CONNECTION.OPEN, (data) => { |
73 |
70 |
|
console.log('CONNECTION:OPEN', JSON.stringify(data)); |
74 |
|
- |
|
|
71 |
+ |
|
75 |
72 |
|
// create new user |
|
73 |
+ |
const buf = crypto.randomBytes(64); |
|
74 |
+ |
const uniqID = buf.toString('hex'); |
76 |
75 |
|
user = Chat.createUser(data.name, data.role, uniqID); |
77 |
76 |
|
|
78 |
77 |
|
console.log('user', user); |
|
@@ -80,6 +79,10 @@ |
80 |
79 |
|
// join user own room |
81 |
80 |
|
socket.join(user.room); |
82 |
81 |
|
|
|
82 |
+ |
// notify user is ready |
|
83 |
+ |
event = Chat.event(EVENTS.ROOM.CREATED, user); |
|
84 |
+ |
io.to(user.room).emit(event.type, event.data); |
|
85 |
+ |
|
83 |
86 |
|
// join operators room if role is operator |
84 |
87 |
|
if (user.role === ROLES.OPERATOR) { |
85 |
88 |
|
socket.join(DEFAULT_ROOMS.OPERATORS); |
|
@@ -104,7 +107,7 @@ |
104 |
107 |
|
const ownerRoom = Chat.joinOwnerRoom(data.user, user); |
105 |
108 |
|
socket.join(ownerRoom); |
106 |
109 |
|
|
107 |
|
- |
event = Chat.event(EVENTS.ROOM.JOIN, ownerRoom); |
|
110 |
+ |
event = Chat.event(EVENTS.ROOM.JOIN, user); |
108 |
111 |
|
io.to(ownerRoom).emit(event.type, event.data); |
109 |
112 |
|
|
110 |
113 |
|
console.log('join room', user.name, event.data); |