@iobroker/socket-classes 0.4.2 → 0.4.5
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 +9 -0
- package/lib/socketCommands.js +33 -0
- package/lib/socketCommandsAdmin.js +0 -29
- package/lib/socketCommon.js +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,6 +69,15 @@ io.close();
|
|
|
69
69
|
-->
|
|
70
70
|
|
|
71
71
|
## Changelog
|
|
72
|
+
### 0.4.5 (2022-06-20)
|
|
73
|
+
* (bluefox) allow to run socket.io behind reverse proxy
|
|
74
|
+
|
|
75
|
+
### 0.4.4 (2022-06-09)
|
|
76
|
+
* (bluefox) Do not show requireLog message
|
|
77
|
+
|
|
78
|
+
### 0.4.3 (2022-06-03)
|
|
79
|
+
* (bluefox) Allowed call of getAdapterInstances for non admin
|
|
80
|
+
|
|
72
81
|
### 0.4.2 (2022-05-23)
|
|
73
82
|
* (bluefox) Corrected renameFile command for admin
|
|
74
83
|
|
package/lib/socketCommands.js
CHANGED
|
@@ -253,6 +253,10 @@ class SocketCommands {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
+
isLogEnabled() {
|
|
257
|
+
return this.logEnabled;
|
|
258
|
+
}
|
|
259
|
+
|
|
256
260
|
subscribe(socket, type, pattern, patternFile) {
|
|
257
261
|
this.subscribes[type] = this.subscribes[type] || {};
|
|
258
262
|
|
|
@@ -875,6 +879,35 @@ class SocketCommands {
|
|
|
875
879
|
this.commands['subscribeFiles'] = (socket, id, pattern, callback) => this._subscribeFiles(socket, id, pattern, callback);
|
|
876
880
|
|
|
877
881
|
this.commands['unsubscribeFiles'] = (socket, id, pattern, callback) => this._unsubscribeFiles(socket, id, pattern, callback);
|
|
882
|
+
|
|
883
|
+
this.commands['getAdapterInstances'] = (socket, adapterName, callback) => {
|
|
884
|
+
if (typeof callback === 'function') {
|
|
885
|
+
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
886
|
+
let _adapterName = adapterName || this.adapterName || '';
|
|
887
|
+
if (_adapterName) {
|
|
888
|
+
_adapterName += '.'
|
|
889
|
+
}
|
|
890
|
+
this.adapter.getObjectView('system', 'instance',
|
|
891
|
+
{startkey: `system.adapter.${_adapterName}`, endkey: `system.adapter.${_adapterName}\u9999`},
|
|
892
|
+
(err, doc) => {
|
|
893
|
+
if (err) {
|
|
894
|
+
callback(err);
|
|
895
|
+
} else {
|
|
896
|
+
callback(null, doc.rows
|
|
897
|
+
.map(item => {
|
|
898
|
+
const obj = item.value;
|
|
899
|
+
if (obj.common) {
|
|
900
|
+
delete obj.common.news;
|
|
901
|
+
}
|
|
902
|
+
this._fixAdminUI(obj);
|
|
903
|
+
return obj;
|
|
904
|
+
})
|
|
905
|
+
.filter(obj => obj && (!adapterName || (obj.common && obj.common.name === adapterName))));
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
};
|
|
878
911
|
}
|
|
879
912
|
|
|
880
913
|
__initCommandsStates() {
|
|
@@ -830,35 +830,6 @@ class SocketCommandsAdmin extends SocketCommands {
|
|
|
830
830
|
}
|
|
831
831
|
};
|
|
832
832
|
|
|
833
|
-
this.commands['getAdapterInstances'] = (socket, adapterName, callback) => {
|
|
834
|
-
if (typeof callback === 'function') {
|
|
835
|
-
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
836
|
-
let _adapterName = adapterName || this.adapterName || '';
|
|
837
|
-
if (_adapterName) {
|
|
838
|
-
_adapterName += '.'
|
|
839
|
-
}
|
|
840
|
-
this.adapter.getObjectView('system', 'instance',
|
|
841
|
-
{startkey: `system.adapter.${_adapterName}`, endkey: `system.adapter.${_adapterName}\u9999`},
|
|
842
|
-
(err, doc) => {
|
|
843
|
-
if (err) {
|
|
844
|
-
callback(err);
|
|
845
|
-
} else {
|
|
846
|
-
callback(null, doc.rows
|
|
847
|
-
.map(item => {
|
|
848
|
-
const obj = item.value;
|
|
849
|
-
if (obj.common) {
|
|
850
|
-
delete obj.common.news;
|
|
851
|
-
}
|
|
852
|
-
this._fixAdminUI(obj);
|
|
853
|
-
return obj;
|
|
854
|
-
})
|
|
855
|
-
.filter(obj => obj && (!adapterName || (obj.common && obj.common.name === adapterName))));
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
|
|
862
833
|
this.commands['getAdapters'] = (socket, adapterName, callback) => {
|
|
863
834
|
if (typeof callback === 'function' && this._checkPermissions(socket, 'getObject', callback)) {
|
|
864
835
|
this.adapter.getObjectView('system', 'adapter',
|
package/lib/socketCommon.js
CHANGED
|
@@ -75,6 +75,10 @@ class SocketCommon {
|
|
|
75
75
|
this.server = socketClass(server, socketOptions);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
if (typeof this.server.of === 'function') {
|
|
79
|
+
this.allNamespaces = this.server.of(/.*/);
|
|
80
|
+
}
|
|
81
|
+
|
|
78
82
|
server.__inited = true;
|
|
79
83
|
this.adapter.log.info(`${this.settings.secure ? 'Secure ' : ''}socket.io server listening on port ${this.settings.port}`);
|
|
80
84
|
}
|
|
@@ -93,6 +97,11 @@ class SocketCommon {
|
|
|
93
97
|
this.eventHandlers.connect && this.eventHandlers.connect(socket);
|
|
94
98
|
this._initSocket(socket, cb);
|
|
95
99
|
});
|
|
100
|
+
// support of dynamic namespaces (because of reverse proxy)
|
|
101
|
+
this.allNamespaces && this.allNamespaces.on('connection', (socket, cb) => {
|
|
102
|
+
this.eventHandlers.connect && this.eventHandlers.connect(socket);
|
|
103
|
+
this._initSocket(socket, cb);
|
|
104
|
+
});
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
this.server.on('error', (error, details) => {
|
|
@@ -101,6 +110,13 @@ class SocketCommon {
|
|
|
101
110
|
this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
|
|
102
111
|
}
|
|
103
112
|
});
|
|
113
|
+
// support of dynamic namespaces (because of reverse proxy)
|
|
114
|
+
this.allNamespaces && this.allNamespaces.on('error', (error, details) => {
|
|
115
|
+
// ignore "failed connection" as it already shown
|
|
116
|
+
if (!error || !error.message || !error.message.includes('failed connection')) {
|
|
117
|
+
this.adapter.log.error(`Error: ${(error && error.message) || JSON.stringify(error)}${details ? ' - ' + details : ''}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
104
120
|
|
|
105
121
|
this._updateConnectedInfo();
|
|
106
122
|
}
|
|
@@ -266,7 +282,7 @@ class SocketCommon {
|
|
|
266
282
|
this._updateConnectedInfo();
|
|
267
283
|
|
|
268
284
|
// Disable logging if no one browser is connected
|
|
269
|
-
if (this.adapter.requireLog) {
|
|
285
|
+
if (this.adapter.requireLog && this.commands && this.commands.isLogEnabled()) {
|
|
270
286
|
this.adapter.log.debug('Disable logging, because no one socket connected');
|
|
271
287
|
this.adapter.requireLog(!!(this.server && this.server.engine && this.server.engine.clientsCount));
|
|
272
288
|
}
|