@interopio/browser 4.0.3 → 4.1.1-beta.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.
@@ -926,6 +926,7 @@ const defaultWidgetConfig = {
926
926
  awaitFactory: true,
927
927
  enable: false,
928
928
  timeout: 5 * 1000,
929
+ restoreLastKnownPosition: true,
929
930
  };
930
931
  const defaultModalsConfig = {
931
932
  alerts: {
@@ -961,6 +962,11 @@ const REQUEST_WIDGET_READY = "requestWidgetFactoryReady";
961
962
  const REQUEST_MODALS_UI_FACTORY_READY = "requestModalsUIFactoryReady";
962
963
  const MAX_SET_TIMEOUT_DELAY = 2147483647;
963
964
  const REQUEST_INTENT_RESOLVER_UI_FACTORY_READY = "requestIntentResolverUIFactoryReady";
965
+ const READONLY_PROPERTY_DESCRIPTOR = {
966
+ configurable: false,
967
+ enumerable: true,
968
+ writable: false,
969
+ };
964
970
 
965
971
  const extractErrorMsg = (error) => {
966
972
  if (typeof error === "string") {
@@ -2177,7 +2183,7 @@ const nonEmptyStringDecoder$2 = string$2().where((s) => s.length > 0, "Expected
2177
2183
  const nonNegativeNumberDecoder$2 = number$2().where((num) => num >= 0, "Expected a non-negative number");
2178
2184
  const optionalNonEmptyStringDecoder = optional$2(nonEmptyStringDecoder$2);
2179
2185
  const libDomainDecoder = oneOf$1(constant$2("system"), constant$2("windows"), constant$2("appManager"), constant$2("layouts"), constant$2("intents"), constant$2("notifications"), constant$2("channels"), constant$2("extension"), constant$2("themes"), constant$2("prefs"), constant$2("ui"));
2180
- const windowOperationTypesDecoder = oneOf$1(constant$2("openWindow"), constant$2("windowHello"), constant$2("windowAdded"), constant$2("windowRemoved"), constant$2("getBounds"), constant$2("getFrameBounds"), constant$2("getUrl"), constant$2("moveResize"), constant$2("focus"), constant$2("close"), constant$2("getTitle"), constant$2("setTitle"), constant$2("focusChange"), constant$2("getChannel"), constant$2("notifyChannelsChanged"), constant$2("operationCheck"));
2186
+ const windowOperationTypesDecoder = oneOf$1(constant$2("openWindow"), constant$2("windowHello"), constant$2("windowAdded"), constant$2("windowRemoved"), constant$2("getBounds"), constant$2("getFrameBounds"), constant$2("getUrl"), constant$2("moveResize"), constant$2("focus"), constant$2("close"), constant$2("getTitle"), constant$2("setTitle"), constant$2("focusChange"), constant$2("getChannel"), constant$2("notifyChannelsChanged"), constant$2("setZoomFactor"), constant$2("zoomFactorChange"), constant$2("refresh"), constant$2("operationCheck"));
2181
2187
  const appManagerOperationTypesDecoder = oneOf$1(constant$2("appHello"), constant$2("appDirectoryStateChange"), constant$2("instanceStarted"), constant$2("instanceStopped"), constant$2("applicationStart"), constant$2("instanceStop"), constant$2("clear"), constant$2("operationCheck"));
2182
2188
  const layoutsOperationTypesDecoder = oneOf$1(constant$2("layoutAdded"), constant$2("layoutChanged"), constant$2("layoutRemoved"), constant$2("layoutRenamed"), constant$2("get"), constant$2("getAll"), constant$2("export"), constant$2("import"), constant$2("remove"), constant$2("rename"), constant$2("clientSaveRequest"), constant$2("getGlobalPermissionState"), constant$2("checkGlobalActivated"), constant$2("requestGlobalPermission"), constant$2("getDefaultGlobal"), constant$2("setDefaultGlobal"), constant$2("clearDefaultGlobal"), constant$2("updateMetadata"), constant$2("operationCheck"), constant$2("getCurrent"), constant$2("defaultLayoutChanged"), constant$2("layoutRestored"));
2183
2189
  const notificationsOperationTypesDecoder = oneOf$1(constant$2("raiseNotification"), constant$2("requestPermission"), constant$2("notificationShow"), constant$2("notificationClick"), constant$2("getPermission"), constant$2("list"), constant$2("notificationRaised"), constant$2("notificationClosed"), constant$2("click"), constant$2("clear"), constant$2("clearAll"), constant$2("configure"), constant$2("getConfiguration"), constant$2("configurationChanged"), constant$2("setState"), constant$2("clearOld"), constant$2("activeCountChange"), constant$2("stateChange"), constant$2("operationCheck"), constant$2("getActiveCount"));
@@ -2256,6 +2262,10 @@ const windowUrlResultDecoder = object$2({
2256
2262
  windowId: nonEmptyStringDecoder$2,
2257
2263
  url: nonEmptyStringDecoder$2
2258
2264
  });
2265
+ const windowZoomFactorConfigDecoder = object$2({
2266
+ windowId: nonEmptyStringDecoder$2,
2267
+ factorIndex: nonNegativeNumberDecoder$2
2268
+ });
2259
2269
  const anyDecoder = anyJson$2();
2260
2270
  const boundsDecoder = object$2({
2261
2271
  top: optional$2(number$2()),
@@ -2369,7 +2379,8 @@ const windowComponentStateDecoder = object$2({
2369
2379
  restoreSettings: object$2({
2370
2380
  groupId: optional$2(nonEmptyStringDecoder$2),
2371
2381
  groupZOrder: optional$2(number$2())
2372
- })
2382
+ }),
2383
+ channelId: optional$2(nonEmptyStringDecoder$2),
2373
2384
  });
2374
2385
  const windowLayoutComponentDecoder = object$2({
2375
2386
  type: constant$2("window"),
@@ -2911,9 +2922,18 @@ const getWindowIdsOnChannelDataDecoder = object$2({
2911
2922
  const getWindowIdsOnChannelResultDecoder = object$2({
2912
2923
  windowIds: array$2(nonEmptyStringDecoder$2)
2913
2924
  });
2914
- const channelsOperationTypesDecoder = oneOf$1(constant$2("addChannel"), constant$2("getMyChannel"), constant$2("getWindowIdsOnChannel"), constant$2("getWindowIdsWithChannels"), constant$2("joinChannel"), constant$2("restrict"), constant$2("getRestrictions"), constant$2("restrictAll"), constant$2("notifyChannelsChanged"), constant$2("leaveChannel"), constant$2("getMode"), constant$2("operationCheck"));
2925
+ const channelsOperationTypesDecoder = oneOf$1(constant$2("appHello"), constant$2("addChannel"), constant$2("getMyChannel"), constant$2("getWindowIdsOnChannel"), constant$2("getWindowIdsWithChannels"), constant$2("joinChannel"), constant$2("restrict"), constant$2("getRestrictions"), constant$2("restrictAll"), constant$2("notifyChannelsChanged"), constant$2("leaveChannel"), constant$2("getMode"), constant$2("operationCheck"));
2926
+ const modeDecoder = oneOf$1(constant$2("single"), constant$2("multi"));
2915
2927
  const getChannelsModeDecoder = object$2({
2916
- mode: oneOf$1(constant$2("single"), constant$2("multi"))
2928
+ mode: modeDecoder
2929
+ });
2930
+ const channelsAppHelloDataDecoder = object$2({
2931
+ windowId: nonEmptyStringDecoder$2
2932
+ });
2933
+ const channelsAppHelloSuccessDecoder = object$2({
2934
+ mode: modeDecoder,
2935
+ channels: array$2(nonEmptyStringDecoder$2),
2936
+ restrictions: array$2(channelRestrictionsDecoder)
2917
2937
  });
2918
2938
  const getMyChanelResultDecoder = object$2({
2919
2939
  channel: optional$2(nonEmptyStringDecoder$2)
@@ -2978,6 +2998,7 @@ const getAllPrefsResultDecoder = object$2({
2978
2998
  });
2979
2999
  const subscriberRegisterConfigDecoder = object$2({
2980
3000
  interopId: nonEmptyStringDecoder$2,
3001
+ appName: optional$2(nonEmptyStringDecoder$2)
2981
3002
  });
2982
3003
  const changePrefsDataDecoder = object$2({
2983
3004
  app: nonEmptyStringDecoder$2,
@@ -3018,8 +3039,7 @@ const channelSelectorDecoder = object$2({
3018
3039
  type: optional$2(channelSelectorTypeDecoder),
3019
3040
  enable: optional$2(boolean$2())
3020
3041
  });
3021
- const positionDecoder = oneOf$1(constant$2("top"), constant$2("bottom"), constant$2("left"), constant$2("right"));
3022
- const modeDecoder = oneOf$1(constant$2("default"), constant$2("compact"));
3042
+ const positionDecoder = oneOf$1(constant$2("top-left"), constant$2("top-center"), constant$2("top-right"), constant$2("center-left"), constant$2("center-right"), constant$2("bottom-left"), constant$2("bottom-center"), constant$2("bottom-right"));
3023
3043
  const displayModeDecoder = oneOf$1(constant$2("all"), constant$2("fdc3"));
3024
3044
  const widgetChannelsDecoder = object$2({
3025
3045
  selector: optional$2(channelSelectorDecoder),
@@ -3028,8 +3048,8 @@ const widgetChannelsDecoder = object$2({
3028
3048
  const platformWidgetDefaultConfigDecoder = object$2({
3029
3049
  channels: optional$2(widgetChannelsDecoder),
3030
3050
  position: optional$2(positionDecoder),
3031
- mode: optional$2(modeDecoder),
3032
- displayInWorkspace: optional$2(boolean$2())
3051
+ displayInWorkspace: optional$2(boolean$2()),
3052
+ restoreLastKnownPosition: optional$2(boolean$2()),
3033
3053
  });
3034
3054
  const widgetConfigDecoder = object$2({
3035
3055
  enable: boolean$2(),
@@ -3037,8 +3057,8 @@ const widgetConfigDecoder = object$2({
3037
3057
  timeout: optional$2(nonNegativeNumberDecoder$1),
3038
3058
  channels: optional$2(widgetChannelsDecoder),
3039
3059
  position: optional$2(positionDecoder),
3040
- mode: optional$2(modeDecoder),
3041
- displayInWorkspace: optional$2(boolean$2())
3060
+ displayInWorkspace: optional$2(boolean$2()),
3061
+ restoreLastKnownPosition: optional$2(boolean$2()),
3042
3062
  });
3043
3063
  const modalsConfigDecoder = object$2({
3044
3064
  alerts: optional$2(object$2({
@@ -3272,6 +3292,9 @@ const operations$a = {
3272
3292
  focusChange: { name: "focusChange", dataDecoder: focusEventDataDecoder },
3273
3293
  getChannel: { name: "getChannel", dataDecoder: simpleWindowDecoder, resultDecoder: windowChannelResultDecoder },
3274
3294
  notifyChannelsChanged: { name: "notifyChannelsChanged", dataDecoder: channelsChangedDataDecoder },
3295
+ setZoomFactor: { name: "setZoomFactor", dataDecoder: windowZoomFactorConfigDecoder },
3296
+ zoomFactorChange: { name: "zoomFactorChange", dataDecoder: windowZoomFactorConfigDecoder },
3297
+ refresh: { name: "refresh", dataDecoder: simpleWindowDecoder },
3275
3298
  operationCheck: { name: "operationCheck" }
3276
3299
  };
3277
3300
 
@@ -3395,18 +3418,41 @@ var lib$1 = createRegistry$1;
3395
3418
 
3396
3419
  var CallbackRegistryFactory$1 = /*@__PURE__*/getDefaultExportFromCjs$1(lib$1);
3397
3420
 
3421
+ const ZOOM_FACTORS = Object.freeze({
3422
+ 0: 24,
3423
+ 1: 33,
3424
+ 2: 50,
3425
+ 3: 67,
3426
+ 4: 75,
3427
+ 5: 80,
3428
+ 6: 90,
3429
+ 7: 100,
3430
+ 8: 110,
3431
+ 9: 125,
3432
+ 10: 150,
3433
+ 11: 175,
3434
+ 12: 200,
3435
+ 13: 250,
3436
+ 14: 300,
3437
+ 15: 400,
3438
+ 16: 500
3439
+ });
3440
+
3398
3441
  class WebWindowModel {
3399
3442
  _id;
3400
3443
  _name;
3401
3444
  _bridge;
3445
+ _logger;
3402
3446
  registry = CallbackRegistryFactory$1();
3403
3447
  myCtxKey;
3404
3448
  ctxUnsubscribe;
3449
+ zoomFactorIndex = 7;
3405
3450
  me;
3406
- constructor(_id, _name, _bridge) {
3451
+ constructor(_id, _name, _bridge, _logger) {
3407
3452
  this._id = _id;
3408
3453
  this._name = _name;
3409
3454
  this._bridge = _bridge;
3455
+ this._logger = _logger;
3410
3456
  this.myCtxKey = `___window___${this.id}`;
3411
3457
  }
3412
3458
  get id() {
@@ -3415,6 +3461,9 @@ class WebWindowModel {
3415
3461
  get name() {
3416
3462
  return this._name.slice();
3417
3463
  }
3464
+ get zoomFactor() {
3465
+ return ZOOM_FACTORS[this.zoomFactorIndex];
3466
+ }
3418
3467
  clean() {
3419
3468
  if (this.ctxUnsubscribe) {
3420
3469
  this.ctxUnsubscribe();
@@ -3427,12 +3476,17 @@ class WebWindowModel {
3427
3476
  processChannelsChangedEvent(channelNames) {
3428
3477
  this.registry.execute("channels-changed", channelNames);
3429
3478
  }
3479
+ processSelfZoomFactorChangedEvent(factorIndex) {
3480
+ this.zoomFactorIndex = factorIndex;
3481
+ this.registry.execute("zoom-factor-changed", this.me);
3482
+ }
3430
3483
  async toApi() {
3431
3484
  this.ctxUnsubscribe = await this._bridge.contextLib.subscribe(this.myCtxKey, (data) => this.registry.execute("context-updated", data));
3432
3485
  this.me = {
3433
3486
  id: this.id,
3434
3487
  name: this.name,
3435
3488
  isFocused: false,
3489
+ zoomFactor: this.zoomFactor,
3436
3490
  getURL: this.getURL.bind(this),
3437
3491
  moveResize: this.moveResize.bind(this),
3438
3492
  resizeTo: this.resizeTo.bind(this),
@@ -3445,11 +3499,26 @@ class WebWindowModel {
3445
3499
  getContext: this.getContext.bind(this),
3446
3500
  updateContext: this.updateContext.bind(this),
3447
3501
  setContext: this.setContext.bind(this),
3502
+ refresh: this.refresh.bind(this),
3448
3503
  onContextUpdated: this.onContextUpdated.bind(this),
3449
3504
  onFocusChanged: this.onFocusChanged.bind(this),
3450
3505
  getChannel: this.getChannel.bind(this),
3451
3506
  onChannelsChanged: this.onChannelsChanged.bind(this),
3507
+ zoomIn: this.zoomIn.bind(this),
3508
+ zoomOut: this.zoomOut.bind(this),
3509
+ setZoomFactor: this.setZoomFactor.bind(this),
3510
+ onZoomFactorChanged: this.onZoomFactorChanged.bind(this),
3452
3511
  };
3512
+ Object.defineProperties(this.me, {
3513
+ id: READONLY_PROPERTY_DESCRIPTOR,
3514
+ name: READONLY_PROPERTY_DESCRIPTOR,
3515
+ zoomFactor: {
3516
+ get: () => {
3517
+ return this.zoomFactor;
3518
+ },
3519
+ enumerable: true,
3520
+ },
3521
+ });
3453
3522
  return this.me;
3454
3523
  }
3455
3524
  async getURL() {
@@ -3556,6 +3625,47 @@ class WebWindowModel {
3556
3625
  onChannelsChanged(callback) {
3557
3626
  return this.registry.add("channels-changed", callback);
3558
3627
  }
3628
+ getClosestZoomFactorIndex(factor) {
3629
+ const closestIndex = Object.entries(ZOOM_FACTORS).reduce((closestIndex, [currentIndex, currentValue]) => {
3630
+ return (Math.abs(currentValue - factor) <= Math.abs(ZOOM_FACTORS[closestIndex] - factor) ? parseInt(currentIndex) : closestIndex);
3631
+ }, 0);
3632
+ const closestFactor = ZOOM_FACTORS[closestIndex];
3633
+ if (closestFactor !== factor) {
3634
+ this._logger.warn(`Zoom factor ${factor} is not available, using closest value ${closestFactor} instead.`);
3635
+ }
3636
+ return closestIndex;
3637
+ }
3638
+ async zoom(factorIndex) {
3639
+ if (factorIndex === this.zoomFactorIndex || !(factorIndex in ZOOM_FACTORS)) {
3640
+ return;
3641
+ }
3642
+ await this._bridge.send("windows", operations$a.setZoomFactor, { windowId: this.id, factorIndex }, undefined, { includeOperationCheck: true });
3643
+ this.zoomFactorIndex = factorIndex;
3644
+ }
3645
+ async zoomIn() {
3646
+ await this.zoom(this.zoomFactorIndex + 1);
3647
+ return this.me;
3648
+ }
3649
+ async zoomOut() {
3650
+ await this.zoom(this.zoomFactorIndex - 1);
3651
+ return this.me;
3652
+ }
3653
+ async setZoomFactor(factor) {
3654
+ const targetZoomFactor = runDecoderWithIOError(number$2(), factor);
3655
+ const closestZoomFactorIndex = this.getClosestZoomFactorIndex(targetZoomFactor);
3656
+ await this.zoom(closestZoomFactorIndex);
3657
+ return this.me;
3658
+ }
3659
+ onZoomFactorChanged(callback) {
3660
+ if (typeof callback !== "function") {
3661
+ return ioError.raiseError("Cannot subscribe to zoom factor changes, because the provided callback is not a function!");
3662
+ }
3663
+ return this.registry.add("zoom-factor-changed", callback);
3664
+ }
3665
+ async refresh() {
3666
+ await this._bridge.send("windows", operations$a.refresh, { windowId: this.id }, undefined, { includeOperationCheck: true });
3667
+ return this.me;
3668
+ }
3559
3669
  }
3560
3670
 
3561
3671
  const commonOperations = {
@@ -3704,6 +3814,9 @@ class WindowsController {
3704
3814
  operations$a.setTitle.execute = this.handleSetTitle.bind(this);
3705
3815
  operations$a.getChannel.execute = this.handleGetChannel.bind(this);
3706
3816
  operations$a.notifyChannelsChanged.execute = this.handleChannelsChanged.bind(this);
3817
+ operations$a.setZoomFactor.execute = this.handleSetZoomFactor.bind(this);
3818
+ operations$a.zoomFactorChange.execute = this.handleZoomFactorChanged.bind(this);
3819
+ operations$a.refresh.execute = this.handleRefresh.bind(this);
3707
3820
  operations$a.operationCheck.execute = async (config) => handleOperationCheck(this.supportedOperationsNames, config.operation);
3708
3821
  this.supportedOperationsNames = getSupportedOperationsNames(operations$a);
3709
3822
  }
@@ -3749,13 +3862,13 @@ class WindowsController {
3749
3862
  const windowsInfo = windows.map(w => `${w.windowId}:${w.name}`).join(", ");
3750
3863
  return ioError.raiseError(`Cannot initialize the window library, because I received no information about me -> id: ${this.publicWindowId} name: ${window.name} from the platform: known windows: ${windowsInfo}`);
3751
3864
  }
3752
- const myProjection = await this.ioc.buildWebWindow(this.publicWindowId, myWindow.name);
3865
+ const myProjection = await this.ioc.buildWebWindow(this.publicWindowId, myWindow.name, this.logger);
3753
3866
  this.me = myProjection.api;
3754
3867
  this.allWindowProjections.push(myProjection);
3755
3868
  }
3756
3869
  const currentWindows = await Promise.all(windows
3757
3870
  .filter((w) => w.windowId !== this.publicWindowId)
3758
- .map((w) => this.ioc.buildWebWindow(w.windowId, w.name)));
3871
+ .map((w) => this.ioc.buildWebWindow(w.windowId, w.name, this.logger)));
3759
3872
  this.logger.trace("all windows projections are completed, building the list collection");
3760
3873
  this.allWindowProjections.push(...currentWindows);
3761
3874
  }
@@ -3772,7 +3885,7 @@ class WindowsController {
3772
3885
  if (this.allWindowProjections.some((projection) => projection.id === data.windowId)) {
3773
3886
  return;
3774
3887
  }
3775
- const webWindowProjection = await this.ioc.buildWebWindow(data.windowId, data.name);
3888
+ const webWindowProjection = await this.ioc.buildWebWindow(data.windowId, data.name, this.logger);
3776
3889
  this.allWindowProjections.push(webWindowProjection);
3777
3890
  this.registry.execute("window-added", webWindowProjection.api);
3778
3891
  }
@@ -3889,17 +4002,38 @@ class WindowsController {
3889
4002
  }
3890
4003
  async handleGetChannel() {
3891
4004
  if (!this.me) {
3892
- return ioError.raiseError("This window cannot report it's channel, because it is not a Glue Window, most likely because it is an iframe");
4005
+ return ioError.raiseError("This window cannot report its channel, because it is not a ioConnect Window, most likely because it is an iframe");
3893
4006
  }
3894
4007
  const channel = this.channelsController.my();
3895
4008
  return {
3896
4009
  ...(channel ? { channel } : {}),
3897
4010
  };
3898
4011
  }
4012
+ async handleRefresh() {
4013
+ if (!this.me) {
4014
+ return ioError.raiseError("This window cannot refresh, because it is not an ioConnect Window, most likely because it is an iframe");
4015
+ }
4016
+ setTimeout(() => {
4017
+ window.location.reload();
4018
+ }, 0);
4019
+ }
3899
4020
  async handleChannelsChanged(data) {
3900
4021
  const windowProjection = this.allWindowProjections.find((projection) => projection.id === data.windowId);
3901
4022
  windowProjection?.model.processChannelsChangedEvent(data.channelNames);
3902
4023
  }
4024
+ async handleSetZoomFactor(config) {
4025
+ if (!this.me) {
4026
+ return ioError.raiseError("This window cannot change its zoom factor, because it is not an ioConnect Window, most likely because it is an iframe");
4027
+ }
4028
+ document.body.style.zoom = `${ZOOM_FACTORS[config.factorIndex]}%`;
4029
+ }
4030
+ async handleZoomFactorChanged(data) {
4031
+ const foundProjection = this.allWindowProjections.find((projection) => projection.id === data.windowId);
4032
+ if (!foundProjection) {
4033
+ return;
4034
+ }
4035
+ foundProjection.model.processSelfZoomFactorChangedEvent(data.factorIndex);
4036
+ }
3903
4037
  }
3904
4038
 
3905
4039
  const GlueWebPlatformControlName = "T42.Web.Platform.Control";
@@ -4103,8 +4237,8 @@ class AppManagerController {
4103
4237
  platformRegistration;
4104
4238
  logger;
4105
4239
  channelsController;
4106
- sessionController;
4107
4240
  interop;
4241
+ initialChannelId;
4108
4242
  handlePlatformShutdown() {
4109
4243
  this.registry.clear();
4110
4244
  this.applications = [];
@@ -4119,7 +4253,6 @@ class AppManagerController {
4119
4253
  this.ioc = ioc;
4120
4254
  this.bridge = ioc.bridge;
4121
4255
  this.channelsController = ioc.channelsController;
4122
- this.sessionController = ioc.sessionController;
4123
4256
  this.interop = coreGlue.interop;
4124
4257
  this.platformRegistration = this.registerWithPlatform();
4125
4258
  await this.platformRegistration;
@@ -4127,6 +4260,12 @@ class AppManagerController {
4127
4260
  const api = this.toApi();
4128
4261
  coreGlue.appManager = api;
4129
4262
  }
4263
+ async postStart() {
4264
+ if (!this.initialChannelId) {
4265
+ return;
4266
+ }
4267
+ await this.channelsController.handleAppManagerInitialChannelId(this.initialChannelId);
4268
+ }
4130
4269
  async handleBridgeMessage(args) {
4131
4270
  await this.platformRegistration;
4132
4271
  const operationName = runDecoderWithIOError(appManagerOperationTypesDecoder, args.operation);
@@ -4355,14 +4494,6 @@ class AppManagerController {
4355
4494
  getApplications() {
4356
4495
  return this.applications.slice();
4357
4496
  }
4358
- async joinInitialChannel(initialChannelId) {
4359
- try {
4360
- await this.channelsController.join(initialChannelId);
4361
- }
4362
- catch (error) {
4363
- this.logger.warn(`Application instance ${this.me} was unable to join the ${initialChannelId} channel. Reason: ${JSON.stringify(error)}`);
4364
- }
4365
- }
4366
4497
  async registerWithPlatform() {
4367
4498
  const result = await this.bridge.send("appManager", operations$9.appHello, { windowId: this.publicWindowId }, { methodResponseTimeoutMs: this.baseApplicationsTimeoutMS });
4368
4499
  this.logger.trace("the platform responded to the hello message with a full list of apps");
@@ -4373,12 +4504,7 @@ class AppManagerController {
4373
4504
  }, []);
4374
4505
  this.me = this.findMyInstance();
4375
4506
  this.logger.trace(`all applications were parsed and saved. I am ${this.me ? "NOT a" : "a"} valid instance`);
4376
- const { channels: channelsStorageData } = this.sessionController.getWindowData();
4377
- const channels = channelsStorageData ? channelsStorageData.currentNames : [result.initialChannelId];
4378
- if (!channels?.length) {
4379
- return;
4380
- }
4381
- await Promise.all(channels.map((channel) => channel ? this.joinInitialChannel(channel) : Promise.resolve()));
4507
+ this.initialChannelId = result.initialChannelId;
4382
4508
  }
4383
4509
  findMyInstance() {
4384
4510
  for (const app of this.applications) {
@@ -5453,6 +5579,7 @@ class IntentsController {
5453
5579
  }
5454
5580
 
5455
5581
  const operations$5 = {
5582
+ appHello: { name: "appHello", dataDecoder: channelsAppHelloDataDecoder, resultDecoder: channelsAppHelloSuccessDecoder },
5456
5583
  addChannel: { name: "addChannel", dataDecoder: channelDefinitionDecoder },
5457
5584
  removeChannel: { name: "removeChannel", dataDecoder: removeChannelDataDecoder },
5458
5585
  getMyChannel: { name: "getMyChannel", resultDecoder: getMyChanelResultDecoder },
@@ -5466,7 +5593,7 @@ const operations$5 = {
5466
5593
  leaveChannel: { name: "leaveChannel", dataDecoder: leaveChannelDataDecoder },
5467
5594
  requestChannelSelector: { name: "requestChannelSelector", dataDecoder: requestChannelSelectorConfigDecoder },
5468
5595
  getMode: { name: "getMode", resultDecoder: getChannelsModeDecoder },
5469
- operationCheck: { name: "operationCheck" }
5596
+ operationCheck: { name: "operationCheck" },
5470
5597
  };
5471
5598
 
5472
5599
  const DEFAULT_MODE = "single";
@@ -5474,6 +5601,8 @@ const CHANNELS_PREFIX = "___channel___";
5474
5601
  const SUBS_KEY = "subs";
5475
5602
  const CHANGED_KEY = "changed";
5476
5603
  const CHANNELS_CHANGED = "channels_changed";
5604
+ const STORAGE_NAMESPACE = "io_connect_channels";
5605
+ const DEFAULT_STORAGE_MODE = "inMemory";
5477
5606
 
5478
5607
  class ChannelsController {
5479
5608
  supportedOperationsNames = [];
@@ -5483,20 +5612,20 @@ class ChannelsController {
5483
5612
  interop;
5484
5613
  bridge;
5485
5614
  windowsController;
5486
- sessionController;
5487
5615
  _mode;
5488
- currentChannels = [];
5489
- unsubscribeDict = {};
5616
+ myWindowId;
5617
+ storage;
5490
5618
  handlePlatformShutdown() {
5491
5619
  this.registry.clear();
5620
+ this.storage.clear();
5492
5621
  }
5493
5622
  addOperationsExecutors() {
5494
5623
  operations$5.getMyChannel.execute = this.handleGetMyChannel.bind(this);
5495
5624
  operations$5.joinChannel.execute = this.handleJoinChannel.bind(this);
5496
5625
  operations$5.leaveChannel.execute = this.handleLeaveChannel.bind(this);
5497
- operations$5.restrict.execute = ({ config }) => this.restrict(config);
5626
+ operations$5.restrict.execute = this.handleRestrict.bind(this);
5498
5627
  operations$5.getRestrictions.execute = ({ windowId }) => this.getRestrictions(windowId);
5499
- operations$5.restrictAll.execute = ({ restrictions }) => this.restrictAll(restrictions);
5628
+ operations$5.restrictAll.execute = this.handleRestrictAll.bind(this);
5500
5629
  operations$5.operationCheck.execute = async (config) => handleOperationCheck(this.supportedOperationsNames, config.operation);
5501
5630
  this.supportedOperationsNames = getSupportedOperationsNames(operations$5);
5502
5631
  }
@@ -5508,9 +5637,10 @@ class ChannelsController {
5508
5637
  this.addOperationsExecutors();
5509
5638
  this.bridge = ioc.bridge;
5510
5639
  this.windowsController = ioc.windowsController;
5511
- this.sessionController = ioc.sessionController;
5640
+ this.storage = ioc.channelsStorage;
5512
5641
  this.logger.trace("no need for platform registration, attaching the channels property to glue and returning");
5513
- this._mode = await this.getPlatformChannelsMode();
5642
+ this.myWindowId = this.windowsController.my().id ?? this.interop.instance.instance;
5643
+ await this.initialize();
5514
5644
  const api = this.toApi();
5515
5645
  coreGlue.channels = api;
5516
5646
  }
@@ -5550,17 +5680,14 @@ class ChannelsController {
5550
5680
  const channelNames = this.getAllChannelNames();
5551
5681
  runDecoderWithIOError(channelNameDecoder(channelNames), name);
5552
5682
  runDecoderWithIOError(optionalNonEmptyStringDecoder, windowId);
5553
- const forAnotherClient = windowId && windowId !== this.interop.instance.instance;
5554
- if (forAnotherClient) {
5555
- return await this.bridge.send("channels", operations$5.joinChannel, { channel: name, windowId }, undefined, { includeOperationCheck: true });
5556
- }
5683
+ const joinData = { channel: name, windowId: windowId ?? this.myWindowId };
5684
+ await this.bridge.send("channels", operations$5.joinChannel, joinData, undefined, { includeOperationCheck: true });
5685
+ }
5686
+ handleJoinChannel({ channel }) {
5557
5687
  if (this._mode === "single") {
5558
- return this.switchToChannel(name);
5688
+ return this.switchToChannel(channel);
5559
5689
  }
5560
- return this.joinAdditionalChannel(name);
5561
- }
5562
- handleJoinChannel({ channel, windowId }) {
5563
- return this.join(channel, windowId);
5690
+ return this.joinAdditionalChannel(channel);
5564
5691
  }
5565
5692
  onChanged(callback) {
5566
5693
  return this.changed(callback);
@@ -5571,22 +5698,25 @@ class ChannelsController {
5571
5698
  const channelNames = this.getAllChannelNames();
5572
5699
  runDecoderWithIOError(channelNameDecoder(channelNames), config.channel);
5573
5700
  }
5574
- const forAnotherClient = config.windowId && config.windowId !== this.interop.instance.instance;
5575
- if (config.windowId && forAnotherClient) {
5576
- const leaveData = { windowId: config.windowId, channelName: config.channel };
5577
- await this.bridge.send("channels", operations$5.leaveChannel, leaveData, undefined, { includeOperationCheck: true });
5701
+ const leaveData = { channelName: config.channel, windowId: config.windowId ?? this.myWindowId };
5702
+ await this.bridge.send("channels", operations$5.leaveChannel, leaveData, undefined, { includeOperationCheck: true });
5703
+ }
5704
+ async handleAppManagerInitialChannelId(channel) {
5705
+ if (this.storage.mode === "inMemory") {
5706
+ return;
5707
+ }
5708
+ if (this.storage.getSessionStorageData()) {
5578
5709
  return;
5579
5710
  }
5580
- const channelNamesToLeave = config.channel ? [config.channel] : this.currentChannels;
5581
- channelNamesToLeave.forEach((name) => this.unsubscribe(name));
5582
- this.currentChannels = this.currentChannels.filter((channelName) => !channelNamesToLeave.includes(channelName));
5583
- this.sessionController.setWindowData({ currentNames: this.currentChannels }, "channels");
5711
+ return this.handleJoinChannel({ channel, windowId: this.myWindowId });
5712
+ }
5713
+ async handleLeaveChannel({ channelName }) {
5714
+ const channelNamesToLeave = channelName ? [channelName] : this.storage.channels;
5715
+ channelNamesToLeave.forEach((name) => this.storage.invokeUnsubscribes(name));
5716
+ this.storage.channels = this.storage.channels.filter((channelName) => !channelNamesToLeave.includes(channelName));
5584
5717
  this.executeChangedEvents();
5585
5718
  await this.notifyChannelsChanged();
5586
5719
  }
5587
- handleLeaveChannel(data) {
5588
- return this.leave({ channel: data.channelName });
5589
- }
5590
5720
  toApi() {
5591
5721
  const api = {
5592
5722
  mode: this._mode,
@@ -5629,47 +5759,36 @@ class ChannelsController {
5629
5759
  return channelNames;
5630
5760
  }
5631
5761
  async joinAdditionalChannel(name) {
5632
- if (this.currentChannels.includes(name)) {
5762
+ if (this.storage.channels.includes(name)) {
5633
5763
  return;
5634
5764
  }
5635
- this.currentChannels = [...this.currentChannels, name];
5765
+ this.storage.channels = [...this.storage.channels, name];
5636
5766
  const contextName = this.createContextName(name);
5637
5767
  const unsub = await this.contexts.subscribe(contextName, (context, delta, _, __, extraData) => {
5638
5768
  this.registry.execute(SUBS_KEY, context.data, context, delta, extraData?.updaterId);
5639
5769
  });
5640
- this.unsubscribeDict[name] = unsub;
5770
+ this.storage.addUnsubscribe(name, unsub);
5641
5771
  this.executeChangedEvents(name);
5642
- this.sessionController.setWindowData({ currentNames: this.currentChannels }, "channels");
5643
5772
  await this.notifyChannelsChanged();
5644
5773
  }
5645
5774
  async switchToChannel(name) {
5646
- const currentChannel = this.currentChannels[0];
5775
+ const currentChannel = this.storage.channels[0];
5647
5776
  if (name === currentChannel) {
5648
5777
  return;
5649
5778
  }
5650
- this.unsubscribe(currentChannel);
5651
- this.currentChannels = [name];
5779
+ this.storage.invokeUnsubscribes(currentChannel);
5780
+ this.storage.channels = [name];
5652
5781
  const contextName = this.createContextName(name);
5653
5782
  const unsub = await this.contexts.subscribe(contextName, (context, delta, _, __, extraData) => {
5654
5783
  this.registry.execute(SUBS_KEY, context.data, context, delta, extraData?.updaterId);
5655
5784
  });
5656
- this.unsubscribeDict[name] = unsub;
5785
+ this.storage.addUnsubscribe(name, unsub);
5657
5786
  this.executeChangedEvents(name);
5658
- this.sessionController.setWindowData({ currentNames: this.currentChannels }, "channels");
5659
5787
  await this.notifyChannelsChanged();
5660
5788
  }
5661
- unsubscribe(channelName) {
5662
- if (channelName) {
5663
- this.unsubscribeDict[channelName]?.();
5664
- delete this.unsubscribeDict[channelName];
5665
- return;
5666
- }
5667
- Object.values(this.unsubscribeDict).forEach((unsub) => unsub());
5668
- this.unsubscribeDict = {};
5669
- }
5670
5789
  executeChangedEvents(name) {
5671
5790
  this.registry.execute(CHANGED_KEY, name);
5672
- this.registry.execute(CHANNELS_CHANGED, this.currentChannels);
5791
+ this.registry.execute(CHANNELS_CHANGED, this.storage.channels);
5673
5792
  }
5674
5793
  async notifyChannelsChanged() {
5675
5794
  const windowId = this.windowsController.my().id;
@@ -5677,7 +5796,7 @@ class ChannelsController {
5677
5796
  return;
5678
5797
  }
5679
5798
  try {
5680
- await this.bridge.send("channels", operations$5.notifyChannelsChanged, { channelNames: this.currentChannels, windowId }, undefined, { includeOperationCheck: true });
5799
+ await this.bridge.send("channels", operations$5.notifyChannelsChanged, { channelNames: this.storage.channels, windowId }, undefined, { includeOperationCheck: true });
5681
5800
  }
5682
5801
  catch (error) {
5683
5802
  this.logger.warn(`Failed to notify channel changed: ${extractErrorMsg(error)}`);
@@ -5760,10 +5879,10 @@ class ChannelsController {
5760
5879
  const channelNames = this.getAllChannelNames();
5761
5880
  runDecoderWithIOError(channelNameDecoder(channelNames), options);
5762
5881
  }
5763
- if (!options && this.currentChannels.length > 1) {
5882
+ if (!options && this.storage.channels.length > 1) {
5764
5883
  return this.publishOnMultipleChannels(data);
5765
5884
  }
5766
- const channelName = typeof options === "string" ? options : this.currentChannels[0];
5885
+ const channelName = typeof options === "string" ? options : this.storage.channels[0];
5767
5886
  if (!channelName) {
5768
5887
  return ioError.raiseError("Cannot publish to channel, because not joined to a channel!");
5769
5888
  }
@@ -5794,13 +5913,13 @@ class ChannelsController {
5794
5913
  return channelContext;
5795
5914
  }
5796
5915
  async getMyChannels() {
5797
- return Promise.all(this.currentChannels.map((channelName) => {
5916
+ return Promise.all(this.storage.channels.map((channelName) => {
5798
5917
  const contextName = this.createContextName(channelName);
5799
5918
  return this.contexts.get(contextName);
5800
5919
  }));
5801
5920
  }
5802
5921
  myChannels() {
5803
- return this.currentChannels;
5922
+ return this.storage.channels;
5804
5923
  }
5805
5924
  getContextForFdc3Type(channelContext, searchedType) {
5806
5925
  const encodedType = `fdc3_${searchedType.split(".").join("&")}`;
@@ -5834,7 +5953,7 @@ class ChannelsController {
5834
5953
  return context;
5835
5954
  }
5836
5955
  current() {
5837
- return this.currentChannels[0];
5956
+ return this.storage.channels[0];
5838
5957
  }
5839
5958
  changed(callback) {
5840
5959
  if (typeof callback !== "function") {
@@ -5878,13 +5997,13 @@ class ChannelsController {
5878
5997
  .catch(err => this.logger.trace(err));
5879
5998
  };
5880
5999
  async getMy(options) {
5881
- if (!this.currentChannels.length) {
6000
+ if (!this.storage.channels.length) {
5882
6001
  return;
5883
6002
  }
5884
6003
  if (options) {
5885
6004
  runDecoderWithIOError(fdc3OptionsDecoder, options);
5886
6005
  }
5887
- return this.get(this.currentChannels[this.currentChannels.length - 1], options);
6006
+ return this.get(this.storage.channels[this.storage.channels.length - 1], options);
5888
6007
  }
5889
6008
  async getWindowsOnChannel(channel) {
5890
6009
  const channelNames = this.getAllChannelNames();
@@ -5918,43 +6037,63 @@ class ChannelsController {
5918
6037
  runDecoderWithIOError(channelRestrictionsDecoder, config);
5919
6038
  const channelNames = this.getAllChannelNames();
5920
6039
  runDecoderWithIOError(channelNameDecoder(channelNames), config.name);
5921
- const forAnotherClient = config.windowId && config.windowId !== this.interop.instance.instance;
5922
- if (forAnotherClient) {
5923
- return this.bridge.send("channels", operations$5.restrict, { config }, undefined, { includeOperationCheck: true });
5924
- }
5925
- const sessionStorageData = this.sessionController.getWindowData();
5926
- const restrictions = sessionStorageData?.restrictions ? { ...sessionStorageData.restrictions, [config.name]: config } : { [config.name]: config };
6040
+ const configData = {
6041
+ config: {
6042
+ ...config,
6043
+ windowId: config.windowId ?? this.myWindowId
6044
+ }
6045
+ };
6046
+ await this.bridge.send("channels", operations$5.restrict, configData, undefined, { includeOperationCheck: true });
6047
+ }
6048
+ async handleRestrict({ config }) {
5927
6049
  const currentChannel = await this.getMy();
5928
- const prevReadAllowed = this.checkPreviousReadAllowed(currentChannel?.name);
5929
- this.sessionController.setWindowData(restrictions, "restrictions");
5930
- if (!currentChannel || prevReadAllowed || !config.read || currentChannel.name !== config.name) {
6050
+ if (!currentChannel) {
6051
+ return this.updateRestriction(config);
6052
+ }
6053
+ const prevReadAllowed = this.isAllowedByRestrictions(currentChannel.name, "read");
6054
+ this.updateRestriction(config);
6055
+ const isForCurrentChannel = config.name === currentChannel.name;
6056
+ if (!isForCurrentChannel || prevReadAllowed || !config.read) {
5931
6057
  return;
5932
6058
  }
5933
6059
  this.replaySubscribeCallback(config.name);
5934
6060
  }
6061
+ updateRestriction(config) {
6062
+ const exists = this.storage.restrictions.some((r) => r.name === config.name);
6063
+ this.storage.restrictions = exists
6064
+ ? this.storage.restrictions.map((restriction) => restriction.name === config.name ? config : restriction)
6065
+ : this.storage.restrictions.concat(config);
6066
+ }
6067
+ updateAllRestrictions(config) {
6068
+ const allChannelNames = this.getAllChannelNames();
6069
+ this.storage.restrictions = allChannelNames.map((name) => ({ name, ...config }));
6070
+ }
5935
6071
  async getRestrictions(windowId) {
5936
6072
  runDecoderWithIOError(optionalNonEmptyStringDecoder, windowId);
5937
6073
  const forAnotherClient = windowId && windowId !== this.interop.instance.instance;
5938
6074
  if (windowId && forAnotherClient) {
5939
6075
  return this.bridge.send("channels", operations$5.getRestrictions, { windowId }, undefined, { includeOperationCheck: true });
5940
6076
  }
5941
- return this.getMyRestrictions();
6077
+ return { channels: this.storage.restrictions };
5942
6078
  }
5943
6079
  async restrictAll(restrictions) {
5944
6080
  runDecoderWithIOError(restrictionsConfigDecoder, restrictions);
5945
- const allChannelNames = this.getAllChannelNames();
5946
- const forAnotherClient = restrictions.windowId && restrictions.windowId !== this.interop.instance.instance;
5947
- if (forAnotherClient) {
5948
- return this.bridge.send("channels", operations$5.restrictAll, { restrictions }, undefined, { includeOperationCheck: true });
5949
- }
5950
- const allRestrictions = {};
5951
- allChannelNames.forEach((name) => {
5952
- allRestrictions[name] = { ...restrictions, name };
5953
- });
6081
+ const configData = {
6082
+ restrictions: {
6083
+ ...restrictions,
6084
+ windowId: restrictions.windowId ?? this.myWindowId
6085
+ }
6086
+ };
6087
+ return this.bridge.send("channels", operations$5.restrictAll, configData, undefined, { includeOperationCheck: true });
6088
+ }
6089
+ async handleRestrictAll({ restrictions }) {
5954
6090
  const currentChannel = await this.getMy();
5955
- const prevReadAllowed = this.checkPreviousReadAllowed(currentChannel?.name);
5956
- this.sessionController.setWindowData(allRestrictions, "restrictions");
5957
- if (!currentChannel || prevReadAllowed || !restrictions.read) {
6091
+ if (!currentChannel) {
6092
+ return this.updateAllRestrictions(restrictions);
6093
+ }
6094
+ const prevReadAllowed = this.isAllowedByRestrictions(currentChannel.name, "read");
6095
+ this.updateAllRestrictions(restrictions);
6096
+ if (prevReadAllowed || !restrictions.read) {
5958
6097
  return;
5959
6098
  }
5960
6099
  this.replaySubscribeCallback(currentChannel.name);
@@ -5970,7 +6109,7 @@ class ChannelsController {
5970
6109
  await this.handleSetPaths("setPaths", dataPaths, name);
5971
6110
  }
5972
6111
  async handleSetPaths(operation, paths, name) {
5973
- const channelNamesToUpdate = name ? [name] : this.currentChannels;
6112
+ const channelNamesToUpdate = name ? [name] : this.storage.channels;
5974
6113
  if (!channelNamesToUpdate.length) {
5975
6114
  return ioError.raiseError(`Cannot complete ${operation} operation, because channel is not specified. Either join one or pass a channel name as second argument!`);
5976
6115
  }
@@ -6004,18 +6143,9 @@ class ChannelsController {
6004
6143
  }, { allowed: [], forbidden: [] });
6005
6144
  }
6006
6145
  isAllowedByRestrictions(channelName, action) {
6007
- const { channels } = this.getMyRestrictions();
6008
- if (!channels?.length) {
6009
- return true;
6010
- }
6011
- const restriction = channels.find((restriction) => restriction.name === channelName);
6146
+ const restriction = this.storage.restrictions.find((restriction) => restriction.name === channelName);
6012
6147
  return restriction ? restriction[action] : true;
6013
6148
  }
6014
- getMyRestrictions() {
6015
- const sessionStorageData = this.sessionController.getWindowData();
6016
- const restrictions = Object.values(sessionStorageData?.restrictions || {});
6017
- return { channels: restrictions };
6018
- }
6019
6149
  replaySubscribeCallback(channelName) {
6020
6150
  const contextName = this.createContextName(channelName);
6021
6151
  this.contexts.subscribe(contextName, (context, delta, _, __, extraData) => {
@@ -6026,26 +6156,16 @@ class ChannelsController {
6026
6156
  }
6027
6157
  }).catch(err => this.logger.error(err));
6028
6158
  }
6029
- checkPreviousReadAllowed(channelName) {
6030
- if (!channelName) {
6031
- return true;
6032
- }
6033
- const prevRestrictions = this.sessionController.getWindowData().restrictions;
6034
- if (!prevRestrictions?.[channelName]) {
6035
- return true;
6036
- }
6037
- return prevRestrictions[channelName].read;
6038
- }
6039
6159
  async publishWithOptions(data, options) {
6040
6160
  if (options.name) {
6041
6161
  const channelNames = this.getAllChannelNames();
6042
6162
  runDecoderWithIOError(channelNameDecoder(channelNames), options.name);
6043
6163
  }
6044
- const publishOnMultipleChannels = options.name ? false : this.currentChannels.length > 1;
6164
+ const publishOnMultipleChannels = options.name ? false : this.storage.channels.length > 1;
6045
6165
  if (publishOnMultipleChannels) {
6046
6166
  return this.publishOnMultipleChannels(data, options.fdc3);
6047
6167
  }
6048
- const channelName = options.name || this.currentChannels[0];
6168
+ const channelName = options.name || this.storage.channels[0];
6049
6169
  if (!channelName) {
6050
6170
  return ioError.raiseError("Cannot publish to channel, because not joined to a channel!");
6051
6171
  }
@@ -6059,9 +6179,9 @@ class ChannelsController {
6059
6179
  return this.publishFdc3Data(channelName, data);
6060
6180
  }
6061
6181
  async publishOnMultipleChannels(data, isFdc3) {
6062
- const { allowed, forbidden } = this.groupChannelsByPermission("write", this.currentChannels);
6063
- if (this.currentChannels.length === forbidden.length) {
6064
- return ioError.raiseError(`Cannot complete 'publish' operation due to write restrictions to all joined channels: ${this.currentChannels.join(", ")}`);
6182
+ const { allowed, forbidden } = this.groupChannelsByPermission("write", this.storage.channels);
6183
+ if (this.storage.channels.length === forbidden.length) {
6184
+ return ioError.raiseError(`Cannot complete 'publish' operation due to write restrictions to all joined channels: ${this.storage.channels.join(", ")}`);
6065
6185
  }
6066
6186
  if (forbidden.length) {
6067
6187
  this.logger.warn(`Data on channel${forbidden.length > 1 ? "s" : ""}: ${forbidden.join(", ")} won't be published due to write restrictions`);
@@ -6137,10 +6257,8 @@ class ChannelsController {
6137
6257
  if (!myAppDetails?.channelSelector?.enabled) {
6138
6258
  return;
6139
6259
  }
6140
- const { channels: channelsStorageData } = this.sessionController.getWindowData();
6141
6260
  const windowId = myInstance.id;
6142
- const channelsNames = channelsStorageData?.currentNames || [];
6143
- const requestChannelSelectorConfig = { windowId, channelsNames };
6261
+ const requestChannelSelectorConfig = { windowId, channelsNames: this.storage.channels };
6144
6262
  await this.bridge.send("channels", operations$5.requestChannelSelector, requestChannelSelectorConfig, undefined, { includeOperationCheck: true });
6145
6263
  }
6146
6264
  async getPlatformChannelsMode() {
@@ -6159,6 +6277,46 @@ class ChannelsController {
6159
6277
  }
6160
6278
  return this.registry.add(CHANNELS_CHANGED, callback);
6161
6279
  }
6280
+ async initialize() {
6281
+ const isAppHelloSupported = await this.checkIfAppHelloSupported();
6282
+ if (!isAppHelloSupported) {
6283
+ return this.handleAppHelloFailure("Platform does not support 'appHello' operation and channel state persistence by windowId. Setting 'sessionStorage' mode for tracking channels and restrictions");
6284
+ }
6285
+ const { success, error } = await this.sendAppHello();
6286
+ if (error) {
6287
+ return this.handleAppHelloFailure(error);
6288
+ }
6289
+ this.logger.trace(`Received 'appHelloSuccess' message. Setting initial channels state to: ${JSON.stringify(success)}`);
6290
+ const { mode, channels, restrictions } = success;
6291
+ this.storage.mode = "inMemory";
6292
+ this._mode = mode;
6293
+ this.storage.channels = channels;
6294
+ this.storage.restrictions = restrictions;
6295
+ }
6296
+ async handleAppHelloFailure(errorMsg) {
6297
+ this.logger.trace(errorMsg);
6298
+ this.storage.mode = "sessionStorage";
6299
+ this._mode = await this.getPlatformChannelsMode();
6300
+ }
6301
+ async sendAppHello() {
6302
+ try {
6303
+ const result = await this.bridge.send("channels", operations$5.appHello, { windowId: this.myWindowId }, undefined, { includeOperationCheck: true });
6304
+ return { success: result, error: undefined };
6305
+ }
6306
+ catch (error) {
6307
+ return { error: `Failed to get initial state from platform. Error: ${extractErrorMsg(error)}`, success: undefined };
6308
+ }
6309
+ }
6310
+ async checkIfAppHelloSupported() {
6311
+ try {
6312
+ const { isSupported } = await this.bridge.send("channels", operations$5.operationCheck, { operation: operations$5.appHello.name }, undefined, { includeOperationCheck: true });
6313
+ return isSupported;
6314
+ }
6315
+ catch (error) {
6316
+ this.logger.trace(`Platform does not support 'appHello' operation and channel state persistence by windowId. Error: ${extractErrorMsg(error)}`);
6317
+ return false;
6318
+ }
6319
+ }
6162
6320
  }
6163
6321
 
6164
6322
  const operations$4 = {
@@ -6766,31 +6924,84 @@ class ThemesController {
6766
6924
  }
6767
6925
  }
6768
6926
 
6769
- class SessionStorageController {
6927
+ class ChannelsStorage {
6770
6928
  sessionStorage = window.sessionStorage;
6771
- windowId;
6772
- get allNamespaces() {
6773
- return [{ namespace: this.windowNamespace, defaultValue: {} }];
6929
+ _mode = DEFAULT_STORAGE_MODE;
6930
+ inMemoryChannels = [];
6931
+ inMemoryRestrictions = [];
6932
+ _unsubscribeDict = {};
6933
+ clear() {
6934
+ this._mode = DEFAULT_STORAGE_MODE;
6935
+ this.inMemoryChannels = [];
6936
+ this.inMemoryRestrictions = [];
6937
+ this._unsubscribeDict = {};
6938
+ this.sessionStorage.setItem(STORAGE_NAMESPACE, JSON.stringify([]));
6774
6939
  }
6775
- configure(config) {
6776
- this.windowId = config.windowId;
6777
- this.allNamespaces.forEach(({ namespace, defaultValue }) => {
6778
- const data = this.sessionStorage.getItem(namespace);
6779
- if (!data) {
6780
- this.sessionStorage.setItem(namespace, JSON.stringify(defaultValue));
6781
- }
6782
- });
6940
+ get mode() {
6941
+ return this._mode;
6783
6942
  }
6784
- get windowNamespace() {
6785
- return `io_connect_window_${this.windowId}`;
6943
+ set mode(mode) {
6944
+ this._mode = mode;
6786
6945
  }
6787
- getWindowData() {
6788
- return JSON.parse(this.sessionStorage.getItem(this.windowNamespace));
6946
+ get channels() {
6947
+ if (this.mode === "inMemory") {
6948
+ return this.inMemoryChannels.slice();
6949
+ }
6950
+ return this.getSessionStorageData()?.channels ?? [];
6789
6951
  }
6790
- setWindowData(data, key) {
6791
- const allData = this.getWindowData();
6792
- allData[key] = data;
6793
- this.sessionStorage.setItem(this.windowNamespace, JSON.stringify(allData));
6952
+ set channels(channels) {
6953
+ if (this.mode === "inMemory") {
6954
+ this.inMemoryChannels = channels;
6955
+ }
6956
+ this.setSessionStorageChannels(channels);
6957
+ }
6958
+ get restrictions() {
6959
+ if (this.mode === "inMemory") {
6960
+ return this.inMemoryRestrictions.slice();
6961
+ }
6962
+ return this.getSessionStorageData()?.restrictions ?? [];
6963
+ }
6964
+ set restrictions(restrictions) {
6965
+ if (this.mode === "inMemory") {
6966
+ this.inMemoryRestrictions = restrictions;
6967
+ }
6968
+ this.setSessionStorageRestrictions(restrictions);
6969
+ }
6970
+ getSessionStorageData() {
6971
+ return JSON.parse(this.sessionStorage.getItem(STORAGE_NAMESPACE) || "null");
6972
+ }
6973
+ addUnsubscribe(channel, unsubscribe) {
6974
+ this._unsubscribeDict[channel] = unsubscribe;
6975
+ }
6976
+ invokeUnsubscribes(channel) {
6977
+ if (channel) {
6978
+ this._unsubscribeDict[channel]?.();
6979
+ delete this._unsubscribeDict[channel];
6980
+ return;
6981
+ }
6982
+ Object.values(this._unsubscribeDict).forEach((unsub) => unsub());
6983
+ this._unsubscribeDict = {};
6984
+ }
6985
+ setSessionStorageChannels(channels) {
6986
+ const data = this.getSessionStorageData();
6987
+ if (data?.channels) {
6988
+ data.channels = channels;
6989
+ return this.setSessionStorageData(data);
6990
+ }
6991
+ const newData = { channels, restrictions: data?.restrictions ?? [] };
6992
+ return this.setSessionStorageData(newData);
6993
+ }
6994
+ setSessionStorageRestrictions(restrictions) {
6995
+ const data = this.getSessionStorageData();
6996
+ if (data?.restrictions) {
6997
+ data.restrictions = restrictions;
6998
+ return this.setSessionStorageData(data);
6999
+ }
7000
+ const newData = { channels: data?.channels ?? [], restrictions };
7001
+ return this.setSessionStorageData(newData);
7002
+ }
7003
+ setSessionStorageData(data) {
7004
+ this.sessionStorage.setItem(STORAGE_NAMESPACE, JSON.stringify(data));
6794
7005
  }
6795
7006
  }
6796
7007
 
@@ -6925,7 +7136,7 @@ class PrefsController {
6925
7136
  return ioError.raiseError("Cannot subscribe to prefs, because the provided callback is not a function!");
6926
7137
  }
6927
7138
  if (!this.signaledSubscription) {
6928
- this.bridge.send("prefs", operations$1.registerSubscriber, { interopId: this.interopId }, undefined, { includeOperationCheck: true })
7139
+ this.bridge.send("prefs", operations$1.registerSubscriber, { interopId: this.interopId, appName: verifiedApp }, undefined, { includeOperationCheck: true })
6929
7140
  .catch((error) => {
6930
7141
  this.logger.warn("Failed to register subscriber for prefs");
6931
7142
  this.logger.error(error);
@@ -7376,7 +7587,7 @@ class IoC {
7376
7587
  _bridgeInstance;
7377
7588
  _eventsDispatcher;
7378
7589
  _preferredConnectionController;
7379
- _sessionController;
7590
+ _channelsStorage;
7380
7591
  _prefsControllerInstance;
7381
7592
  _uiController;
7382
7593
  controllers = {
@@ -7482,11 +7693,11 @@ class IoC {
7482
7693
  }
7483
7694
  return this._preferredConnectionController;
7484
7695
  }
7485
- get sessionController() {
7486
- if (!this._sessionController) {
7487
- this._sessionController = new SessionStorageController();
7696
+ get channelsStorage() {
7697
+ if (!this._channelsStorage) {
7698
+ this._channelsStorage = new ChannelsStorage();
7488
7699
  }
7489
- return this._sessionController;
7700
+ return this._channelsStorage;
7490
7701
  }
7491
7702
  get config() {
7492
7703
  return this._webConfig;
@@ -7500,8 +7711,8 @@ class IoC {
7500
7711
  defineConfig(config) {
7501
7712
  this._webConfig = config;
7502
7713
  }
7503
- async buildWebWindow(id, name) {
7504
- const model = new WebWindowModel(id, name, this.bridge);
7714
+ async buildWebWindow(id, name, logger) {
7715
+ const model = new WebWindowModel(id, name, this.bridge, logger);
7505
7716
  const api = await model.toApi();
7506
7717
  return { id, model, api };
7507
7718
  }
@@ -7519,7 +7730,7 @@ class IoC {
7519
7730
  }
7520
7731
  }
7521
7732
 
7522
- var version$1 = "4.0.3";
7733
+ var version$1 = "4.1.1-beta.0";
7523
7734
 
7524
7735
  const setupGlobalSystem = (io, bridge) => {
7525
7736
  return {
@@ -7555,7 +7766,6 @@ const createFactoryFunction = (coreFactoryFunction) => {
7555
7766
  const glue = await PromiseWrap(() => coreFactoryFunction(config, { version: version$1 }), 30000, "Glue Web initialization timed out, because core didn't resolve");
7556
7767
  const logger = glue.logger.subLogger("web.main.controller");
7557
7768
  ioc.defineGlue(glue);
7558
- ioc.sessionController.configure({ windowId: glue.interop.instance.instance });
7559
7769
  await ioc.preferredConnectionController.start(config);
7560
7770
  await ioc.bridge.start(ioc.controllers);
7561
7771
  ioc.defineConfig(config);
@@ -8939,6 +9149,7 @@ class WebPlatformTransport {
8939
9149
  logger;
8940
9150
  identity;
8941
9151
  isPreferredActivated;
9152
+ _connectionProtocolVersion;
8942
9153
  _communicationId;
8943
9154
  publicWindowId;
8944
9155
  selfAssignedWindowId;
@@ -9154,24 +9365,34 @@ class WebPlatformTransport {
9154
9365
  return;
9155
9366
  }
9156
9367
  window.addEventListener("beforeunload", () => {
9157
- if (this.extContentConnected) {
9368
+ if (this._connectionProtocolVersion) {
9158
9369
  return;
9159
9370
  }
9160
- const message = {
9161
- glue42core: {
9162
- type: this.messages.clientUnload.name,
9163
- data: {
9164
- clientId: this.myClientId,
9165
- ownWindowId: this.identity?.windowId
9166
- }
9167
- }
9168
- };
9169
- if (this.parent) {
9170
- this.parent.postMessage(message, this.defaultTargetString);
9371
+ this.signalClientDisappearing();
9372
+ });
9373
+ window.addEventListener("pagehide", () => {
9374
+ if (!this._connectionProtocolVersion) {
9375
+ return;
9171
9376
  }
9172
- this.port?.postMessage(message);
9377
+ this.signalClientDisappearing();
9173
9378
  });
9174
9379
  }
9380
+ signalClientDisappearing() {
9381
+ if (this.extContentConnected) {
9382
+ return;
9383
+ }
9384
+ const message = {
9385
+ glue42core: {
9386
+ type: this.messages.clientUnload.name,
9387
+ data: {
9388
+ clientId: this.myClientId,
9389
+ ownWindowId: this.identity?.windowId
9390
+ }
9391
+ }
9392
+ };
9393
+ this.parent?.postMessage(message, this.defaultTargetString);
9394
+ this.port?.postMessage(message);
9395
+ }
9175
9396
  handlePlatformReady(event) {
9176
9397
  this.logger.debug("the web platform gave the ready signal");
9177
9398
  this.parentReady = true;
@@ -9203,6 +9424,7 @@ class WebPlatformTransport {
9203
9424
  this.logger.error("cannot set up my connection, because I was not provided with a port");
9204
9425
  return;
9205
9426
  }
9427
+ this._connectionProtocolVersion = data.connectionProtocolVersion;
9206
9428
  this.publicWindowId = this.getMyWindowId();
9207
9429
  if (this.identity) {
9208
9430
  this.identity.windowId = this.publicWindowId;
@@ -9682,7 +9904,7 @@ function domainSession (domain, connection, logger, successMessages, errorMessag
9682
9904
  resolve(successMsg);
9683
9905
  },
9684
9906
  error: (errorMsg) => {
9685
- logger.warn(`Gateway error - ${JSON.stringify(errorMsg)}`);
9907
+ console.warn(`Gateway error - ${JSON.stringify(errorMsg)}`);
9686
9908
  delete requestsMap[requestId];
9687
9909
  errorMsg._tag = tag;
9688
9910
  reject(errorMsg);
@@ -10437,7 +10659,12 @@ class Logger {
10437
10659
  this.logFn.warn(toPrint);
10438
10660
  break;
10439
10661
  case "error":
10440
- this.logFn.error(toPrint, error);
10662
+ if (error) {
10663
+ this.logFn.error(toPrint, error);
10664
+ }
10665
+ else {
10666
+ this.logFn.error(toPrint);
10667
+ }
10441
10668
  break;
10442
10669
  }
10443
10670
  }
@@ -10481,7 +10708,7 @@ const ContextMessageReplaySpec = {
10481
10708
  }
10482
10709
  };
10483
10710
 
10484
- var version = "6.6.0";
10711
+ var version = "6.7.1-beta.0";
10485
10712
 
10486
10713
  function prepareConfig (configuration, ext, glue42gd) {
10487
10714
  let nodeStartingContext;
@@ -10623,9 +10850,10 @@ function prepareConfig (configuration, ext, glue42gd) {
10623
10850
  gatewayToken: nodeStartingContext.gwToken
10624
10851
  };
10625
10852
  }
10626
- if (configuration.gateway?.webPlatform || configuration.gateway?.inproc || configuration.gateway?.sharedWorker) {
10853
+ if (configuration.gateway?.webPlatform) {
10627
10854
  return {
10628
- username: "glue42", password: "glue42"
10855
+ username: "glue42",
10856
+ password: ""
10629
10857
  };
10630
10858
  }
10631
10859
  }
@@ -12569,15 +12797,20 @@ function deepEqual(x, y) {
12569
12797
  }
12570
12798
  function setValueToPath(obj, value, path) {
12571
12799
  const pathArr = path.split(".");
12800
+ const forbiddenKeys = ["__proto__", "constructor", "prototype"];
12572
12801
  let i;
12573
12802
  for (i = 0; i < pathArr.length - 1; i++) {
12574
- if (!obj[pathArr[i]]) {
12575
- obj[pathArr[i]] = {};
12803
+ const key = pathArr[i];
12804
+ if (forbiddenKeys.includes(key)) {
12805
+ throw new Error(`The provided path ${path} is invalid. It cannot contain segment/key that is equal to one of the following values: ${forbiddenKeys}.`);
12576
12806
  }
12577
- if (typeof obj[pathArr[i]] !== "object") {
12578
- obj[pathArr[i]] = {};
12807
+ if (!obj[key]) {
12808
+ obj[key] = {};
12579
12809
  }
12580
- obj = obj[pathArr[i]];
12810
+ if (typeof obj[key] !== "object") {
12811
+ obj[key] = {};
12812
+ }
12813
+ obj = obj[key];
12581
12814
  }
12582
12815
  obj[pathArr[i]] = value;
12583
12816
  }