@iobroker/socket-classes 0.3.2 → 0.4.0
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/README.md +3 -0
- package/lib/socketAdmin.js +15 -5
- package/lib/socketCommands.js +2 -2
- package/lib/socketCommon.js +21 -7
- package/package.json +1 -1
package/README.md
CHANGED
package/lib/socketAdmin.js
CHANGED
|
@@ -141,21 +141,27 @@ class SocketAdmin extends SocketCommon {
|
|
|
141
141
|
this.commands.stateChange(id, state);
|
|
142
142
|
|
|
143
143
|
if (this.server && this.server.sockets) {
|
|
144
|
-
this.server.sockets.connected
|
|
144
|
+
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
145
|
+
|
|
146
|
+
sockets.forEach(socket =>
|
|
145
147
|
this.commands.publish(socket, 'stateChange', id, state));
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
fileChange(id, fileName, size) {
|
|
150
152
|
if (this.server && this.server.sockets) {
|
|
151
|
-
this.server.sockets.connected
|
|
153
|
+
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
154
|
+
|
|
155
|
+
sockets.forEach(socket =>
|
|
152
156
|
this.commands.publishFile(socket, id, fileName, size));
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
159
|
|
|
156
160
|
repoUpdated() {
|
|
157
161
|
if (this.server && this.server.sockets) {
|
|
158
|
-
this.server.sockets.connected
|
|
162
|
+
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
163
|
+
|
|
164
|
+
sockets.forEach(socket =>
|
|
159
165
|
this.__updateSession(socket));
|
|
160
166
|
|
|
161
167
|
this.server.sockets.emit('repoUpdated');
|
|
@@ -164,7 +170,9 @@ class SocketAdmin extends SocketCommon {
|
|
|
164
170
|
|
|
165
171
|
objectChange(id, obj) {
|
|
166
172
|
if (this.server && this.server.sockets) {
|
|
167
|
-
this.server.sockets.connected
|
|
173
|
+
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
174
|
+
|
|
175
|
+
sockets.forEach(socket =>
|
|
168
176
|
this.commands.publish(socket, 'objectChange', id, obj));
|
|
169
177
|
}
|
|
170
178
|
}
|
|
@@ -179,7 +187,9 @@ class SocketAdmin extends SocketCommon {
|
|
|
179
187
|
|
|
180
188
|
sendCommand(obj) {
|
|
181
189
|
if (this.commands.sendCommand(obj) && this.server && this.server.sockets) {
|
|
182
|
-
this.server.sockets.connected
|
|
190
|
+
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
191
|
+
|
|
192
|
+
sockets.forEach(socket =>
|
|
183
193
|
this.__updateSession(socket));
|
|
184
194
|
|
|
185
195
|
this.server.sockets.emit(obj.command, obj.message.id, obj.message.data);
|
package/lib/socketCommands.js
CHANGED
|
@@ -630,8 +630,8 @@ class SocketCommands {
|
|
|
630
630
|
zipFiles
|
|
631
631
|
.writeDirAsZip(
|
|
632
632
|
this.adapter, // normally we have to pass here the internal "objects" object, but as
|
|
633
|
-
|
|
634
|
-
|
|
633
|
+
// only writeFile is used, and it has the same name we can pass here the
|
|
634
|
+
// adapter, which has the function with the same name and arguments
|
|
635
635
|
message.id,
|
|
636
636
|
message.name,
|
|
637
637
|
Buffer.from(message.data, 'base64'),
|
package/lib/socketCommon.js
CHANGED
|
@@ -67,7 +67,14 @@ class SocketCommon {
|
|
|
67
67
|
// it can be used as client too for cloud
|
|
68
68
|
if (socketClass) {
|
|
69
69
|
if (!server.__inited) {
|
|
70
|
-
|
|
70
|
+
if (typeof socketClass.listen === 'function') {
|
|
71
|
+
// old socket.io@2.x and ws
|
|
72
|
+
this.server = socketClass.listen(server, socketOptions);
|
|
73
|
+
} else {
|
|
74
|
+
// socket.io 4.x
|
|
75
|
+
this.server = socketClass(server, socketOptions);
|
|
76
|
+
}
|
|
77
|
+
|
|
71
78
|
server.__inited = true;
|
|
72
79
|
this.adapter.log.info(`${this.settings.secure ? 'Secure ' : ''}socket.io server listening on port ${this.settings.port}`);
|
|
73
80
|
}
|
|
@@ -77,6 +84,7 @@ class SocketCommon {
|
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
// Enable cross domain access
|
|
87
|
+
// deprecated, because no more used in socket.io@4 only(in @2)
|
|
80
88
|
if (this.settings.crossDomain && this.server.set) {
|
|
81
89
|
this.server.set('origins', '*:*');
|
|
82
90
|
}
|
|
@@ -141,8 +149,10 @@ class SocketCommon {
|
|
|
141
149
|
_unsubscribeAll() {
|
|
142
150
|
if (this.server && this.server.ioBroker) {
|
|
143
151
|
// this could be an object or array
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
153
|
+
|
|
154
|
+
Object.keys(sockets).forEach(i =>
|
|
155
|
+
this.commands.unsubscribeSocket(sockets[i]));
|
|
146
156
|
} else
|
|
147
157
|
if (this.server && this.server.sockets) {
|
|
148
158
|
for (const socket in this.server.sockets) {
|
|
@@ -320,8 +330,10 @@ class SocketCommon {
|
|
|
320
330
|
let clientsArray = [];
|
|
321
331
|
if (this.server.sockets) {
|
|
322
332
|
// this could be an object or array
|
|
323
|
-
|
|
324
|
-
|
|
333
|
+
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
334
|
+
|
|
335
|
+
Object.keys(sockets).forEach(i =>
|
|
336
|
+
clientsArray.push(sockets[i]._name || 'noname'));
|
|
325
337
|
}
|
|
326
338
|
const text = `[${clientsArray.length}]${clientsArray.join(', ')}`;
|
|
327
339
|
this.adapter.setState('info.connected', text, true);
|
|
@@ -360,8 +372,10 @@ class SocketCommon {
|
|
|
360
372
|
|
|
361
373
|
if (this.server && this.server.sockets) {
|
|
362
374
|
// this could be an object or array
|
|
363
|
-
|
|
364
|
-
|
|
375
|
+
const sockets = this.server.sockets.sockets || this.server.sockets.connected;
|
|
376
|
+
|
|
377
|
+
Object.keys(sockets).forEach(i => {
|
|
378
|
+
const socket = sockets[i];
|
|
365
379
|
if (socket._sessionTimer) {
|
|
366
380
|
clearTimeout(socket._sessionTimer);
|
|
367
381
|
socket._sessionTimer = null;
|