Skip to content

Commit c8e5a6a

Browse files
committed
WIP: Simplifying global event model to discourage bad design decisions - Preparing for iocluster upgrade.
1 parent a277190 commit c8e5a6a

File tree

5 files changed

+8
-19
lines changed

5 files changed

+8
-19
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ module.exports.run = function (worker) {
222222
console.log('Socket ' + socket.id + ' was disconnected');
223223
});
224224

225-
wsServer.on('sessiondestroy', function (ssid) {
225+
wsServer.on('sessionend', function (ssid) {
226226
delete activeSessions[ssid];
227227
});
228228

@@ -248,24 +248,17 @@ On the current session (this is the recommended way; accounts for multiple open
248248
socket.session.emit('foo', eventData, callback);
249249
```
250250

251-
On a specific session (possibly hosted on a different worker process):
252-
```js
253-
// Function signature: emit(sessionId, event, data, callback)
254-
socket.global.emit('localhost_9101_8000_0_47kR_u7W4LGk56rSAAAA', 'foo', eventData, callback);
255-
```
256-
^ Generally, you should avoid targeting clients explicitly - Instead, you should use a pub/sub approach using global events and middleware for auth.
257-
258-
Broadcast to all interested sockets/sessions (on all worker processes):
251+
Broadcast to all subscribed sockets/sessions (on all worker processes):
259252
```js
260253
socket.global.broadcast('foo', eventData, callback);
261254
```
262255

263-
Broadcast to all interested sockets/session (this time we access the global object directly from the SCServer instance):
256+
Broadcast to all subscribed sockets/session (this time we access the global object directly from the SCServer instance):
264257
```js
265258
wsServer.global.broadcast('foo', eventData, callback);
266259
```
267260

268-
Note that when you broadcast an event, only the clients which are actually subscribed tp that particular event
261+
Note that when you broadcast an event, only the clients which are actually subscribed to that particular event
269262
will receive it. SocketCluster is efficient and works more like a pub/sub system.
270263
When you listen to an even on the client using socket.on(...), it will send a 'subscribe' event to the backend which
271264
may be intercepted/blocked by your middleware if appropriate.

sample/worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports.run = function (worker) {
4343
});
4444
});
4545

46-
wsServer.on('sessiondestroy', function (ssid) {
46+
wsServer.on('sessionend', function (ssid) {
4747
delete activeSessions[ssid];
4848
});
4949

test/external/worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports.run = function (worker) {
3535
});
3636
});
3737

38-
wsServer.on('sessiondestroy', function (ssid) {
38+
wsServer.on('sessionend', function (ssid) {
3939
delete activeSessions[ssid];
4040
});
4141
};

test/internal/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var socketCluster = new SocketCluster({
1212
addressSocketLimit: 0,
1313
socketEventLimit: 100,
1414
rebootWorkerOnCrash: true,
15-
useSmartBalancing: false,
15+
useSmartBalancing: true,
1616
sessionTimeout: 20
1717
});
1818

test/internal/worker.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ module.exports.run = function (worker) {
2727
affect all sockets which belong to that session.
2828
*/
2929
activeSessions[socket.session.id] = socket.session;
30-
31-
socket.on('test', function (data) {
32-
// TODO: Fix this
33-
});
3430
});
3531

36-
wsServer.on('sessiondestroy', function (ssid) {
32+
wsServer.on('sessionend', function (ssid) {
3733
delete activeSessions[ssid];
3834
});
3935
};

0 commit comments

Comments
 (0)