redweb 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ws/BaseSocketServer.js +18 -0
package/package.json
CHANGED
|
@@ -23,6 +23,15 @@ const SOCKET_OPTIONS = {
|
|
|
23
23
|
ssl: null
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param {BaseSocketServer} socketServer
|
|
29
|
+
* @param {Object} message
|
|
30
|
+
*/
|
|
31
|
+
function broadcast(socketServer, message) {
|
|
32
|
+
socketServer.clients.forEach(client => client.send(JSON.stringify(message)));
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
class BaseSocketServer {
|
|
27
36
|
/**
|
|
28
37
|
* Base Socket Server
|
|
@@ -72,6 +81,15 @@ class BaseSocketServer {
|
|
|
72
81
|
handleError(socket, error, ip) {
|
|
73
82
|
console.error(`Socket error from ${ip}:`, error);
|
|
74
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* This sends the same message to all clients.
|
|
88
|
+
* @param {Object} message
|
|
89
|
+
*/
|
|
90
|
+
broadcast(message) {
|
|
91
|
+
broadcast(this, message);
|
|
92
|
+
}
|
|
75
93
|
}
|
|
76
94
|
|
|
77
95
|
module.exports = {BaseSocketServer, SOCKET_OPTIONS};
|