@iobroker/adapter-react-v5 4.4.3 → 4.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.
@@ -822,7 +822,7 @@ declare class Connection {
822
822
  * Unsubscribe from instance message
823
823
  * @param {string} [targetInstance] instance, like 'cameras.0'
824
824
  * @param {string} [messageType] message type like 'startCamera/cam3'
825
- * @param {function} [callback] message handler
825
+ * @param {function} [callback] message handler. Could be null if all callbacks for this messageType should be unsubscribed
826
826
  * @returns {Promise<boolean>}
827
827
  */
828
828
  unsubscribeFromInstance(targetInstance?: string, messageType?: string, callback?: Function): Promise<boolean>;
@@ -3353,14 +3353,16 @@ var Connection = /*#__PURE__*/function () {
3353
3353
  } else if (result && result.error) {
3354
3354
  reject(result.error);
3355
3355
  } else {
3356
+ if (!targetInstance.startsWith('system.adapter.')) {
3357
+ targetInstance = "system.adapter.".concat(targetInstance);
3358
+ }
3356
3359
  // save callback
3357
3360
  _this79._instanceSubscriptions[targetInstance] = _this79._instanceSubscriptions[targetInstance] || [];
3358
3361
  if (!_this79._instanceSubscriptions[targetInstance].find(function (sub) {
3359
- return sub.messageType === messageType && sub.targetInstance === targetInstance && sub.callback === callback;
3362
+ return sub.messageType === messageType && sub.callback === callback;
3360
3363
  })) {
3361
3364
  _this79._instanceSubscriptions[targetInstance].push({
3362
3365
  messageType: messageType,
3363
- targetInstance: targetInstance,
3364
3366
  callback: callback
3365
3367
  });
3366
3368
  }
@@ -3374,39 +3376,59 @@ var Connection = /*#__PURE__*/function () {
3374
3376
  * Unsubscribe from instance message
3375
3377
  * @param {string} [targetInstance] instance, like 'cameras.0'
3376
3378
  * @param {string} [messageType] message type like 'startCamera/cam3'
3377
- * @param {function} [callback] message handler
3379
+ * @param {function} [callback] message handler. Could be null if all callbacks for this messageType should be unsubscribed
3378
3380
  * @returns {Promise<boolean>}
3379
3381
  */
3380
3382
  }, {
3381
3383
  key: "unsubscribeFromInstance",
3382
3384
  value: function unsubscribeFromInstance(targetInstance, messageType, callback) {
3383
- var _this$_instanceSubscr,
3384
- _this80 = this;
3385
- var index = (_this$_instanceSubscr = this._instanceSubscriptions[targetInstance]) === null || _this$_instanceSubscr === void 0 ? void 0 : _this$_instanceSubscr.findIndex(function (sub) {
3386
- return sub.messageType === messageType && sub.callback === callback;
3387
- });
3388
- if (index !== undefined && index !== null && index !== -1) {
3389
- var _messageType = this._instanceSubscriptions[targetInstance][index].messageType;
3390
- this._instanceSubscriptions[targetInstance].splice(index, 1);
3391
- if (!this._instanceSubscriptions[targetInstance].length) {
3392
- delete this._instanceSubscriptions[targetInstance];
3393
- }
3385
+ var _this80 = this;
3386
+ if (!targetInstance.startsWith('system.adapter.')) {
3387
+ targetInstance = "system.adapter.".concat(targetInstance);
3388
+ }
3389
+ var deleted;
3390
+ var promiseResults = [];
3391
+ var _loop = function _loop() {
3392
+ var _this80$_instanceSubs;
3393
+ deleted = false;
3394
+ var index = (_this80$_instanceSubs = _this80._instanceSubscriptions[targetInstance]) === null || _this80$_instanceSubs === void 0 ? void 0 : _this80$_instanceSubs.findIndex(function (sub) {
3395
+ return (!messageType || sub.messageType === messageType) && (!callback || sub.callback === callback);
3396
+ });
3397
+ if (index !== undefined && index !== null && index !== -1) {
3398
+ deleted = true;
3399
+ // remember messageType
3400
+ var _messageType = _this80._instanceSubscriptions[targetInstance][index].messageType;
3401
+ _this80._instanceSubscriptions[targetInstance].splice(index, 1);
3402
+ if (!_this80._instanceSubscriptions[targetInstance].length) {
3403
+ delete _this80._instanceSubscriptions[targetInstance];
3404
+ }
3394
3405
 
3395
- // try to find another subscription for this instance and messageType
3396
- var found = this._instanceSubscriptions[targetInstance] && this._instanceSubscriptions[targetInstance].find(function (sub) {
3397
- return sub.messageType === _messageType;
3398
- });
3399
- if (!found) {
3400
- return new Promise(function (resolve, reject) {
3401
- return _this80._socket.emit('clientUnsubscribe', targetInstance, messageType, function (err, wasSubscribed) {
3402
- if (err) {
3403
- reject(err);
3404
- } else {
3405
- resolve(wasSubscribed);
3406
- }
3407
- });
3406
+ // try to find another subscription for this instance and messageType
3407
+ var found = _this80._instanceSubscriptions[targetInstance] && _this80._instanceSubscriptions[targetInstance].find(function (sub) {
3408
+ return sub.messageType === _messageType;
3408
3409
  });
3410
+ if (!found) {
3411
+ promiseResults.push(new Promise(function (resolve, reject) {
3412
+ return _this80._socket.emit('clientUnsubscribe', targetInstance, messageType, function (err, wasSubscribed) {
3413
+ if (err) {
3414
+ reject(err);
3415
+ } else {
3416
+ resolve(wasSubscribed);
3417
+ }
3418
+ });
3419
+ }));
3420
+ }
3409
3421
  }
3422
+ };
3423
+ do {
3424
+ _loop();
3425
+ } while (deleted && (!callback || !messageType));
3426
+ if (promiseResults.length) {
3427
+ return Promise.all(promiseResults).then(function (results) {
3428
+ return results.find(function (result) {
3429
+ return result;
3430
+ }) || false;
3431
+ });
3410
3432
  }
3411
3433
  return Promise.resolve(false);
3412
3434
  }