@interopio/browser 4.0.2 → 4.1.0-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.
@@ -932,6 +932,7 @@
932
932
  awaitFactory: true,
933
933
  enable: false,
934
934
  timeout: 5 * 1000,
935
+ restoreLastKnownPosition: true,
935
936
  };
936
937
  const defaultModalsConfig = {
937
938
  alerts: {
@@ -967,6 +968,11 @@
967
968
  const REQUEST_MODALS_UI_FACTORY_READY = "requestModalsUIFactoryReady";
968
969
  const MAX_SET_TIMEOUT_DELAY = 2147483647;
969
970
  const REQUEST_INTENT_RESOLVER_UI_FACTORY_READY = "requestIntentResolverUIFactoryReady";
971
+ const READONLY_PROPERTY_DESCRIPTOR = {
972
+ configurable: false,
973
+ enumerable: true,
974
+ writable: false,
975
+ };
970
976
 
971
977
  const extractErrorMsg = (error) => {
972
978
  if (typeof error === "string") {
@@ -2183,7 +2189,7 @@
2183
2189
  const nonNegativeNumberDecoder$2 = number$2().where((num) => num >= 0, "Expected a non-negative number");
2184
2190
  const optionalNonEmptyStringDecoder = optional$2(nonEmptyStringDecoder$2);
2185
2191
  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"));
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("operationCheck"));
2192
+ 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"));
2187
2193
  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"));
2188
2194
  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"));
2189
2195
  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"));
@@ -2262,6 +2268,10 @@
2262
2268
  windowId: nonEmptyStringDecoder$2,
2263
2269
  url: nonEmptyStringDecoder$2
2264
2270
  });
2271
+ const windowZoomFactorConfigDecoder = object$2({
2272
+ windowId: nonEmptyStringDecoder$2,
2273
+ factorIndex: nonNegativeNumberDecoder$2
2274
+ });
2265
2275
  const anyDecoder = anyJson$2();
2266
2276
  const boundsDecoder = object$2({
2267
2277
  top: optional$2(number$2()),
@@ -2375,7 +2385,8 @@
2375
2385
  restoreSettings: object$2({
2376
2386
  groupId: optional$2(nonEmptyStringDecoder$2),
2377
2387
  groupZOrder: optional$2(number$2())
2378
- })
2388
+ }),
2389
+ channelId: optional$2(nonEmptyStringDecoder$2),
2379
2390
  });
2380
2391
  const windowLayoutComponentDecoder = object$2({
2381
2392
  type: constant$2("window"),
@@ -2917,9 +2928,18 @@
2917
2928
  const getWindowIdsOnChannelResultDecoder = object$2({
2918
2929
  windowIds: array$2(nonEmptyStringDecoder$2)
2919
2930
  });
2920
- 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"));
2931
+ 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"));
2932
+ const modeDecoder = oneOf$1(constant$2("single"), constant$2("multi"));
2921
2933
  const getChannelsModeDecoder = object$2({
2922
- mode: oneOf$1(constant$2("single"), constant$2("multi"))
2934
+ mode: modeDecoder
2935
+ });
2936
+ const channelsAppHelloDataDecoder = object$2({
2937
+ windowId: nonEmptyStringDecoder$2
2938
+ });
2939
+ const channelsAppHelloSuccessDecoder = object$2({
2940
+ mode: modeDecoder,
2941
+ channels: array$2(nonEmptyStringDecoder$2),
2942
+ restrictions: array$2(channelRestrictionsDecoder)
2923
2943
  });
2924
2944
  const getMyChanelResultDecoder = object$2({
2925
2945
  channel: optional$2(nonEmptyStringDecoder$2)
@@ -2984,6 +3004,7 @@
2984
3004
  });
2985
3005
  const subscriberRegisterConfigDecoder = object$2({
2986
3006
  interopId: nonEmptyStringDecoder$2,
3007
+ appName: optional$2(nonEmptyStringDecoder$2)
2987
3008
  });
2988
3009
  const changePrefsDataDecoder = object$2({
2989
3010
  app: nonEmptyStringDecoder$2,
@@ -3024,8 +3045,7 @@
3024
3045
  type: optional$2(channelSelectorTypeDecoder),
3025
3046
  enable: optional$2(boolean$2())
3026
3047
  });
3027
- const positionDecoder = oneOf$1(constant$2("top"), constant$2("bottom"), constant$2("left"), constant$2("right"));
3028
- const modeDecoder = oneOf$1(constant$2("default"), constant$2("compact"));
3048
+ 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"));
3029
3049
  const displayModeDecoder = oneOf$1(constant$2("all"), constant$2("fdc3"));
3030
3050
  const widgetChannelsDecoder = object$2({
3031
3051
  selector: optional$2(channelSelectorDecoder),
@@ -3034,8 +3054,8 @@
3034
3054
  const platformWidgetDefaultConfigDecoder = object$2({
3035
3055
  channels: optional$2(widgetChannelsDecoder),
3036
3056
  position: optional$2(positionDecoder),
3037
- mode: optional$2(modeDecoder),
3038
- displayInWorkspace: optional$2(boolean$2())
3057
+ displayInWorkspace: optional$2(boolean$2()),
3058
+ restoreLastKnownPosition: optional$2(boolean$2()),
3039
3059
  });
3040
3060
  const widgetConfigDecoder = object$2({
3041
3061
  enable: boolean$2(),
@@ -3043,8 +3063,8 @@
3043
3063
  timeout: optional$2(nonNegativeNumberDecoder$1),
3044
3064
  channels: optional$2(widgetChannelsDecoder),
3045
3065
  position: optional$2(positionDecoder),
3046
- mode: optional$2(modeDecoder),
3047
- displayInWorkspace: optional$2(boolean$2())
3066
+ displayInWorkspace: optional$2(boolean$2()),
3067
+ restoreLastKnownPosition: optional$2(boolean$2()),
3048
3068
  });
3049
3069
  const modalsConfigDecoder = object$2({
3050
3070
  alerts: optional$2(object$2({
@@ -3278,6 +3298,9 @@
3278
3298
  focusChange: { name: "focusChange", dataDecoder: focusEventDataDecoder },
3279
3299
  getChannel: { name: "getChannel", dataDecoder: simpleWindowDecoder, resultDecoder: windowChannelResultDecoder },
3280
3300
  notifyChannelsChanged: { name: "notifyChannelsChanged", dataDecoder: channelsChangedDataDecoder },
3301
+ setZoomFactor: { name: "setZoomFactor", dataDecoder: windowZoomFactorConfigDecoder },
3302
+ zoomFactorChange: { name: "zoomFactorChange", dataDecoder: windowZoomFactorConfigDecoder },
3303
+ refresh: { name: "refresh", dataDecoder: simpleWindowDecoder },
3281
3304
  operationCheck: { name: "operationCheck" }
3282
3305
  };
3283
3306
 
@@ -3401,18 +3424,41 @@
3401
3424
 
3402
3425
  var CallbackRegistryFactory$1 = /*@__PURE__*/getDefaultExportFromCjs$1(lib$1);
3403
3426
 
3427
+ const ZOOM_FACTORS = Object.freeze({
3428
+ 0: 24,
3429
+ 1: 33,
3430
+ 2: 50,
3431
+ 3: 67,
3432
+ 4: 75,
3433
+ 5: 80,
3434
+ 6: 90,
3435
+ 7: 100,
3436
+ 8: 110,
3437
+ 9: 125,
3438
+ 10: 150,
3439
+ 11: 175,
3440
+ 12: 200,
3441
+ 13: 250,
3442
+ 14: 300,
3443
+ 15: 400,
3444
+ 16: 500
3445
+ });
3446
+
3404
3447
  class WebWindowModel {
3405
3448
  _id;
3406
3449
  _name;
3407
3450
  _bridge;
3451
+ _logger;
3408
3452
  registry = CallbackRegistryFactory$1();
3409
3453
  myCtxKey;
3410
3454
  ctxUnsubscribe;
3455
+ zoomFactorIndex = 7;
3411
3456
  me;
3412
- constructor(_id, _name, _bridge) {
3457
+ constructor(_id, _name, _bridge, _logger) {
3413
3458
  this._id = _id;
3414
3459
  this._name = _name;
3415
3460
  this._bridge = _bridge;
3461
+ this._logger = _logger;
3416
3462
  this.myCtxKey = `___window___${this.id}`;
3417
3463
  }
3418
3464
  get id() {
@@ -3421,6 +3467,9 @@
3421
3467
  get name() {
3422
3468
  return this._name.slice();
3423
3469
  }
3470
+ get zoomFactor() {
3471
+ return ZOOM_FACTORS[this.zoomFactorIndex];
3472
+ }
3424
3473
  clean() {
3425
3474
  if (this.ctxUnsubscribe) {
3426
3475
  this.ctxUnsubscribe();
@@ -3433,12 +3482,17 @@
3433
3482
  processChannelsChangedEvent(channelNames) {
3434
3483
  this.registry.execute("channels-changed", channelNames);
3435
3484
  }
3485
+ processSelfZoomFactorChangedEvent(factorIndex) {
3486
+ this.zoomFactorIndex = factorIndex;
3487
+ this.registry.execute("zoom-factor-changed", this.me);
3488
+ }
3436
3489
  async toApi() {
3437
3490
  this.ctxUnsubscribe = await this._bridge.contextLib.subscribe(this.myCtxKey, (data) => this.registry.execute("context-updated", data));
3438
3491
  this.me = {
3439
3492
  id: this.id,
3440
3493
  name: this.name,
3441
3494
  isFocused: false,
3495
+ zoomFactor: this.zoomFactor,
3442
3496
  getURL: this.getURL.bind(this),
3443
3497
  moveResize: this.moveResize.bind(this),
3444
3498
  resizeTo: this.resizeTo.bind(this),
@@ -3451,11 +3505,26 @@
3451
3505
  getContext: this.getContext.bind(this),
3452
3506
  updateContext: this.updateContext.bind(this),
3453
3507
  setContext: this.setContext.bind(this),
3508
+ refresh: this.refresh.bind(this),
3454
3509
  onContextUpdated: this.onContextUpdated.bind(this),
3455
3510
  onFocusChanged: this.onFocusChanged.bind(this),
3456
3511
  getChannel: this.getChannel.bind(this),
3457
3512
  onChannelsChanged: this.onChannelsChanged.bind(this),
3513
+ zoomIn: this.zoomIn.bind(this),
3514
+ zoomOut: this.zoomOut.bind(this),
3515
+ setZoomFactor: this.setZoomFactor.bind(this),
3516
+ onZoomFactorChanged: this.onZoomFactorChanged.bind(this),
3458
3517
  };
3518
+ Object.defineProperties(this.me, {
3519
+ id: READONLY_PROPERTY_DESCRIPTOR,
3520
+ name: READONLY_PROPERTY_DESCRIPTOR,
3521
+ zoomFactor: {
3522
+ get: () => {
3523
+ return this.zoomFactor;
3524
+ },
3525
+ enumerable: true,
3526
+ },
3527
+ });
3459
3528
  return this.me;
3460
3529
  }
3461
3530
  async getURL() {
@@ -3562,6 +3631,47 @@
3562
3631
  onChannelsChanged(callback) {
3563
3632
  return this.registry.add("channels-changed", callback);
3564
3633
  }
3634
+ getClosestZoomFactorIndex(factor) {
3635
+ const closestIndex = Object.entries(ZOOM_FACTORS).reduce((closestIndex, [currentIndex, currentValue]) => {
3636
+ return (Math.abs(currentValue - factor) <= Math.abs(ZOOM_FACTORS[closestIndex] - factor) ? parseInt(currentIndex) : closestIndex);
3637
+ }, 0);
3638
+ const closestFactor = ZOOM_FACTORS[closestIndex];
3639
+ if (closestFactor !== factor) {
3640
+ this._logger.warn(`Zoom factor ${factor} is not available, using closest value ${closestFactor} instead.`);
3641
+ }
3642
+ return closestIndex;
3643
+ }
3644
+ async zoom(factorIndex) {
3645
+ if (factorIndex === this.zoomFactorIndex || !(factorIndex in ZOOM_FACTORS)) {
3646
+ return;
3647
+ }
3648
+ await this._bridge.send("windows", operations$a.setZoomFactor, { windowId: this.id, factorIndex }, undefined, { includeOperationCheck: true });
3649
+ this.zoomFactorIndex = factorIndex;
3650
+ }
3651
+ async zoomIn() {
3652
+ await this.zoom(this.zoomFactorIndex + 1);
3653
+ return this.me;
3654
+ }
3655
+ async zoomOut() {
3656
+ await this.zoom(this.zoomFactorIndex - 1);
3657
+ return this.me;
3658
+ }
3659
+ async setZoomFactor(factor) {
3660
+ const targetZoomFactor = runDecoderWithIOError(number$2(), factor);
3661
+ const closestZoomFactorIndex = this.getClosestZoomFactorIndex(targetZoomFactor);
3662
+ await this.zoom(closestZoomFactorIndex);
3663
+ return this.me;
3664
+ }
3665
+ onZoomFactorChanged(callback) {
3666
+ if (typeof callback !== "function") {
3667
+ return ioError.raiseError("Cannot subscribe to zoom factor changes, because the provided callback is not a function!");
3668
+ }
3669
+ return this.registry.add("zoom-factor-changed", callback);
3670
+ }
3671
+ async refresh() {
3672
+ await this._bridge.send("windows", operations$a.refresh, { windowId: this.id }, undefined, { includeOperationCheck: true });
3673
+ return this.me;
3674
+ }
3565
3675
  }
3566
3676
 
3567
3677
  const commonOperations = {
@@ -3710,6 +3820,9 @@
3710
3820
  operations$a.setTitle.execute = this.handleSetTitle.bind(this);
3711
3821
  operations$a.getChannel.execute = this.handleGetChannel.bind(this);
3712
3822
  operations$a.notifyChannelsChanged.execute = this.handleChannelsChanged.bind(this);
3823
+ operations$a.setZoomFactor.execute = this.handleSetZoomFactor.bind(this);
3824
+ operations$a.zoomFactorChange.execute = this.handleZoomFactorChanged.bind(this);
3825
+ operations$a.refresh.execute = this.handleRefresh.bind(this);
3713
3826
  operations$a.operationCheck.execute = async (config) => handleOperationCheck(this.supportedOperationsNames, config.operation);
3714
3827
  this.supportedOperationsNames = getSupportedOperationsNames(operations$a);
3715
3828
  }
@@ -3755,13 +3868,13 @@
3755
3868
  const windowsInfo = windows.map(w => `${w.windowId}:${w.name}`).join(", ");
3756
3869
  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}`);
3757
3870
  }
3758
- const myProjection = await this.ioc.buildWebWindow(this.publicWindowId, myWindow.name);
3871
+ const myProjection = await this.ioc.buildWebWindow(this.publicWindowId, myWindow.name, this.logger);
3759
3872
  this.me = myProjection.api;
3760
3873
  this.allWindowProjections.push(myProjection);
3761
3874
  }
3762
3875
  const currentWindows = await Promise.all(windows
3763
3876
  .filter((w) => w.windowId !== this.publicWindowId)
3764
- .map((w) => this.ioc.buildWebWindow(w.windowId, w.name)));
3877
+ .map((w) => this.ioc.buildWebWindow(w.windowId, w.name, this.logger)));
3765
3878
  this.logger.trace("all windows projections are completed, building the list collection");
3766
3879
  this.allWindowProjections.push(...currentWindows);
3767
3880
  }
@@ -3778,7 +3891,7 @@
3778
3891
  if (this.allWindowProjections.some((projection) => projection.id === data.windowId)) {
3779
3892
  return;
3780
3893
  }
3781
- const webWindowProjection = await this.ioc.buildWebWindow(data.windowId, data.name);
3894
+ const webWindowProjection = await this.ioc.buildWebWindow(data.windowId, data.name, this.logger);
3782
3895
  this.allWindowProjections.push(webWindowProjection);
3783
3896
  this.registry.execute("window-added", webWindowProjection.api);
3784
3897
  }
@@ -3895,17 +4008,38 @@
3895
4008
  }
3896
4009
  async handleGetChannel() {
3897
4010
  if (!this.me) {
3898
- return ioError.raiseError("This window cannot report it's channel, because it is not a Glue Window, most likely because it is an iframe");
4011
+ return ioError.raiseError("This window cannot report its channel, because it is not a ioConnect Window, most likely because it is an iframe");
3899
4012
  }
3900
4013
  const channel = this.channelsController.my();
3901
4014
  return {
3902
4015
  ...(channel ? { channel } : {}),
3903
4016
  };
3904
4017
  }
4018
+ async handleRefresh() {
4019
+ if (!this.me) {
4020
+ return ioError.raiseError("This window cannot refresh, because it is not an ioConnect Window, most likely because it is an iframe");
4021
+ }
4022
+ setTimeout(() => {
4023
+ window.location.reload();
4024
+ }, 0);
4025
+ }
3905
4026
  async handleChannelsChanged(data) {
3906
4027
  const windowProjection = this.allWindowProjections.find((projection) => projection.id === data.windowId);
3907
4028
  windowProjection?.model.processChannelsChangedEvent(data.channelNames);
3908
4029
  }
4030
+ async handleSetZoomFactor(config) {
4031
+ if (!this.me) {
4032
+ return ioError.raiseError("This window cannot change its zoom factor, because it is not an ioConnect Window, most likely because it is an iframe");
4033
+ }
4034
+ document.body.style.zoom = `${ZOOM_FACTORS[config.factorIndex]}%`;
4035
+ }
4036
+ async handleZoomFactorChanged(data) {
4037
+ const foundProjection = this.allWindowProjections.find((projection) => projection.id === data.windowId);
4038
+ if (!foundProjection) {
4039
+ return;
4040
+ }
4041
+ foundProjection.model.processSelfZoomFactorChangedEvent(data.factorIndex);
4042
+ }
3909
4043
  }
3910
4044
 
3911
4045
  const GlueWebPlatformControlName = "T42.Web.Platform.Control";
@@ -4109,8 +4243,8 @@
4109
4243
  platformRegistration;
4110
4244
  logger;
4111
4245
  channelsController;
4112
- sessionController;
4113
4246
  interop;
4247
+ initialChannelId;
4114
4248
  handlePlatformShutdown() {
4115
4249
  this.registry.clear();
4116
4250
  this.applications = [];
@@ -4125,7 +4259,6 @@
4125
4259
  this.ioc = ioc;
4126
4260
  this.bridge = ioc.bridge;
4127
4261
  this.channelsController = ioc.channelsController;
4128
- this.sessionController = ioc.sessionController;
4129
4262
  this.interop = coreGlue.interop;
4130
4263
  this.platformRegistration = this.registerWithPlatform();
4131
4264
  await this.platformRegistration;
@@ -4133,6 +4266,12 @@
4133
4266
  const api = this.toApi();
4134
4267
  coreGlue.appManager = api;
4135
4268
  }
4269
+ async postStart() {
4270
+ if (!this.initialChannelId) {
4271
+ return;
4272
+ }
4273
+ await this.channelsController.handleAppManagerInitialChannelId(this.initialChannelId);
4274
+ }
4136
4275
  async handleBridgeMessage(args) {
4137
4276
  await this.platformRegistration;
4138
4277
  const operationName = runDecoderWithIOError(appManagerOperationTypesDecoder, args.operation);
@@ -4361,14 +4500,6 @@
4361
4500
  getApplications() {
4362
4501
  return this.applications.slice();
4363
4502
  }
4364
- async joinInitialChannel(initialChannelId) {
4365
- try {
4366
- await this.channelsController.join(initialChannelId);
4367
- }
4368
- catch (error) {
4369
- this.logger.warn(`Application instance ${this.me} was unable to join the ${initialChannelId} channel. Reason: ${JSON.stringify(error)}`);
4370
- }
4371
- }
4372
4503
  async registerWithPlatform() {
4373
4504
  const result = await this.bridge.send("appManager", operations$9.appHello, { windowId: this.publicWindowId }, { methodResponseTimeoutMs: this.baseApplicationsTimeoutMS });
4374
4505
  this.logger.trace("the platform responded to the hello message with a full list of apps");
@@ -4379,12 +4510,7 @@
4379
4510
  }, []);
4380
4511
  this.me = this.findMyInstance();
4381
4512
  this.logger.trace(`all applications were parsed and saved. I am ${this.me ? "NOT a" : "a"} valid instance`);
4382
- const { channels: channelsStorageData } = this.sessionController.getWindowData();
4383
- const channels = channelsStorageData ? channelsStorageData.currentNames : [result.initialChannelId];
4384
- if (!channels?.length) {
4385
- return;
4386
- }
4387
- await Promise.all(channels.map((channel) => channel ? this.joinInitialChannel(channel) : Promise.resolve()));
4513
+ this.initialChannelId = result.initialChannelId;
4388
4514
  }
4389
4515
  findMyInstance() {
4390
4516
  for (const app of this.applications) {
@@ -5459,6 +5585,7 @@
5459
5585
  }
5460
5586
 
5461
5587
  const operations$5 = {
5588
+ appHello: { name: "appHello", dataDecoder: channelsAppHelloDataDecoder, resultDecoder: channelsAppHelloSuccessDecoder },
5462
5589
  addChannel: { name: "addChannel", dataDecoder: channelDefinitionDecoder },
5463
5590
  removeChannel: { name: "removeChannel", dataDecoder: removeChannelDataDecoder },
5464
5591
  getMyChannel: { name: "getMyChannel", resultDecoder: getMyChanelResultDecoder },
@@ -5472,7 +5599,7 @@
5472
5599
  leaveChannel: { name: "leaveChannel", dataDecoder: leaveChannelDataDecoder },
5473
5600
  requestChannelSelector: { name: "requestChannelSelector", dataDecoder: requestChannelSelectorConfigDecoder },
5474
5601
  getMode: { name: "getMode", resultDecoder: getChannelsModeDecoder },
5475
- operationCheck: { name: "operationCheck" }
5602
+ operationCheck: { name: "operationCheck" },
5476
5603
  };
5477
5604
 
5478
5605
  const DEFAULT_MODE = "single";
@@ -5480,6 +5607,8 @@
5480
5607
  const SUBS_KEY = "subs";
5481
5608
  const CHANGED_KEY = "changed";
5482
5609
  const CHANNELS_CHANGED = "channels_changed";
5610
+ const STORAGE_NAMESPACE = "io_connect_channels";
5611
+ const DEFAULT_STORAGE_MODE = "inMemory";
5483
5612
 
5484
5613
  class ChannelsController {
5485
5614
  supportedOperationsNames = [];
@@ -5489,20 +5618,20 @@
5489
5618
  interop;
5490
5619
  bridge;
5491
5620
  windowsController;
5492
- sessionController;
5493
5621
  _mode;
5494
- currentChannels = [];
5495
- unsubscribeDict = {};
5622
+ myWindowId;
5623
+ storage;
5496
5624
  handlePlatformShutdown() {
5497
5625
  this.registry.clear();
5626
+ this.storage.clear();
5498
5627
  }
5499
5628
  addOperationsExecutors() {
5500
5629
  operations$5.getMyChannel.execute = this.handleGetMyChannel.bind(this);
5501
5630
  operations$5.joinChannel.execute = this.handleJoinChannel.bind(this);
5502
5631
  operations$5.leaveChannel.execute = this.handleLeaveChannel.bind(this);
5503
- operations$5.restrict.execute = ({ config }) => this.restrict(config);
5632
+ operations$5.restrict.execute = this.handleRestrict.bind(this);
5504
5633
  operations$5.getRestrictions.execute = ({ windowId }) => this.getRestrictions(windowId);
5505
- operations$5.restrictAll.execute = ({ restrictions }) => this.restrictAll(restrictions);
5634
+ operations$5.restrictAll.execute = this.handleRestrictAll.bind(this);
5506
5635
  operations$5.operationCheck.execute = async (config) => handleOperationCheck(this.supportedOperationsNames, config.operation);
5507
5636
  this.supportedOperationsNames = getSupportedOperationsNames(operations$5);
5508
5637
  }
@@ -5514,9 +5643,10 @@
5514
5643
  this.addOperationsExecutors();
5515
5644
  this.bridge = ioc.bridge;
5516
5645
  this.windowsController = ioc.windowsController;
5517
- this.sessionController = ioc.sessionController;
5646
+ this.storage = ioc.channelsStorage;
5518
5647
  this.logger.trace("no need for platform registration, attaching the channels property to glue and returning");
5519
- this._mode = await this.getPlatformChannelsMode();
5648
+ this.myWindowId = this.windowsController.my().id ?? this.interop.instance.instance;
5649
+ await this.initialize();
5520
5650
  const api = this.toApi();
5521
5651
  coreGlue.channels = api;
5522
5652
  }
@@ -5556,17 +5686,14 @@
5556
5686
  const channelNames = this.getAllChannelNames();
5557
5687
  runDecoderWithIOError(channelNameDecoder(channelNames), name);
5558
5688
  runDecoderWithIOError(optionalNonEmptyStringDecoder, windowId);
5559
- const forAnotherClient = windowId && windowId !== this.interop.instance.instance;
5560
- if (forAnotherClient) {
5561
- return await this.bridge.send("channels", operations$5.joinChannel, { channel: name, windowId }, undefined, { includeOperationCheck: true });
5562
- }
5689
+ const joinData = { channel: name, windowId: windowId ?? this.myWindowId };
5690
+ await this.bridge.send("channels", operations$5.joinChannel, joinData, undefined, { includeOperationCheck: true });
5691
+ }
5692
+ handleJoinChannel({ channel }) {
5563
5693
  if (this._mode === "single") {
5564
- return this.switchToChannel(name);
5694
+ return this.switchToChannel(channel);
5565
5695
  }
5566
- return this.joinAdditionalChannel(name);
5567
- }
5568
- handleJoinChannel({ channel, windowId }) {
5569
- return this.join(channel, windowId);
5696
+ return this.joinAdditionalChannel(channel);
5570
5697
  }
5571
5698
  onChanged(callback) {
5572
5699
  return this.changed(callback);
@@ -5577,22 +5704,25 @@
5577
5704
  const channelNames = this.getAllChannelNames();
5578
5705
  runDecoderWithIOError(channelNameDecoder(channelNames), config.channel);
5579
5706
  }
5580
- const forAnotherClient = config.windowId && config.windowId !== this.interop.instance.instance;
5581
- if (config.windowId && forAnotherClient) {
5582
- const leaveData = { windowId: config.windowId, channelName: config.channel };
5583
- await this.bridge.send("channels", operations$5.leaveChannel, leaveData, undefined, { includeOperationCheck: true });
5707
+ const leaveData = { channelName: config.channel, windowId: config.windowId ?? this.myWindowId };
5708
+ await this.bridge.send("channels", operations$5.leaveChannel, leaveData, undefined, { includeOperationCheck: true });
5709
+ }
5710
+ async handleAppManagerInitialChannelId(channel) {
5711
+ if (this.storage.mode === "inMemory") {
5712
+ return;
5713
+ }
5714
+ if (this.storage.getSessionStorageData()) {
5584
5715
  return;
5585
5716
  }
5586
- const channelNamesToLeave = config.channel ? [config.channel] : this.currentChannels;
5587
- channelNamesToLeave.forEach((name) => this.unsubscribe(name));
5588
- this.currentChannels = this.currentChannels.filter((channelName) => !channelNamesToLeave.includes(channelName));
5589
- this.sessionController.setWindowData({ currentNames: this.currentChannels }, "channels");
5717
+ return this.handleJoinChannel({ channel, windowId: this.myWindowId });
5718
+ }
5719
+ async handleLeaveChannel({ channelName }) {
5720
+ const channelNamesToLeave = channelName ? [channelName] : this.storage.channels;
5721
+ channelNamesToLeave.forEach((name) => this.storage.invokeUnsubscribes(name));
5722
+ this.storage.channels = this.storage.channels.filter((channelName) => !channelNamesToLeave.includes(channelName));
5590
5723
  this.executeChangedEvents();
5591
5724
  await this.notifyChannelsChanged();
5592
5725
  }
5593
- handleLeaveChannel(data) {
5594
- return this.leave({ channel: data.channelName });
5595
- }
5596
5726
  toApi() {
5597
5727
  const api = {
5598
5728
  mode: this._mode,
@@ -5635,47 +5765,36 @@
5635
5765
  return channelNames;
5636
5766
  }
5637
5767
  async joinAdditionalChannel(name) {
5638
- if (this.currentChannels.includes(name)) {
5768
+ if (this.storage.channels.includes(name)) {
5639
5769
  return;
5640
5770
  }
5641
- this.currentChannels = [...this.currentChannels, name];
5771
+ this.storage.channels = [...this.storage.channels, name];
5642
5772
  const contextName = this.createContextName(name);
5643
5773
  const unsub = await this.contexts.subscribe(contextName, (context, delta, _, __, extraData) => {
5644
5774
  this.registry.execute(SUBS_KEY, context.data, context, delta, extraData?.updaterId);
5645
5775
  });
5646
- this.unsubscribeDict[name] = unsub;
5776
+ this.storage.addUnsubscribe(name, unsub);
5647
5777
  this.executeChangedEvents(name);
5648
- this.sessionController.setWindowData({ currentNames: this.currentChannels }, "channels");
5649
5778
  await this.notifyChannelsChanged();
5650
5779
  }
5651
5780
  async switchToChannel(name) {
5652
- const currentChannel = this.currentChannels[0];
5781
+ const currentChannel = this.storage.channels[0];
5653
5782
  if (name === currentChannel) {
5654
5783
  return;
5655
5784
  }
5656
- this.unsubscribe(currentChannel);
5657
- this.currentChannels = [name];
5785
+ this.storage.invokeUnsubscribes(currentChannel);
5786
+ this.storage.channels = [name];
5658
5787
  const contextName = this.createContextName(name);
5659
5788
  const unsub = await this.contexts.subscribe(contextName, (context, delta, _, __, extraData) => {
5660
5789
  this.registry.execute(SUBS_KEY, context.data, context, delta, extraData?.updaterId);
5661
5790
  });
5662
- this.unsubscribeDict[name] = unsub;
5791
+ this.storage.addUnsubscribe(name, unsub);
5663
5792
  this.executeChangedEvents(name);
5664
- this.sessionController.setWindowData({ currentNames: this.currentChannels }, "channels");
5665
5793
  await this.notifyChannelsChanged();
5666
5794
  }
5667
- unsubscribe(channelName) {
5668
- if (channelName) {
5669
- this.unsubscribeDict[channelName]?.();
5670
- delete this.unsubscribeDict[channelName];
5671
- return;
5672
- }
5673
- Object.values(this.unsubscribeDict).forEach((unsub) => unsub());
5674
- this.unsubscribeDict = {};
5675
- }
5676
5795
  executeChangedEvents(name) {
5677
5796
  this.registry.execute(CHANGED_KEY, name);
5678
- this.registry.execute(CHANNELS_CHANGED, this.currentChannels);
5797
+ this.registry.execute(CHANNELS_CHANGED, this.storage.channels);
5679
5798
  }
5680
5799
  async notifyChannelsChanged() {
5681
5800
  const windowId = this.windowsController.my().id;
@@ -5683,7 +5802,7 @@
5683
5802
  return;
5684
5803
  }
5685
5804
  try {
5686
- await this.bridge.send("channels", operations$5.notifyChannelsChanged, { channelNames: this.currentChannels, windowId }, undefined, { includeOperationCheck: true });
5805
+ await this.bridge.send("channels", operations$5.notifyChannelsChanged, { channelNames: this.storage.channels, windowId }, undefined, { includeOperationCheck: true });
5687
5806
  }
5688
5807
  catch (error) {
5689
5808
  this.logger.warn(`Failed to notify channel changed: ${extractErrorMsg(error)}`);
@@ -5766,10 +5885,10 @@
5766
5885
  const channelNames = this.getAllChannelNames();
5767
5886
  runDecoderWithIOError(channelNameDecoder(channelNames), options);
5768
5887
  }
5769
- if (!options && this.currentChannels.length > 1) {
5888
+ if (!options && this.storage.channels.length > 1) {
5770
5889
  return this.publishOnMultipleChannels(data);
5771
5890
  }
5772
- const channelName = typeof options === "string" ? options : this.currentChannels[0];
5891
+ const channelName = typeof options === "string" ? options : this.storage.channels[0];
5773
5892
  if (!channelName) {
5774
5893
  return ioError.raiseError("Cannot publish to channel, because not joined to a channel!");
5775
5894
  }
@@ -5800,13 +5919,13 @@
5800
5919
  return channelContext;
5801
5920
  }
5802
5921
  async getMyChannels() {
5803
- return Promise.all(this.currentChannels.map((channelName) => {
5922
+ return Promise.all(this.storage.channels.map((channelName) => {
5804
5923
  const contextName = this.createContextName(channelName);
5805
5924
  return this.contexts.get(contextName);
5806
5925
  }));
5807
5926
  }
5808
5927
  myChannels() {
5809
- return this.currentChannels;
5928
+ return this.storage.channels;
5810
5929
  }
5811
5930
  getContextForFdc3Type(channelContext, searchedType) {
5812
5931
  const encodedType = `fdc3_${searchedType.split(".").join("&")}`;
@@ -5840,7 +5959,7 @@
5840
5959
  return context;
5841
5960
  }
5842
5961
  current() {
5843
- return this.currentChannels[0];
5962
+ return this.storage.channels[0];
5844
5963
  }
5845
5964
  changed(callback) {
5846
5965
  if (typeof callback !== "function") {
@@ -5884,13 +6003,13 @@
5884
6003
  .catch(err => this.logger.trace(err));
5885
6004
  };
5886
6005
  async getMy(options) {
5887
- if (!this.currentChannels.length) {
6006
+ if (!this.storage.channels.length) {
5888
6007
  return;
5889
6008
  }
5890
6009
  if (options) {
5891
6010
  runDecoderWithIOError(fdc3OptionsDecoder, options);
5892
6011
  }
5893
- return this.get(this.currentChannels[this.currentChannels.length - 1], options);
6012
+ return this.get(this.storage.channels[this.storage.channels.length - 1], options);
5894
6013
  }
5895
6014
  async getWindowsOnChannel(channel) {
5896
6015
  const channelNames = this.getAllChannelNames();
@@ -5924,43 +6043,63 @@
5924
6043
  runDecoderWithIOError(channelRestrictionsDecoder, config);
5925
6044
  const channelNames = this.getAllChannelNames();
5926
6045
  runDecoderWithIOError(channelNameDecoder(channelNames), config.name);
5927
- const forAnotherClient = config.windowId && config.windowId !== this.interop.instance.instance;
5928
- if (forAnotherClient) {
5929
- return this.bridge.send("channels", operations$5.restrict, { config }, undefined, { includeOperationCheck: true });
5930
- }
5931
- const sessionStorageData = this.sessionController.getWindowData();
5932
- const restrictions = sessionStorageData?.restrictions ? { ...sessionStorageData.restrictions, [config.name]: config } : { [config.name]: config };
6046
+ const configData = {
6047
+ config: {
6048
+ ...config,
6049
+ windowId: config.windowId ?? this.myWindowId
6050
+ }
6051
+ };
6052
+ await this.bridge.send("channels", operations$5.restrict, configData, undefined, { includeOperationCheck: true });
6053
+ }
6054
+ async handleRestrict({ config }) {
5933
6055
  const currentChannel = await this.getMy();
5934
- const prevReadAllowed = this.checkPreviousReadAllowed(currentChannel?.name);
5935
- this.sessionController.setWindowData(restrictions, "restrictions");
5936
- if (!currentChannel || prevReadAllowed || !config.read || currentChannel.name !== config.name) {
6056
+ if (!currentChannel) {
6057
+ return this.updateRestriction(config);
6058
+ }
6059
+ const prevReadAllowed = this.isAllowedByRestrictions(currentChannel.name, "read");
6060
+ this.updateRestriction(config);
6061
+ const isForCurrentChannel = config.name === currentChannel.name;
6062
+ if (!isForCurrentChannel || prevReadAllowed || !config.read) {
5937
6063
  return;
5938
6064
  }
5939
6065
  this.replaySubscribeCallback(config.name);
5940
6066
  }
6067
+ updateRestriction(config) {
6068
+ const exists = this.storage.restrictions.some((r) => r.name === config.name);
6069
+ this.storage.restrictions = exists
6070
+ ? this.storage.restrictions.map((restriction) => restriction.name === config.name ? config : restriction)
6071
+ : this.storage.restrictions.concat(config);
6072
+ }
6073
+ updateAllRestrictions(config) {
6074
+ const allChannelNames = this.getAllChannelNames();
6075
+ this.storage.restrictions = allChannelNames.map((name) => ({ name, ...config }));
6076
+ }
5941
6077
  async getRestrictions(windowId) {
5942
6078
  runDecoderWithIOError(optionalNonEmptyStringDecoder, windowId);
5943
6079
  const forAnotherClient = windowId && windowId !== this.interop.instance.instance;
5944
6080
  if (windowId && forAnotherClient) {
5945
6081
  return this.bridge.send("channels", operations$5.getRestrictions, { windowId }, undefined, { includeOperationCheck: true });
5946
6082
  }
5947
- return this.getMyRestrictions();
6083
+ return { channels: this.storage.restrictions };
5948
6084
  }
5949
6085
  async restrictAll(restrictions) {
5950
6086
  runDecoderWithIOError(restrictionsConfigDecoder, restrictions);
5951
- const allChannelNames = this.getAllChannelNames();
5952
- const forAnotherClient = restrictions.windowId && restrictions.windowId !== this.interop.instance.instance;
5953
- if (forAnotherClient) {
5954
- return this.bridge.send("channels", operations$5.restrictAll, { restrictions }, undefined, { includeOperationCheck: true });
5955
- }
5956
- const allRestrictions = {};
5957
- allChannelNames.forEach((name) => {
5958
- allRestrictions[name] = { ...restrictions, name };
5959
- });
6087
+ const configData = {
6088
+ restrictions: {
6089
+ ...restrictions,
6090
+ windowId: restrictions.windowId ?? this.myWindowId
6091
+ }
6092
+ };
6093
+ return this.bridge.send("channels", operations$5.restrictAll, configData, undefined, { includeOperationCheck: true });
6094
+ }
6095
+ async handleRestrictAll({ restrictions }) {
5960
6096
  const currentChannel = await this.getMy();
5961
- const prevReadAllowed = this.checkPreviousReadAllowed(currentChannel?.name);
5962
- this.sessionController.setWindowData(allRestrictions, "restrictions");
5963
- if (!currentChannel || prevReadAllowed || !restrictions.read) {
6097
+ if (!currentChannel) {
6098
+ return this.updateAllRestrictions(restrictions);
6099
+ }
6100
+ const prevReadAllowed = this.isAllowedByRestrictions(currentChannel.name, "read");
6101
+ this.updateAllRestrictions(restrictions);
6102
+ if (prevReadAllowed || !restrictions.read) {
5964
6103
  return;
5965
6104
  }
5966
6105
  this.replaySubscribeCallback(currentChannel.name);
@@ -5976,7 +6115,7 @@
5976
6115
  await this.handleSetPaths("setPaths", dataPaths, name);
5977
6116
  }
5978
6117
  async handleSetPaths(operation, paths, name) {
5979
- const channelNamesToUpdate = name ? [name] : this.currentChannels;
6118
+ const channelNamesToUpdate = name ? [name] : this.storage.channels;
5980
6119
  if (!channelNamesToUpdate.length) {
5981
6120
  return ioError.raiseError(`Cannot complete ${operation} operation, because channel is not specified. Either join one or pass a channel name as second argument!`);
5982
6121
  }
@@ -6010,18 +6149,9 @@
6010
6149
  }, { allowed: [], forbidden: [] });
6011
6150
  }
6012
6151
  isAllowedByRestrictions(channelName, action) {
6013
- const { channels } = this.getMyRestrictions();
6014
- if (!channels?.length) {
6015
- return true;
6016
- }
6017
- const restriction = channels.find((restriction) => restriction.name === channelName);
6152
+ const restriction = this.storage.restrictions.find((restriction) => restriction.name === channelName);
6018
6153
  return restriction ? restriction[action] : true;
6019
6154
  }
6020
- getMyRestrictions() {
6021
- const sessionStorageData = this.sessionController.getWindowData();
6022
- const restrictions = Object.values(sessionStorageData?.restrictions || {});
6023
- return { channels: restrictions };
6024
- }
6025
6155
  replaySubscribeCallback(channelName) {
6026
6156
  const contextName = this.createContextName(channelName);
6027
6157
  this.contexts.subscribe(contextName, (context, delta, _, __, extraData) => {
@@ -6032,26 +6162,16 @@
6032
6162
  }
6033
6163
  }).catch(err => this.logger.error(err));
6034
6164
  }
6035
- checkPreviousReadAllowed(channelName) {
6036
- if (!channelName) {
6037
- return true;
6038
- }
6039
- const prevRestrictions = this.sessionController.getWindowData().restrictions;
6040
- if (!prevRestrictions?.[channelName]) {
6041
- return true;
6042
- }
6043
- return prevRestrictions[channelName].read;
6044
- }
6045
6165
  async publishWithOptions(data, options) {
6046
6166
  if (options.name) {
6047
6167
  const channelNames = this.getAllChannelNames();
6048
6168
  runDecoderWithIOError(channelNameDecoder(channelNames), options.name);
6049
6169
  }
6050
- const publishOnMultipleChannels = options.name ? false : this.currentChannels.length > 1;
6170
+ const publishOnMultipleChannels = options.name ? false : this.storage.channels.length > 1;
6051
6171
  if (publishOnMultipleChannels) {
6052
6172
  return this.publishOnMultipleChannels(data, options.fdc3);
6053
6173
  }
6054
- const channelName = options.name || this.currentChannels[0];
6174
+ const channelName = options.name || this.storage.channels[0];
6055
6175
  if (!channelName) {
6056
6176
  return ioError.raiseError("Cannot publish to channel, because not joined to a channel!");
6057
6177
  }
@@ -6065,9 +6185,9 @@
6065
6185
  return this.publishFdc3Data(channelName, data);
6066
6186
  }
6067
6187
  async publishOnMultipleChannels(data, isFdc3) {
6068
- const { allowed, forbidden } = this.groupChannelsByPermission("write", this.currentChannels);
6069
- if (this.currentChannels.length === forbidden.length) {
6070
- return ioError.raiseError(`Cannot complete 'publish' operation due to write restrictions to all joined channels: ${this.currentChannels.join(", ")}`);
6188
+ const { allowed, forbidden } = this.groupChannelsByPermission("write", this.storage.channels);
6189
+ if (this.storage.channels.length === forbidden.length) {
6190
+ return ioError.raiseError(`Cannot complete 'publish' operation due to write restrictions to all joined channels: ${this.storage.channels.join(", ")}`);
6071
6191
  }
6072
6192
  if (forbidden.length) {
6073
6193
  this.logger.warn(`Data on channel${forbidden.length > 1 ? "s" : ""}: ${forbidden.join(", ")} won't be published due to write restrictions`);
@@ -6143,10 +6263,8 @@
6143
6263
  if (!myAppDetails?.channelSelector?.enabled) {
6144
6264
  return;
6145
6265
  }
6146
- const { channels: channelsStorageData } = this.sessionController.getWindowData();
6147
6266
  const windowId = myInstance.id;
6148
- const channelsNames = channelsStorageData?.currentNames || [];
6149
- const requestChannelSelectorConfig = { windowId, channelsNames };
6267
+ const requestChannelSelectorConfig = { windowId, channelsNames: this.storage.channels };
6150
6268
  await this.bridge.send("channels", operations$5.requestChannelSelector, requestChannelSelectorConfig, undefined, { includeOperationCheck: true });
6151
6269
  }
6152
6270
  async getPlatformChannelsMode() {
@@ -6165,6 +6283,46 @@
6165
6283
  }
6166
6284
  return this.registry.add(CHANNELS_CHANGED, callback);
6167
6285
  }
6286
+ async initialize() {
6287
+ const isAppHelloSupported = await this.checkIfAppHelloSupported();
6288
+ if (!isAppHelloSupported) {
6289
+ return this.handleAppHelloFailure("Platform does not support 'appHello' operation and channel state persistence by windowId. Setting 'sessionStorage' mode for tracking channels and restrictions");
6290
+ }
6291
+ const { success, error } = await this.sendAppHello();
6292
+ if (error) {
6293
+ return this.handleAppHelloFailure(error);
6294
+ }
6295
+ this.logger.trace(`Received 'appHelloSuccess' message. Setting initial channels state to: ${JSON.stringify(success)}`);
6296
+ const { mode, channels, restrictions } = success;
6297
+ this.storage.mode = "inMemory";
6298
+ this._mode = mode;
6299
+ this.storage.channels = channels;
6300
+ this.storage.restrictions = restrictions;
6301
+ }
6302
+ async handleAppHelloFailure(errorMsg) {
6303
+ this.logger.trace(errorMsg);
6304
+ this.storage.mode = "sessionStorage";
6305
+ this._mode = await this.getPlatformChannelsMode();
6306
+ }
6307
+ async sendAppHello() {
6308
+ try {
6309
+ const result = await this.bridge.send("channels", operations$5.appHello, { windowId: this.myWindowId }, undefined, { includeOperationCheck: true });
6310
+ return { success: result, error: undefined };
6311
+ }
6312
+ catch (error) {
6313
+ return { error: `Failed to get initial state from platform. Error: ${extractErrorMsg(error)}`, success: undefined };
6314
+ }
6315
+ }
6316
+ async checkIfAppHelloSupported() {
6317
+ try {
6318
+ const { isSupported } = await this.bridge.send("channels", operations$5.operationCheck, { operation: operations$5.appHello.name }, undefined, { includeOperationCheck: true });
6319
+ return isSupported;
6320
+ }
6321
+ catch (error) {
6322
+ this.logger.trace(`Platform does not support 'appHello' operation and channel state persistence by windowId. Error: ${extractErrorMsg(error)}`);
6323
+ return false;
6324
+ }
6325
+ }
6168
6326
  }
6169
6327
 
6170
6328
  const operations$4 = {
@@ -6772,31 +6930,84 @@
6772
6930
  }
6773
6931
  }
6774
6932
 
6775
- class SessionStorageController {
6933
+ class ChannelsStorage {
6776
6934
  sessionStorage = window.sessionStorage;
6777
- windowId;
6778
- get allNamespaces() {
6779
- return [{ namespace: this.windowNamespace, defaultValue: {} }];
6935
+ _mode = DEFAULT_STORAGE_MODE;
6936
+ inMemoryChannels = [];
6937
+ inMemoryRestrictions = [];
6938
+ _unsubscribeDict = {};
6939
+ clear() {
6940
+ this._mode = DEFAULT_STORAGE_MODE;
6941
+ this.inMemoryChannels = [];
6942
+ this.inMemoryRestrictions = [];
6943
+ this._unsubscribeDict = {};
6944
+ this.sessionStorage.setItem(STORAGE_NAMESPACE, JSON.stringify([]));
6780
6945
  }
6781
- configure(config) {
6782
- this.windowId = config.windowId;
6783
- this.allNamespaces.forEach(({ namespace, defaultValue }) => {
6784
- const data = this.sessionStorage.getItem(namespace);
6785
- if (!data) {
6786
- this.sessionStorage.setItem(namespace, JSON.stringify(defaultValue));
6787
- }
6788
- });
6946
+ get mode() {
6947
+ return this._mode;
6789
6948
  }
6790
- get windowNamespace() {
6791
- return `io_connect_window_${this.windowId}`;
6949
+ set mode(mode) {
6950
+ this._mode = mode;
6792
6951
  }
6793
- getWindowData() {
6794
- return JSON.parse(this.sessionStorage.getItem(this.windowNamespace));
6952
+ get channels() {
6953
+ if (this.mode === "inMemory") {
6954
+ return this.inMemoryChannels.slice();
6955
+ }
6956
+ return this.getSessionStorageData()?.channels ?? [];
6795
6957
  }
6796
- setWindowData(data, key) {
6797
- const allData = this.getWindowData();
6798
- allData[key] = data;
6799
- this.sessionStorage.setItem(this.windowNamespace, JSON.stringify(allData));
6958
+ set channels(channels) {
6959
+ if (this.mode === "inMemory") {
6960
+ this.inMemoryChannels = channels;
6961
+ }
6962
+ this.setSessionStorageChannels(channels);
6963
+ }
6964
+ get restrictions() {
6965
+ if (this.mode === "inMemory") {
6966
+ return this.inMemoryRestrictions.slice();
6967
+ }
6968
+ return this.getSessionStorageData()?.restrictions ?? [];
6969
+ }
6970
+ set restrictions(restrictions) {
6971
+ if (this.mode === "inMemory") {
6972
+ this.inMemoryRestrictions = restrictions;
6973
+ }
6974
+ this.setSessionStorageRestrictions(restrictions);
6975
+ }
6976
+ getSessionStorageData() {
6977
+ return JSON.parse(this.sessionStorage.getItem(STORAGE_NAMESPACE) || "null");
6978
+ }
6979
+ addUnsubscribe(channel, unsubscribe) {
6980
+ this._unsubscribeDict[channel] = unsubscribe;
6981
+ }
6982
+ invokeUnsubscribes(channel) {
6983
+ if (channel) {
6984
+ this._unsubscribeDict[channel]?.();
6985
+ delete this._unsubscribeDict[channel];
6986
+ return;
6987
+ }
6988
+ Object.values(this._unsubscribeDict).forEach((unsub) => unsub());
6989
+ this._unsubscribeDict = {};
6990
+ }
6991
+ setSessionStorageChannels(channels) {
6992
+ const data = this.getSessionStorageData();
6993
+ if (data?.channels) {
6994
+ data.channels = channels;
6995
+ return this.setSessionStorageData(data);
6996
+ }
6997
+ const newData = { channels, restrictions: data?.restrictions ?? [] };
6998
+ return this.setSessionStorageData(newData);
6999
+ }
7000
+ setSessionStorageRestrictions(restrictions) {
7001
+ const data = this.getSessionStorageData();
7002
+ if (data?.restrictions) {
7003
+ data.restrictions = restrictions;
7004
+ return this.setSessionStorageData(data);
7005
+ }
7006
+ const newData = { channels: data?.channels ?? [], restrictions };
7007
+ return this.setSessionStorageData(newData);
7008
+ }
7009
+ setSessionStorageData(data) {
7010
+ this.sessionStorage.setItem(STORAGE_NAMESPACE, JSON.stringify(data));
6800
7011
  }
6801
7012
  }
6802
7013
 
@@ -6931,7 +7142,7 @@
6931
7142
  return ioError.raiseError("Cannot subscribe to prefs, because the provided callback is not a function!");
6932
7143
  }
6933
7144
  if (!this.signaledSubscription) {
6934
- this.bridge.send("prefs", operations$1.registerSubscriber, { interopId: this.interopId }, undefined, { includeOperationCheck: true })
7145
+ this.bridge.send("prefs", operations$1.registerSubscriber, { interopId: this.interopId, appName: verifiedApp }, undefined, { includeOperationCheck: true })
6935
7146
  .catch((error) => {
6936
7147
  this.logger.warn("Failed to register subscriber for prefs");
6937
7148
  this.logger.error(error);
@@ -7382,7 +7593,7 @@
7382
7593
  _bridgeInstance;
7383
7594
  _eventsDispatcher;
7384
7595
  _preferredConnectionController;
7385
- _sessionController;
7596
+ _channelsStorage;
7386
7597
  _prefsControllerInstance;
7387
7598
  _uiController;
7388
7599
  controllers = {
@@ -7488,11 +7699,11 @@
7488
7699
  }
7489
7700
  return this._preferredConnectionController;
7490
7701
  }
7491
- get sessionController() {
7492
- if (!this._sessionController) {
7493
- this._sessionController = new SessionStorageController();
7702
+ get channelsStorage() {
7703
+ if (!this._channelsStorage) {
7704
+ this._channelsStorage = new ChannelsStorage();
7494
7705
  }
7495
- return this._sessionController;
7706
+ return this._channelsStorage;
7496
7707
  }
7497
7708
  get config() {
7498
7709
  return this._webConfig;
@@ -7506,8 +7717,8 @@
7506
7717
  defineConfig(config) {
7507
7718
  this._webConfig = config;
7508
7719
  }
7509
- async buildWebWindow(id, name) {
7510
- const model = new WebWindowModel(id, name, this.bridge);
7720
+ async buildWebWindow(id, name, logger) {
7721
+ const model = new WebWindowModel(id, name, this.bridge, logger);
7511
7722
  const api = await model.toApi();
7512
7723
  return { id, model, api };
7513
7724
  }
@@ -7525,7 +7736,7 @@
7525
7736
  }
7526
7737
  }
7527
7738
 
7528
- var version$1 = "4.0.2";
7739
+ var version$1 = "4.1.0-beta.0";
7529
7740
 
7530
7741
  const setupGlobalSystem = (io, bridge) => {
7531
7742
  return {
@@ -7561,7 +7772,6 @@
7561
7772
  const glue = await PromiseWrap(() => coreFactoryFunction(config, { version: version$1 }), 30000, "Glue Web initialization timed out, because core didn't resolve");
7562
7773
  const logger = glue.logger.subLogger("web.main.controller");
7563
7774
  ioc.defineGlue(glue);
7564
- ioc.sessionController.configure({ windowId: glue.interop.instance.instance });
7565
7775
  await ioc.preferredConnectionController.start(config);
7566
7776
  await ioc.bridge.start(ioc.controllers);
7567
7777
  ioc.defineConfig(config);
@@ -8945,6 +9155,7 @@
8945
9155
  logger;
8946
9156
  identity;
8947
9157
  isPreferredActivated;
9158
+ _connectionProtocolVersion;
8948
9159
  _communicationId;
8949
9160
  publicWindowId;
8950
9161
  selfAssignedWindowId;
@@ -9160,24 +9371,34 @@
9160
9371
  return;
9161
9372
  }
9162
9373
  window.addEventListener("beforeunload", () => {
9163
- if (this.extContentConnected) {
9374
+ if (this._connectionProtocolVersion) {
9164
9375
  return;
9165
9376
  }
9166
- const message = {
9167
- glue42core: {
9168
- type: this.messages.clientUnload.name,
9169
- data: {
9170
- clientId: this.myClientId,
9171
- ownWindowId: this.identity?.windowId
9172
- }
9173
- }
9174
- };
9175
- if (this.parent) {
9176
- this.parent.postMessage(message, this.defaultTargetString);
9377
+ this.signalClientDisappearing();
9378
+ });
9379
+ window.addEventListener("pagehide", () => {
9380
+ if (!this._connectionProtocolVersion) {
9381
+ return;
9177
9382
  }
9178
- this.port?.postMessage(message);
9383
+ this.signalClientDisappearing();
9179
9384
  });
9180
9385
  }
9386
+ signalClientDisappearing() {
9387
+ if (this.extContentConnected) {
9388
+ return;
9389
+ }
9390
+ const message = {
9391
+ glue42core: {
9392
+ type: this.messages.clientUnload.name,
9393
+ data: {
9394
+ clientId: this.myClientId,
9395
+ ownWindowId: this.identity?.windowId
9396
+ }
9397
+ }
9398
+ };
9399
+ this.parent?.postMessage(message, this.defaultTargetString);
9400
+ this.port?.postMessage(message);
9401
+ }
9181
9402
  handlePlatformReady(event) {
9182
9403
  this.logger.debug("the web platform gave the ready signal");
9183
9404
  this.parentReady = true;
@@ -9209,6 +9430,7 @@
9209
9430
  this.logger.error("cannot set up my connection, because I was not provided with a port");
9210
9431
  return;
9211
9432
  }
9433
+ this._connectionProtocolVersion = data.connectionProtocolVersion;
9212
9434
  this.publicWindowId = this.getMyWindowId();
9213
9435
  if (this.identity) {
9214
9436
  this.identity.windowId = this.publicWindowId;
@@ -9688,7 +9910,7 @@
9688
9910
  resolve(successMsg);
9689
9911
  },
9690
9912
  error: (errorMsg) => {
9691
- logger.warn(`Gateway error - ${JSON.stringify(errorMsg)}`);
9913
+ console.warn(`Gateway error - ${JSON.stringify(errorMsg)}`);
9692
9914
  delete requestsMap[requestId];
9693
9915
  errorMsg._tag = tag;
9694
9916
  reject(errorMsg);
@@ -10443,7 +10665,12 @@
10443
10665
  this.logFn.warn(toPrint);
10444
10666
  break;
10445
10667
  case "error":
10446
- this.logFn.error(toPrint, error);
10668
+ if (error) {
10669
+ this.logFn.error(toPrint, error);
10670
+ }
10671
+ else {
10672
+ this.logFn.error(toPrint);
10673
+ }
10447
10674
  break;
10448
10675
  }
10449
10676
  }
@@ -10487,7 +10714,7 @@
10487
10714
  }
10488
10715
  };
10489
10716
 
10490
- var version = "6.6.0";
10717
+ var version = "6.7.0-beta.0";
10491
10718
 
10492
10719
  function prepareConfig (configuration, ext, glue42gd) {
10493
10720
  let nodeStartingContext;
@@ -10629,9 +10856,10 @@
10629
10856
  gatewayToken: nodeStartingContext.gwToken
10630
10857
  };
10631
10858
  }
10632
- if (configuration.gateway?.webPlatform || configuration.gateway?.inproc || configuration.gateway?.sharedWorker) {
10859
+ if (configuration.gateway?.webPlatform) {
10633
10860
  return {
10634
- username: "glue42", password: "glue42"
10861
+ username: "glue42",
10862
+ password: ""
10635
10863
  };
10636
10864
  }
10637
10865
  }
@@ -12575,15 +12803,20 @@
12575
12803
  }
12576
12804
  function setValueToPath(obj, value, path) {
12577
12805
  const pathArr = path.split(".");
12806
+ const forbiddenKeys = ["__proto__", "constructor", "prototype"];
12578
12807
  let i;
12579
12808
  for (i = 0; i < pathArr.length - 1; i++) {
12580
- if (!obj[pathArr[i]]) {
12581
- obj[pathArr[i]] = {};
12809
+ const key = pathArr[i];
12810
+ if (forbiddenKeys.includes(key)) {
12811
+ throw new Error(`The provided path ${path} is invalid. It cannot contain segment/key that is equal to one of the following values: ${forbiddenKeys}.`);
12582
12812
  }
12583
- if (typeof obj[pathArr[i]] !== "object") {
12584
- obj[pathArr[i]] = {};
12813
+ if (!obj[key]) {
12814
+ obj[key] = {};
12585
12815
  }
12586
- obj = obj[pathArr[i]];
12816
+ if (typeof obj[key] !== "object") {
12817
+ obj[key] = {};
12818
+ }
12819
+ obj = obj[key];
12587
12820
  }
12588
12821
  obj[pathArr[i]] = value;
12589
12822
  }