@interopio/fdc3 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,4 +1,6 @@
1
- 2.0.0
1
+ 2.0.2
2
+ fix: context listener's handler is invoked when subscription is made via User Channel interface and the app hasn't joined a channel
3
+ 2.0.1
2
4
  feat: Introduce the new IO Connect FDC3 API
3
5
  3.2.3
4
6
  fix: Fdc3 channels selector fix
package/dist/fdc3.es.js CHANGED
@@ -1982,7 +1982,7 @@ class IntentsController {
1982
1982
  }
1983
1983
  }
1984
1984
 
1985
- var version = "2.0.1";
1985
+ var version = "2.0.2";
1986
1986
 
1987
1987
  class ApplicationsController {
1988
1988
  constructor(glueController) {
@@ -2192,13 +2192,12 @@ class ApplicationsController {
2192
2192
  }
2193
2193
 
2194
2194
  class ChannelsController {
2195
- constructor(glueController, channelsStateStore, channelsParser, channelsFactory, channelsCallbackRegistry, channelsPendingListenersStore) {
2195
+ constructor(glueController, channelsStateStore, channelsParser, channelsFactory, channelsCallbackRegistry) {
2196
2196
  this.glueController = glueController;
2197
2197
  this.channelsStateStore = channelsStateStore;
2198
2198
  this.channelsParser = channelsParser;
2199
2199
  this.channelsFactory = channelsFactory;
2200
2200
  this.channelsCallbackRegistry = channelsCallbackRegistry;
2201
- this.channelsPendingListenersStore = channelsPendingListenersStore;
2202
2201
  this.invokeContextHandlerWithStartupContext = true;
2203
2202
  this.initDonePromise = this.initialize();
2204
2203
  this.initDonePromise.catch(() => { });
@@ -2219,7 +2218,7 @@ class ChannelsController {
2219
2218
  this.handleWindowContextOnOpening(commandId, handler, contextType).catch((err) => this.logger.warn(`[${commandId}] - ${err}`));
2220
2219
  }
2221
2220
  const channelIdToSubscribeTo = channelId || ((_a = this.channelsStateStore.currentChannel) === null || _a === void 0 ? void 0 : _a.id);
2222
- return this.addContextListenerByChannelId(commandId, handler, channelIdToSubscribeTo, contextType);
2221
+ return this.addContextListenerByChannelId({ commandId, handler, invokedOnChannelModel: !!channelId, channelId: channelIdToSubscribeTo, contextType });
2223
2222
  });
2224
2223
  }
2225
2224
  broadcast(commandId, context, channelId) {
@@ -2292,7 +2291,6 @@ class ChannelsController {
2292
2291
  yield this.glueController.leaveChannel();
2293
2292
  this.channelsStateStore.currentChannel = null;
2294
2293
  this.logger.info(`[${commandId}] - current channel is left. unsubscribing from all listeners`);
2295
- this.channelsPendingListenersStore.unsubscribePendingListeners();
2296
2294
  });
2297
2295
  }
2298
2296
  getContextForChannel({ commandId, channelId, contextType }) {
@@ -2407,13 +2405,10 @@ class ChannelsController {
2407
2405
  handleOnChannelChanged(channelId) {
2408
2406
  return __awaiter(this, void 0, void 0, function* () {
2409
2407
  if (!channelId) {
2410
- this.channelsPendingListenersStore.unsubscribePendingListeners();
2411
2408
  return;
2412
2409
  }
2413
2410
  const isFdc3ChannelName = fdc3ChannelNames.includes(channelId);
2414
2411
  const userChannelId = isFdc3ChannelName ? channelId : this.channelsStateStore.getFdc3ChannelIdByGlueChannelName(channelId);
2415
- const commandId = nanoid();
2416
- yield this.channelsPendingListenersStore.subscribePendingListeners(commandId, this.addContextListener.bind(this), userChannelId);
2417
2412
  this.channelsStateStore.currentChannel = this.channelsStateStore.userChannels[userChannelId];
2418
2413
  });
2419
2414
  }
@@ -2508,23 +2503,17 @@ class ChannelsController {
2508
2503
  return this.glueController.channelsUpdate(glueChannelName, context);
2509
2504
  });
2510
2505
  }
2511
- addContextListenerByChannelId(commandId, handler, channelId, contextType) {
2506
+ addContextListenerByChannelId({ commandId, channelId, handler, contextType, invokedOnChannelModel }) {
2512
2507
  return __awaiter(this, void 0, void 0, function* () {
2513
2508
  const subHandler = parseContextHandler(handler, contextType);
2514
2509
  if (!channelId) {
2515
- this.logger.info(`[${commandId}] - no channel to subscribe for. Creating a pending listener`);
2516
- return this.channelsPendingListenersStore.createPendingListener(subHandler, contextType);
2510
+ this.logger.info(`[${commandId}] - Creating a channel subscription using glue.channels.subscribe`);
2511
+ const unsubscribe = this.glueController.channelsSubscribe(subHandler);
2512
+ return { unsubscribe };
2517
2513
  }
2518
2514
  const channelType = this.getChannelTypeById(channelId);
2519
2515
  if (channelType === ChannelTypes.User) {
2520
- this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
2521
- const unsubscribe = this.glueController.channelsSubscribe(subHandler);
2522
- return {
2523
- unsubscribe: () => {
2524
- this.logger.info(`[${commandId}] - invoking unsubscribe for fdc3 user channel with id ${channelId}`);
2525
- unsubscribe();
2526
- }
2527
- };
2516
+ return this.addContextListenerOnUserChannel({ commandId, channelId, handler: subHandler, contextType, invokedOnChannelModel });
2528
2517
  }
2529
2518
  if (channelType === ChannelTypes.App) {
2530
2519
  this.logger.info(`[${commandId}] - subscribing for fdc3 app channel with id ${channelId} (underlying glue context with same name)`);
@@ -2554,6 +2543,26 @@ class ChannelsController {
2554
2543
  throw { message: ChannelError.AccessDenied, reason: "Cannot add a context listener on an invalid channel" };
2555
2544
  });
2556
2545
  }
2546
+ addContextListenerOnUserChannel({ commandId, channelId, handler, invokedOnChannelModel }) {
2547
+ return __awaiter(this, void 0, void 0, function* () {
2548
+ let unsubscribe;
2549
+ if (invokedOnChannelModel) {
2550
+ const contextToSubscribeTo = this.channelsParser.mapChannelNameToContextName(this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId));
2551
+ this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
2552
+ unsubscribe = yield this.glueController.contextsSubscribe(contextToSubscribeTo, handler);
2553
+ }
2554
+ else {
2555
+ this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
2556
+ unsubscribe = this.glueController.channelsSubscribe(handler);
2557
+ }
2558
+ return {
2559
+ unsubscribe: () => {
2560
+ this.logger.info(`[${commandId}] - invoking unsubscribe for fdc3 user channel with id ${channelId}`);
2561
+ unsubscribe();
2562
+ }
2563
+ };
2564
+ });
2565
+ }
2557
2566
  getChannelTypeById(channelId) {
2558
2567
  const isUser = this.isUserChannel(channelId);
2559
2568
  if (isUser) {
@@ -3001,48 +3010,6 @@ class GlueEventsController {
3001
3010
  }
3002
3011
  }
3003
3012
 
3004
- class ChannelsPendingListenersStore {
3005
- constructor() {
3006
- this.pendingListeners = [];
3007
- }
3008
- createPendingListener(handler, contextType) {
3009
- const id = nanoid();
3010
- const unsubscribe = () => this.filterPendingListenersById(id);
3011
- const listener = { unsubscribe };
3012
- const setActualUnsub = (actualUnsub) => {
3013
- listener.unsubscribe = actualUnsub;
3014
- };
3015
- this.pendingListeners.push({ id, handler, contextType, setActualUnsub, listener, unsubWithoutFilter: () => { } });
3016
- return listener;
3017
- }
3018
- subscribePendingListeners(commandId, addContextListenerFn, channelId) {
3019
- return __awaiter(this, void 0, void 0, function* () {
3020
- const listeners = yield Promise.all(this.pendingListeners.map(pendingListener => {
3021
- const { handler, contextType } = pendingListener;
3022
- return addContextListenerFn({ commandId, handler, contextType, channelId });
3023
- }));
3024
- Object.values(this.pendingListeners).forEach(({ id, setActualUnsub, unsubWithoutFilter }, index) => {
3025
- unsubWithoutFilter = listeners[index].unsubscribe;
3026
- const un = () => {
3027
- this.filterPendingListenersById(id);
3028
- unsubWithoutFilter();
3029
- };
3030
- setActualUnsub(un);
3031
- });
3032
- });
3033
- }
3034
- unsubscribePendingListeners() {
3035
- this.pendingListeners.forEach(({ id, setActualUnsub, unsubWithoutFilter }) => {
3036
- unsubWithoutFilter();
3037
- const newUnsub = () => this.filterPendingListenersById(id);
3038
- setActualUnsub(newUnsub);
3039
- });
3040
- }
3041
- filterPendingListenersById(id) {
3042
- this.pendingListeners = this.pendingListeners.filter((listener) => listener.id !== id);
3043
- }
3044
- }
3045
-
3046
3013
  class IoC {
3047
3014
  get ioc() {
3048
3015
  return this;
@@ -3112,7 +3079,7 @@ class IoC {
3112
3079
  }
3113
3080
  get channelsController() {
3114
3081
  if (!this._channelsController) {
3115
- this._channelsController = new ChannelsController(this.glueController, this.channelsStateStore, this.channelsParser, this.channelsFactory, this.channelsCallbackRegistry, this.channelsPendingListenersStore);
3082
+ this._channelsController = new ChannelsController(this.glueController, this.channelsStateStore, this.channelsParser, this.channelsFactory, this.channelsCallbackRegistry);
3116
3083
  }
3117
3084
  return this._channelsController;
3118
3085
  }
@@ -3122,12 +3089,6 @@ class IoC {
3122
3089
  }
3123
3090
  return this._channelsStateStore;
3124
3091
  }
3125
- get channelsPendingListenersStore() {
3126
- if (!this._channelsPendingListenersStore) {
3127
- this._channelsPendingListenersStore = new ChannelsPendingListenersStore();
3128
- }
3129
- return this._channelsPendingListenersStore;
3130
- }
3131
3092
  get channelsCallbackRegistry() {
3132
3093
  if (!this._channelsCallbackRegistry) {
3133
3094
  this._channelsCallbackRegistry = new ChannelsCallbackRegistry();
package/dist/fdc3.umd.js CHANGED
@@ -1988,7 +1988,7 @@
1988
1988
  }
1989
1989
  }
1990
1990
 
1991
- var version = "2.0.1";
1991
+ var version = "2.0.2";
1992
1992
 
1993
1993
  class ApplicationsController {
1994
1994
  constructor(glueController) {
@@ -2198,13 +2198,12 @@
2198
2198
  }
2199
2199
 
2200
2200
  class ChannelsController {
2201
- constructor(glueController, channelsStateStore, channelsParser, channelsFactory, channelsCallbackRegistry, channelsPendingListenersStore) {
2201
+ constructor(glueController, channelsStateStore, channelsParser, channelsFactory, channelsCallbackRegistry) {
2202
2202
  this.glueController = glueController;
2203
2203
  this.channelsStateStore = channelsStateStore;
2204
2204
  this.channelsParser = channelsParser;
2205
2205
  this.channelsFactory = channelsFactory;
2206
2206
  this.channelsCallbackRegistry = channelsCallbackRegistry;
2207
- this.channelsPendingListenersStore = channelsPendingListenersStore;
2208
2207
  this.invokeContextHandlerWithStartupContext = true;
2209
2208
  this.initDonePromise = this.initialize();
2210
2209
  this.initDonePromise.catch(() => { });
@@ -2225,7 +2224,7 @@
2225
2224
  this.handleWindowContextOnOpening(commandId, handler, contextType).catch((err) => this.logger.warn(`[${commandId}] - ${err}`));
2226
2225
  }
2227
2226
  const channelIdToSubscribeTo = channelId || ((_a = this.channelsStateStore.currentChannel) === null || _a === void 0 ? void 0 : _a.id);
2228
- return this.addContextListenerByChannelId(commandId, handler, channelIdToSubscribeTo, contextType);
2227
+ return this.addContextListenerByChannelId({ commandId, handler, invokedOnChannelModel: !!channelId, channelId: channelIdToSubscribeTo, contextType });
2229
2228
  });
2230
2229
  }
2231
2230
  broadcast(commandId, context, channelId) {
@@ -2298,7 +2297,6 @@
2298
2297
  yield this.glueController.leaveChannel();
2299
2298
  this.channelsStateStore.currentChannel = null;
2300
2299
  this.logger.info(`[${commandId}] - current channel is left. unsubscribing from all listeners`);
2301
- this.channelsPendingListenersStore.unsubscribePendingListeners();
2302
2300
  });
2303
2301
  }
2304
2302
  getContextForChannel({ commandId, channelId, contextType }) {
@@ -2413,13 +2411,10 @@
2413
2411
  handleOnChannelChanged(channelId) {
2414
2412
  return __awaiter(this, void 0, void 0, function* () {
2415
2413
  if (!channelId) {
2416
- this.channelsPendingListenersStore.unsubscribePendingListeners();
2417
2414
  return;
2418
2415
  }
2419
2416
  const isFdc3ChannelName = fdc3ChannelNames.includes(channelId);
2420
2417
  const userChannelId = isFdc3ChannelName ? channelId : this.channelsStateStore.getFdc3ChannelIdByGlueChannelName(channelId);
2421
- const commandId = nanoid();
2422
- yield this.channelsPendingListenersStore.subscribePendingListeners(commandId, this.addContextListener.bind(this), userChannelId);
2423
2418
  this.channelsStateStore.currentChannel = this.channelsStateStore.userChannels[userChannelId];
2424
2419
  });
2425
2420
  }
@@ -2514,23 +2509,17 @@
2514
2509
  return this.glueController.channelsUpdate(glueChannelName, context);
2515
2510
  });
2516
2511
  }
2517
- addContextListenerByChannelId(commandId, handler, channelId, contextType) {
2512
+ addContextListenerByChannelId({ commandId, channelId, handler, contextType, invokedOnChannelModel }) {
2518
2513
  return __awaiter(this, void 0, void 0, function* () {
2519
2514
  const subHandler = parseContextHandler(handler, contextType);
2520
2515
  if (!channelId) {
2521
- this.logger.info(`[${commandId}] - no channel to subscribe for. Creating a pending listener`);
2522
- return this.channelsPendingListenersStore.createPendingListener(subHandler, contextType);
2516
+ this.logger.info(`[${commandId}] - Creating a channel subscription using glue.channels.subscribe`);
2517
+ const unsubscribe = this.glueController.channelsSubscribe(subHandler);
2518
+ return { unsubscribe };
2523
2519
  }
2524
2520
  const channelType = this.getChannelTypeById(channelId);
2525
2521
  if (channelType === ChannelTypes.User) {
2526
- this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
2527
- const unsubscribe = this.glueController.channelsSubscribe(subHandler);
2528
- return {
2529
- unsubscribe: () => {
2530
- this.logger.info(`[${commandId}] - invoking unsubscribe for fdc3 user channel with id ${channelId}`);
2531
- unsubscribe();
2532
- }
2533
- };
2522
+ return this.addContextListenerOnUserChannel({ commandId, channelId, handler: subHandler, contextType, invokedOnChannelModel });
2534
2523
  }
2535
2524
  if (channelType === ChannelTypes.App) {
2536
2525
  this.logger.info(`[${commandId}] - subscribing for fdc3 app channel with id ${channelId} (underlying glue context with same name)`);
@@ -2560,6 +2549,26 @@
2560
2549
  throw { message: ChannelError.AccessDenied, reason: "Cannot add a context listener on an invalid channel" };
2561
2550
  });
2562
2551
  }
2552
+ addContextListenerOnUserChannel({ commandId, channelId, handler, invokedOnChannelModel }) {
2553
+ return __awaiter(this, void 0, void 0, function* () {
2554
+ let unsubscribe;
2555
+ if (invokedOnChannelModel) {
2556
+ const contextToSubscribeTo = this.channelsParser.mapChannelNameToContextName(this.channelsStateStore.getGlueChannelNameByFdc3ChannelId(channelId));
2557
+ this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
2558
+ unsubscribe = yield this.glueController.contextsSubscribe(contextToSubscribeTo, handler);
2559
+ }
2560
+ else {
2561
+ this.logger.info(`[${commandId}] - subscribing for fdc3 user channel with id ${channelId}`);
2562
+ unsubscribe = this.glueController.channelsSubscribe(handler);
2563
+ }
2564
+ return {
2565
+ unsubscribe: () => {
2566
+ this.logger.info(`[${commandId}] - invoking unsubscribe for fdc3 user channel with id ${channelId}`);
2567
+ unsubscribe();
2568
+ }
2569
+ };
2570
+ });
2571
+ }
2563
2572
  getChannelTypeById(channelId) {
2564
2573
  const isUser = this.isUserChannel(channelId);
2565
2574
  if (isUser) {
@@ -3007,48 +3016,6 @@
3007
3016
  }
3008
3017
  }
3009
3018
 
3010
- class ChannelsPendingListenersStore {
3011
- constructor() {
3012
- this.pendingListeners = [];
3013
- }
3014
- createPendingListener(handler, contextType) {
3015
- const id = nanoid();
3016
- const unsubscribe = () => this.filterPendingListenersById(id);
3017
- const listener = { unsubscribe };
3018
- const setActualUnsub = (actualUnsub) => {
3019
- listener.unsubscribe = actualUnsub;
3020
- };
3021
- this.pendingListeners.push({ id, handler, contextType, setActualUnsub, listener, unsubWithoutFilter: () => { } });
3022
- return listener;
3023
- }
3024
- subscribePendingListeners(commandId, addContextListenerFn, channelId) {
3025
- return __awaiter(this, void 0, void 0, function* () {
3026
- const listeners = yield Promise.all(this.pendingListeners.map(pendingListener => {
3027
- const { handler, contextType } = pendingListener;
3028
- return addContextListenerFn({ commandId, handler, contextType, channelId });
3029
- }));
3030
- Object.values(this.pendingListeners).forEach(({ id, setActualUnsub, unsubWithoutFilter }, index) => {
3031
- unsubWithoutFilter = listeners[index].unsubscribe;
3032
- const un = () => {
3033
- this.filterPendingListenersById(id);
3034
- unsubWithoutFilter();
3035
- };
3036
- setActualUnsub(un);
3037
- });
3038
- });
3039
- }
3040
- unsubscribePendingListeners() {
3041
- this.pendingListeners.forEach(({ id, setActualUnsub, unsubWithoutFilter }) => {
3042
- unsubWithoutFilter();
3043
- const newUnsub = () => this.filterPendingListenersById(id);
3044
- setActualUnsub(newUnsub);
3045
- });
3046
- }
3047
- filterPendingListenersById(id) {
3048
- this.pendingListeners = this.pendingListeners.filter((listener) => listener.id !== id);
3049
- }
3050
- }
3051
-
3052
3019
  class IoC {
3053
3020
  get ioc() {
3054
3021
  return this;
@@ -3118,7 +3085,7 @@
3118
3085
  }
3119
3086
  get channelsController() {
3120
3087
  if (!this._channelsController) {
3121
- this._channelsController = new ChannelsController(this.glueController, this.channelsStateStore, this.channelsParser, this.channelsFactory, this.channelsCallbackRegistry, this.channelsPendingListenersStore);
3088
+ this._channelsController = new ChannelsController(this.glueController, this.channelsStateStore, this.channelsParser, this.channelsFactory, this.channelsCallbackRegistry);
3122
3089
  }
3123
3090
  return this._channelsController;
3124
3091
  }
@@ -3128,12 +3095,6 @@
3128
3095
  }
3129
3096
  return this._channelsStateStore;
3130
3097
  }
3131
- get channelsPendingListenersStore() {
3132
- if (!this._channelsPendingListenersStore) {
3133
- this._channelsPendingListenersStore = new ChannelsPendingListenersStore();
3134
- }
3135
- return this._channelsPendingListenersStore;
3136
- }
3137
3098
  get channelsCallbackRegistry() {
3138
3099
  if (!this._channelsCallbackRegistry) {
3139
3100
  this._channelsCallbackRegistry = new ChannelsCallbackRegistry();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interopio/fdc3",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "IO Connect implementation of the FDC3 standard",
5
5
  "main": "dist/fdc3.umd.js",
6
6
  "module": "dist/fdc3.es.js",
@@ -49,5 +49,5 @@
49
49
  "decoder-validate": "^0.0.2",
50
50
  "nanoid": "^4.0.0"
51
51
  },
52
- "gitHead": "e611bbfef816b6ba3722ab8f0ac21d420af8ec9d"
52
+ "gitHead": "600fb46c350ca7a635a20c8686d7b89ecd0e3626"
53
53
  }