redweb 0.4.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redweb",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "A way to quickly set up an express server",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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,9 +81,14 @@ class BaseSocketServer {
72
81
  handleError(socket, error, ip) {
73
82
  console.error(`Socket error from ${ip}:`, error);
74
83
  }
75
-
76
- broadcast(type, data) {
77
- this.clients.forEach(client => client.send(JSON.stringify({type, data})));
84
+
85
+ /**
86
+ *
87
+ * This sends the same message to all clients.
88
+ * @param {Object} message
89
+ */
90
+ broadcast(message) {
91
+ broadcast(this, message);
78
92
  }
79
93
  }
80
94