@concord-consortium/lara-interactive-api 1.10.0-pre.2 → 1.11.0-pre.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.
package/api.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { IInitInteractive, INavigationOptions, IAuthInfo, ISupportedFeatures, IShowModal, ICloseModal, IGetInteractiveListOptions, IGetInteractiveListResponse, ISetLinkedInteractives, IGetLibraryInteractiveListRequest, IJwtResponse, ICustomMessageHandler, ICustomMessagesHandledMap, IGetInteractiveSnapshotOptions, IGetInteractiveSnapshotResponse, IAddLinkedInteractiveStateListenerOptions, IDecoratedContentEvent, ITextDecorationHandler, WriteAttachmentParams, ReadAttachmentParams, GetAttachmentUrlParams, IGetReportItemAnswerHandler, IReportItemAnswer, OnUnloadFunction, IReportItemHandlerMetadata, ICustomMessage } from "./types";
2
+ import { PubSubChannel } from "./pubsub";
3
+ export { PubSubChannel };
2
4
  export declare const getInitInteractiveMessage: <InteractiveState = {}, AuthoredState = {}, GlobalInteractiveState = {}>() => Promise<IInitInteractive<InteractiveState, AuthoredState, GlobalInteractiveState> | null>;
3
5
  export declare const getMode: () => Promise<"runtime" | "authoring" | "report" | "reportItem" | undefined>;
4
6
  export declare const getInteractiveState: <InteractiveState>() => InteractiveState | null;
@@ -117,3 +119,4 @@ export declare const getAttachmentUrl: (params: GetAttachmentUrlParams) => Promi
117
119
  export declare const sendReportItemAnswer: (request: Omit<IReportItemAnswer, "requestId">) => void;
118
120
  export declare const setOnUnload: (onUnload?: OnUnloadFunction<{}> | undefined) => void;
119
121
  export declare const sendCustomMessage: (customMessage: ICustomMessage) => void;
122
+ export declare const createPubSubChannel: (channelId: string, channelInfo?: any) => PubSubChannel;
package/client.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as iframePhone from "iframe-phone";
2
2
  import { ClientMessage, ICustomMessagesHandledMap, ISupportedFeaturesRequest, ServerMessage, OnUnloadFunction } from "./types";
3
3
  import { ManagedState } from "./managed-state";
4
+ import { PubSubChannel } from "./pubsub";
4
5
  export declare const getClient: () => Client;
5
6
  /**
6
7
  * This class is intended to provide basic helpers (like `post()` or `add/removeListener`), maintain client-specific
@@ -21,5 +22,6 @@ export declare class Client {
21
22
  removeListener(message: ServerMessage, requestId?: number, callback?: iframePhone.ListenerCallback): boolean;
22
23
  setSupportedFeatures: (request: ISupportedFeaturesRequest) => void;
23
24
  setOnUnload: (onUnload?: OnUnloadFunction<{}> | undefined) => void;
25
+ createPubSubChannel(channelId: string, channelInfo?: any): PubSubChannel;
24
26
  private connect;
25
27
  }
package/index-bundle.d.ts CHANGED
@@ -168,8 +168,8 @@ interface ICustomReportFieldsInteractiveState {
168
168
  };
169
169
  };
170
170
  }
171
- declare type IRuntimeClientMessage = "interactiveState" | "height" | "hint" | "getAttachmentUrl" | "getAuthInfo" | "supportedFeatures" | "navigation" | "getFirebaseJWT" | "authoredState" | "authoringCustomReportFields" | "runtimeCustomReportValues" | "showModal" | "closeModal" | "getLibraryInteractiveList" | "getInteractiveSnapshot" | "addLinkedInteractiveStateListener" | "removeLinkedInteractiveStateListener" | "decoratedContentEvent" | "customMessage";
172
- declare type IRuntimeServerMessage = "attachmentUrl" | "authInfo" | "getInteractiveState" | "initInteractive" | "firebaseJWT" | "closedModal" | "customMessage" | "libraryInteractiveList" | "interactiveSnapshot" | "contextMembership" | "linkedInteractiveState" | "decorateContent";
171
+ declare type IRuntimeClientMessage = "interactiveState" | "height" | "hint" | "getAttachmentUrl" | "getAuthInfo" | "supportedFeatures" | "navigation" | "getFirebaseJWT" | "authoredState" | "authoringCustomReportFields" | "runtimeCustomReportValues" | "showModal" | "closeModal" | "getLibraryInteractiveList" | "getInteractiveSnapshot" | "addLinkedInteractiveStateListener" | "removeLinkedInteractiveStateListener" | "decoratedContentEvent" | "customMessage" | "createChannel" | "publish" | "subscribe" | "unsubscribe";
172
+ declare type IRuntimeServerMessage = "attachmentUrl" | "authInfo" | "getInteractiveState" | "initInteractive" | "firebaseJWT" | "closedModal" | "customMessage" | "libraryInteractiveList" | "interactiveSnapshot" | "contextMembership" | "linkedInteractiveState" | "decorateContent" | "pubSubMessage" | "pubSubChannelInfo";
173
173
  declare type IAuthoringClientMessage = "getInteractiveList" | "setLinkedInteractives" | "getFirebaseJWT";
174
174
  declare type IAuthoringServerMessage = "interactiveList" | "firebaseJWT";
175
175
  declare type IReportItemClientMessage = "reportItemAnswer" | "reportItemClientReady";
@@ -480,6 +480,38 @@ interface IMediaLibrary {
480
480
  * The @concord-consortium/object-storage package implements both the in-memory and Firebase backends.
481
481
  */
482
482
  declare type IOpaqueObjectStorageConfig = Record<string, unknown>;
483
+ interface IPubSubCreateChannel {
484
+ channelId: string;
485
+ channelInfo: any;
486
+ timestamp: number;
487
+ }
488
+ interface IPubSubPublish {
489
+ channelId: string;
490
+ message: any;
491
+ timestamp: number;
492
+ }
493
+ interface IPubSubSubscribe {
494
+ channelId: string;
495
+ subscriptionId: string;
496
+ }
497
+ interface IPubSubUnsubscribe {
498
+ channelId: string;
499
+ subscriptionId: string;
500
+ }
501
+ interface IPubSubMessage {
502
+ channelId: string;
503
+ message: any;
504
+ publisherId: string;
505
+ timestamp: number;
506
+ }
507
+ interface IPubSubChannelInfo {
508
+ channelId: string;
509
+ channelInfo: any;
510
+ publisherId: string;
511
+ timestamp: number;
512
+ }
513
+ declare type PubSubMessageHandler = (message: any, publisherId: string) => void;
514
+ declare type PubSubChannelInfoHandler = (channelInfo: any, publisherId: string) => void;
483
515
 
484
516
  declare type ChoiceId = string;
485
517
  interface IAuthoringMetadataBase {
@@ -546,6 +578,70 @@ declare type IRuntimeMetadata = IRuntimeInteractiveMetadata | IRuntimeOpenRespon
546
578
 
547
579
  declare const inIframe: () => boolean;
548
580
 
581
+ declare type ManagedStateEvent = "interactiveStateUpdated" | "globalInteractiveStateUpdated" | "authoredStateUpdated" | "initInteractive";
582
+ declare class ManagedState {
583
+ interactiveStateDirty: boolean;
584
+ private _initMessage;
585
+ private _interactiveState;
586
+ private _authoredState;
587
+ private _globalInteractiveState;
588
+ private emitter;
589
+ get initMessage(): any;
590
+ set initMessage(value: any);
591
+ get interactiveState(): any;
592
+ set interactiveState(value: any);
593
+ get authoredState(): any;
594
+ set authoredState(value: any);
595
+ get globalInteractiveState(): any;
596
+ set globalInteractiveState(value: any);
597
+ emit(event: ManagedStateEvent, content?: any): void;
598
+ on(event: ManagedStateEvent, handler: any): void;
599
+ off(event: ManagedStateEvent, handler: any): void;
600
+ once(event: ManagedStateEvent, handler: any): void;
601
+ }
602
+
603
+ declare const getClient: () => Client;
604
+ /**
605
+ * This class is intended to provide basic helpers (like `post()` or `add/removeListener`), maintain client-specific
606
+ * state, and generally be as minimal as possible. Most of the client-specific helpers and logic can be implemented
607
+ * in api.ts or hooks.ts (or both so the client app has choice).
608
+ */
609
+ declare class Client {
610
+ phone: iframePhone.IFrameEndpoint;
611
+ managedState: ManagedState;
612
+ customMessagesHandled: ICustomMessagesHandledMap;
613
+ private listeners;
614
+ private requestId;
615
+ private onUnload;
616
+ constructor();
617
+ getNextRequestId(): number;
618
+ post(message: ClientMessage, content?: any): void;
619
+ addListener(message: ServerMessage, callback: iframePhone.ListenerCallback, requestId?: number): boolean;
620
+ removeListener(message: ServerMessage, requestId?: number, callback?: iframePhone.ListenerCallback): boolean;
621
+ setSupportedFeatures: (request: ISupportedFeaturesRequest) => void;
622
+ setOnUnload: (onUnload?: OnUnloadFunction<{}> | undefined) => void;
623
+ createPubSubChannel(channelId: string, channelInfo?: any): PubSubChannel;
624
+ private connect;
625
+ }
626
+
627
+ declare class PubSubChannel {
628
+ private client;
629
+ private channelId;
630
+ private channelInfo;
631
+ private subscriptions;
632
+ private listenersRegistered;
633
+ constructor(client: Client, channelId: string, channelInfo?: any);
634
+ publish(message: any): void;
635
+ subscribe(handler: PubSubMessageHandler, onChannelInfo?: PubSubChannelInfoHandler): () => void;
636
+ dispose(): void;
637
+ getChannelId(): string;
638
+ getChannelInfo(): any;
639
+ setChannelInfo(channelInfo: any): void;
640
+ private registerListeners;
641
+ private createChannel;
642
+ private unsubscribe;
643
+ }
644
+
549
645
  declare const getInitInteractiveMessage: <InteractiveState = {}, AuthoredState = {}, GlobalInteractiveState = {}>() => Promise<IInitInteractive<InteractiveState, AuthoredState, GlobalInteractiveState> | null>;
550
646
  declare const getMode: () => Promise<"runtime" | "authoring" | "report" | "reportItem" | undefined>;
551
647
  declare const getInteractiveState: <InteractiveState>() => InteractiveState | null;
@@ -664,6 +760,7 @@ declare const getAttachmentUrl: (params: GetAttachmentUrlParams) => Promise<stri
664
760
  declare const sendReportItemAnswer: (request: Omit<IReportItemAnswer, "requestId">) => void;
665
761
  declare const setOnUnload: (onUnload?: OnUnloadFunction<{}> | undefined) => void;
666
762
  declare const sendCustomMessage: (customMessage: ICustomMessage) => void;
763
+ declare const createPubSubChannel: (channelId: string, channelInfo?: any) => PubSubChannel;
667
764
 
668
765
  declare type UpdateFunc<S> = (prevState: S | null) => S;
669
766
  declare const useInteractiveState: <InteractiveState>() => {
@@ -695,49 +792,4 @@ interface IUseAccessibilityProps {
695
792
  }
696
793
  declare const useAccessibility: (props?: IUseAccessibilityProps | undefined) => IAccessibilitySettings;
697
794
 
698
- declare type ManagedStateEvent = "interactiveStateUpdated" | "globalInteractiveStateUpdated" | "authoredStateUpdated" | "initInteractive";
699
- declare class ManagedState {
700
- interactiveStateDirty: boolean;
701
- private _initMessage;
702
- private _interactiveState;
703
- private _authoredState;
704
- private _globalInteractiveState;
705
- private emitter;
706
- get initMessage(): any;
707
- set initMessage(value: any);
708
- get interactiveState(): any;
709
- set interactiveState(value: any);
710
- get authoredState(): any;
711
- set authoredState(value: any);
712
- get globalInteractiveState(): any;
713
- set globalInteractiveState(value: any);
714
- emit(event: ManagedStateEvent, content?: any): void;
715
- on(event: ManagedStateEvent, handler: any): void;
716
- off(event: ManagedStateEvent, handler: any): void;
717
- once(event: ManagedStateEvent, handler: any): void;
718
- }
719
-
720
- declare const getClient: () => Client;
721
- /**
722
- * This class is intended to provide basic helpers (like `post()` or `add/removeListener`), maintain client-specific
723
- * state, and generally be as minimal as possible. Most of the client-specific helpers and logic can be implemented
724
- * in api.ts or hooks.ts (or both so the client app has choice).
725
- */
726
- declare class Client {
727
- phone: iframePhone.IFrameEndpoint;
728
- managedState: ManagedState;
729
- customMessagesHandled: ICustomMessagesHandledMap;
730
- private listeners;
731
- private requestId;
732
- private onUnload;
733
- constructor();
734
- getNextRequestId(): number;
735
- post(message: ClientMessage, content?: any): void;
736
- addListener(message: ServerMessage, callback: iframePhone.ListenerCallback, requestId?: number): boolean;
737
- removeListener(message: ServerMessage, requestId?: number, callback?: iframePhone.ListenerCallback): boolean;
738
- setSupportedFeatures: (request: ISupportedFeaturesRequest) => void;
739
- setOnUnload: (onUnload?: OnUnloadFunction<{}> | undefined) => void;
740
- private connect;
741
- }
742
-
743
- export { AttachmentInfoMap, ChoiceId, Client, ClientMessage, DefaultAccessibilitySettings, DeprecatedRuntimeClientMessage, DeprecatedRuntimeServerMessage, GetAttachmentUrlParams, GlobalIFrameSaverClientMessage, GlobalIFrameSaverServerMessage, IAccessibilitySettings, IAddLinkedInteractiveStateListenerOptions, IAddLinkedInteractiveStateListenerRequest, IAttachmentInfo, IAttachmentUrlRequest, IAttachmentUrlResponse, IAuthInfo, IAuthoringClientMessage, IAuthoringCustomReportField, IAuthoringCustomReportFields, IAuthoringImageQuestionMetadata, IAuthoringInitInteractive, IAuthoringInteractiveMetadata, IAuthoringMetadata, IAuthoringMetadataBase, IAuthoringMultipleChoiceChoiceMetadata, IAuthoringMultipleChoiceMetadata, IAuthoringOpenResponseMetadata, IAuthoringServerMessage, IBaseShowModal, ICloseModal, IContextMember, IContextMembership, ICustomMessage, ICustomMessageHandler, ICustomMessageOptions, ICustomMessagesHandledMap, ICustomReportFieldsAuthoredState, ICustomReportFieldsAuthoredStateField, ICustomReportFieldsInteractiveState, IDataset, IDecoratedContentEvent, IGetAuthInfoRequest, IGetAuthInfoResponse, IGetFirebaseJwtRequest, IGetFirebaseJwtResponse, IGetInteractiveListOptions, IGetInteractiveListRequest, IGetInteractiveListResponse, IGetInteractiveSnapshotOptions, IGetInteractiveSnapshotRequest, IGetInteractiveSnapshotResponse, IGetInteractiveState, IGetLibraryInteractiveListOptions, IGetLibraryInteractiveListRequest, IGetLibraryInteractiveListResponse, IGetReportItemAnswer, IGetReportItemAnswerHandler, IHintRequest, IHostFeatureSupport, IHostFeatures, IHostModalSupport, IInitInteractive, IInteractiveListResponseItem, IInteractiveStateProps, IInteractiveStateWithDataset, IJwtClaims, IJwtResponse, ILibraryInteractiveListResponseItem, ILinkedInteractive, ILinkedInteractiveStateResponse, IMediaLibrary, IMediaLibraryItem, IMediaLibraryItemType, INavigationOptions, IOpaqueObjectStorageConfig, IPortalClaims, IRemoveLinkedInteractiveStateListenerRequest, IReportInitInteractive, IReportItemAnswer, IReportItemAnswerItem, IReportItemAnswerItemAnswerText, IReportItemAnswerItemAttachment, IReportItemAnswerItemHtml, IReportItemAnswerItemLinks, IReportItemAnswerItemScore, IReportItemClientMessage, IReportItemHandlerMetadata, IReportItemInitInteractive, IReportItemServerMessage, IRuntimeClientMessage, IRuntimeCustomReportValues, IRuntimeImageQuestionMetadata, IRuntimeInitInteractive, IRuntimeInteractiveMetadata, IRuntimeMetadata, IRuntimeMetadataBase, IRuntimeMultipleChoiceMetadata, IRuntimeOpenResponseMetadata, IRuntimeServerMessage, ISetLinkedInteractives, IShowAlert, IShowDialog, IShowLightbox, IShowModal, ISupportedFeatures, ISupportedFeaturesRequest, ITextDecorationHandler, ITextDecorationHandlerInfo, ITextDecorationInfo, IThemeInfo, IUseAccessibilityProps, IUseReportItemOptions, IWriteAttachmentRequest, IframePhoneServerMessage, InitInteractiveMode, InteractiveItemId, LoggerClientMessage, ModalType, OnUnloadFunction, ReadAttachmentParams, ReportItemsType, ServerMessage, WriteAttachmentParams, addAuthoredStateListener, addCustomMessageListener, addDecorateContentListener, addGetReportItemAnswerListener, addGlobalInteractiveStateListener, addInteractiveStateListener, addLinkedInteractiveStateListener, closeModal, flushStateUpdates, getAttachmentUrl, getAuthInfo, getAuthoredState, getClient, getFirebaseJwt, getGlobalInteractiveState, getInitInteractiveMessage, getInteractiveList, getInteractiveSnapshot, getInteractiveState, getLibraryInteractiveList, getMode, inIframe, log, notifyReportItemClientReady, postDecoratedContentEvent, readAttachment, removeAuthoredStateListener, removeCustomMessageListener, removeDecorateContentListener, removeGetReportItemAnswerListener, removeGlobalInteractiveStateListener, removeInteractiveStateListener, removeLinkedInteractiveStateListener, sendCustomMessage, sendReportItemAnswer, setAuthoredState, setGlobalInteractiveState, setHeight, setHint, setInteractiveState, setInteractiveStateTimeout, setLinkedInteractives, setNavigation, setOnUnload, setSupportedFeatures, showModal, useAccessibility, useAuthoredState, useAutoSetHeight, useCustomMessages, useDecorateContent, useGlobalInteractiveState, useInitMessage, useInteractiveState, useReportItem, writeAttachment };
795
+ export { AttachmentInfoMap, ChoiceId, Client, ClientMessage, DefaultAccessibilitySettings, DeprecatedRuntimeClientMessage, DeprecatedRuntimeServerMessage, GetAttachmentUrlParams, GlobalIFrameSaverClientMessage, GlobalIFrameSaverServerMessage, IAccessibilitySettings, IAddLinkedInteractiveStateListenerOptions, IAddLinkedInteractiveStateListenerRequest, IAttachmentInfo, IAttachmentUrlRequest, IAttachmentUrlResponse, IAuthInfo, IAuthoringClientMessage, IAuthoringCustomReportField, IAuthoringCustomReportFields, IAuthoringImageQuestionMetadata, IAuthoringInitInteractive, IAuthoringInteractiveMetadata, IAuthoringMetadata, IAuthoringMetadataBase, IAuthoringMultipleChoiceChoiceMetadata, IAuthoringMultipleChoiceMetadata, IAuthoringOpenResponseMetadata, IAuthoringServerMessage, IBaseShowModal, ICloseModal, IContextMember, IContextMembership, ICustomMessage, ICustomMessageHandler, ICustomMessageOptions, ICustomMessagesHandledMap, ICustomReportFieldsAuthoredState, ICustomReportFieldsAuthoredStateField, ICustomReportFieldsInteractiveState, IDataset, IDecoratedContentEvent, IGetAuthInfoRequest, IGetAuthInfoResponse, IGetFirebaseJwtRequest, IGetFirebaseJwtResponse, IGetInteractiveListOptions, IGetInteractiveListRequest, IGetInteractiveListResponse, IGetInteractiveSnapshotOptions, IGetInteractiveSnapshotRequest, IGetInteractiveSnapshotResponse, IGetInteractiveState, IGetLibraryInteractiveListOptions, IGetLibraryInteractiveListRequest, IGetLibraryInteractiveListResponse, IGetReportItemAnswer, IGetReportItemAnswerHandler, IHintRequest, IHostFeatureSupport, IHostFeatures, IHostModalSupport, IInitInteractive, IInteractiveListResponseItem, IInteractiveStateProps, IInteractiveStateWithDataset, IJwtClaims, IJwtResponse, ILibraryInteractiveListResponseItem, ILinkedInteractive, ILinkedInteractiveStateResponse, IMediaLibrary, IMediaLibraryItem, IMediaLibraryItemType, INavigationOptions, IOpaqueObjectStorageConfig, IPortalClaims, IPubSubChannelInfo, IPubSubCreateChannel, IPubSubMessage, IPubSubPublish, IPubSubSubscribe, IPubSubUnsubscribe, IRemoveLinkedInteractiveStateListenerRequest, IReportInitInteractive, IReportItemAnswer, IReportItemAnswerItem, IReportItemAnswerItemAnswerText, IReportItemAnswerItemAttachment, IReportItemAnswerItemHtml, IReportItemAnswerItemLinks, IReportItemAnswerItemScore, IReportItemClientMessage, IReportItemHandlerMetadata, IReportItemInitInteractive, IReportItemServerMessage, IRuntimeClientMessage, IRuntimeCustomReportValues, IRuntimeImageQuestionMetadata, IRuntimeInitInteractive, IRuntimeInteractiveMetadata, IRuntimeMetadata, IRuntimeMetadataBase, IRuntimeMultipleChoiceMetadata, IRuntimeOpenResponseMetadata, IRuntimeServerMessage, ISetLinkedInteractives, IShowAlert, IShowDialog, IShowLightbox, IShowModal, ISupportedFeatures, ISupportedFeaturesRequest, ITextDecorationHandler, ITextDecorationHandlerInfo, ITextDecorationInfo, IThemeInfo, IUseAccessibilityProps, IUseReportItemOptions, IWriteAttachmentRequest, IframePhoneServerMessage, InitInteractiveMode, InteractiveItemId, LoggerClientMessage, ModalType, OnUnloadFunction, PubSubChannel, PubSubChannelInfoHandler, PubSubMessageHandler, ReadAttachmentParams, ReportItemsType, ServerMessage, WriteAttachmentParams, addAuthoredStateListener, addCustomMessageListener, addDecorateContentListener, addGetReportItemAnswerListener, addGlobalInteractiveStateListener, addInteractiveStateListener, addLinkedInteractiveStateListener, closeModal, createPubSubChannel, flushStateUpdates, getAttachmentUrl, getAuthInfo, getAuthoredState, getClient, getFirebaseJwt, getGlobalInteractiveState, getInitInteractiveMessage, getInteractiveList, getInteractiveSnapshot, getInteractiveState, getLibraryInteractiveList, getMode, inIframe, log, notifyReportItemClientReady, postDecoratedContentEvent, readAttachment, removeAuthoredStateListener, removeCustomMessageListener, removeDecorateContentListener, removeGetReportItemAnswerListener, removeGlobalInteractiveStateListener, removeInteractiveStateListener, removeLinkedInteractiveStateListener, sendCustomMessage, sendReportItemAnswer, setAuthoredState, setGlobalInteractiveState, setHeight, setHint, setInteractiveState, setInteractiveStateTimeout, setLinkedInteractives, setNavigation, setOnUnload, setSupportedFeatures, showModal, useAccessibility, useAuthoredState, useAutoSetHeight, useCustomMessages, useDecorateContent, useGlobalInteractiveState, useInitMessage, useInteractiveState, useReportItem, writeAttachment };
package/index.js CHANGED
@@ -2268,6 +2268,77 @@ module.exports = {
2268
2268
  };
2269
2269
 
2270
2270
 
2271
+ /***/ }),
2272
+
2273
+ /***/ "./node_modules/nanoid/index.browser.js":
2274
+ /*!**********************************************!*\
2275
+ !*** ./node_modules/nanoid/index.browser.js ***!
2276
+ \**********************************************/
2277
+ /*! exports provided: nanoid, customAlphabet, customRandom, urlAlphabet, random */
2278
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
2279
+
2280
+ "use strict";
2281
+ __webpack_require__.r(__webpack_exports__);
2282
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "nanoid", function() { return nanoid; });
2283
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "customAlphabet", function() { return customAlphabet; });
2284
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "customRandom", function() { return customRandom; });
2285
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "random", function() { return random; });
2286
+ /* harmony import */ var _url_alphabet_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./url-alphabet/index.js */ "./node_modules/nanoid/url-alphabet/index.js");
2287
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "urlAlphabet", function() { return _url_alphabet_index_js__WEBPACK_IMPORTED_MODULE_0__["urlAlphabet"]; });
2288
+
2289
+
2290
+ let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
2291
+ let customRandom = (alphabet, defaultSize, getRandom) => {
2292
+ let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
2293
+ let step = -~((1.6 * mask * defaultSize) / alphabet.length)
2294
+ return (size = defaultSize) => {
2295
+ let id = ''
2296
+ while (true) {
2297
+ let bytes = getRandom(step)
2298
+ let j = step | 0
2299
+ while (j--) {
2300
+ id += alphabet[bytes[j] & mask] || ''
2301
+ if (id.length === size) return id
2302
+ }
2303
+ }
2304
+ }
2305
+ }
2306
+ let customAlphabet = (alphabet, size = 21) =>
2307
+ customRandom(alphabet, size, random)
2308
+ let nanoid = (size = 21) =>
2309
+ crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
2310
+ byte &= 63
2311
+ if (byte < 36) {
2312
+ id += byte.toString(36)
2313
+ } else if (byte < 62) {
2314
+ id += (byte - 26).toString(36).toUpperCase()
2315
+ } else if (byte > 62) {
2316
+ id += '-'
2317
+ } else {
2318
+ id += '_'
2319
+ }
2320
+ return id
2321
+ }, '')
2322
+
2323
+
2324
+
2325
+ /***/ }),
2326
+
2327
+ /***/ "./node_modules/nanoid/url-alphabet/index.js":
2328
+ /*!***************************************************!*\
2329
+ !*** ./node_modules/nanoid/url-alphabet/index.js ***!
2330
+ \***************************************************/
2331
+ /*! exports provided: urlAlphabet */
2332
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
2333
+
2334
+ "use strict";
2335
+ __webpack_require__.r(__webpack_exports__);
2336
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "urlAlphabet", function() { return urlAlphabet; });
2337
+ let urlAlphabet =
2338
+ 'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
2339
+
2340
+
2341
+
2271
2342
  /***/ }),
2272
2343
 
2273
2344
  /***/ "./node_modules/process/browser.js":
@@ -4618,9 +4689,11 @@ var __rest = (this && this.__rest) || function (s, e) {
4618
4689
  return t;
4619
4690
  };
4620
4691
  Object.defineProperty(exports, "__esModule", { value: true });
4621
- exports.sendCustomMessage = exports.setOnUnload = exports.sendReportItemAnswer = exports.getAttachmentUrl = exports.readAttachment = exports.writeAttachment = exports.getLibraryInteractiveList = exports.getInteractiveSnapshot = exports.setLinkedInteractives = exports.getInteractiveList = exports.closeModal = exports.showModal = exports.removeLinkedInteractiveStateListener = exports.addLinkedInteractiveStateListener = exports.removeGlobalInteractiveStateListener = exports.addGlobalInteractiveStateListener = exports.removeAuthoredStateListener = exports.addAuthoredStateListener = exports.removeInteractiveStateListener = exports.addInteractiveStateListener = exports.log = exports.getFirebaseJwt = exports.getAuthInfo = exports.setNavigation = exports.setHint = exports.postDecoratedContentEvent = exports.setHeight = exports.setSupportedFeatures = exports.notifyReportItemClientReady = exports.removeGetReportItemAnswerListener = exports.addGetReportItemAnswerListener = exports.removeDecorateContentListener = exports.addDecorateContentListener = exports.removeCustomMessageListener = exports.addCustomMessageListener = exports.setGlobalInteractiveState = exports.getGlobalInteractiveState = exports.setAuthoredState = exports.getAuthoredState = exports.flushStateUpdates = exports.setInteractiveState = exports.setInteractiveStateTimeout = exports.getInteractiveState = exports.getMode = exports.getInitInteractiveMessage = void 0;
4692
+ exports.createPubSubChannel = exports.sendCustomMessage = exports.setOnUnload = exports.sendReportItemAnswer = exports.getAttachmentUrl = exports.readAttachment = exports.writeAttachment = exports.getLibraryInteractiveList = exports.getInteractiveSnapshot = exports.setLinkedInteractives = exports.getInteractiveList = exports.closeModal = exports.showModal = exports.removeLinkedInteractiveStateListener = exports.addLinkedInteractiveStateListener = exports.removeGlobalInteractiveStateListener = exports.addGlobalInteractiveStateListener = exports.removeAuthoredStateListener = exports.addAuthoredStateListener = exports.removeInteractiveStateListener = exports.addInteractiveStateListener = exports.log = exports.getFirebaseJwt = exports.getAuthInfo = exports.setNavigation = exports.setHint = exports.postDecoratedContentEvent = exports.setHeight = exports.setSupportedFeatures = exports.notifyReportItemClientReady = exports.removeGetReportItemAnswerListener = exports.addGetReportItemAnswerListener = exports.removeDecorateContentListener = exports.addDecorateContentListener = exports.removeCustomMessageListener = exports.addCustomMessageListener = exports.setGlobalInteractiveState = exports.getGlobalInteractiveState = exports.setAuthoredState = exports.getAuthoredState = exports.flushStateUpdates = exports.setInteractiveState = exports.setInteractiveStateTimeout = exports.getInteractiveState = exports.getMode = exports.getInitInteractiveMessage = exports.PubSubChannel = void 0;
4622
4693
  var client_1 = __webpack_require__(/*! ./client */ "./src/interactive-api-client/client.ts");
4623
4694
  var uuid_1 = __webpack_require__(/*! uuid */ "./node_modules/uuid/dist/esm-browser/index.js");
4695
+ var pubsub_1 = __webpack_require__(/*! ./pubsub */ "./src/interactive-api-client/pubsub.ts");
4696
+ Object.defineProperty(exports, "PubSubChannel", { enumerable: true, get: function () { return pubsub_1.PubSubChannel; } });
4624
4697
  var THROW_NOT_IMPLEMENTED_YET = function (method) {
4625
4698
  throw new Error(method + " is not yet implemented in the client!");
4626
4699
  };
@@ -5126,6 +5199,10 @@ var sendCustomMessage = function (customMessage) {
5126
5199
  (0, client_1.getClient)().post("customMessage", customMessage);
5127
5200
  };
5128
5201
  exports.sendCustomMessage = sendCustomMessage;
5202
+ var createPubSubChannel = function (channelId, channelInfo) {
5203
+ return (0, client_1.getClient)().createPubSubChannel(channelId, channelInfo);
5204
+ };
5205
+ exports.createPubSubChannel = createPubSubChannel;
5129
5206
 
5130
5207
 
5131
5208
  /***/ }),
@@ -5205,6 +5282,7 @@ exports.Client = exports.getClient = void 0;
5205
5282
  var iframePhone = __webpack_require__(/*! iframe-phone */ "./node_modules/iframe-phone/main.js");
5206
5283
  var in_frame_1 = __webpack_require__(/*! ./in-frame */ "./src/interactive-api-client/in-frame.ts");
5207
5284
  var managed_state_1 = __webpack_require__(/*! ./managed-state */ "./src/interactive-api-client/managed-state.ts");
5285
+ var pubsub_1 = __webpack_require__(/*! ./pubsub */ "./src/interactive-api-client/pubsub.ts");
5208
5286
  var parseJSONIfString = function (data) {
5209
5287
  // Note that we don't want to call JSON.parse for an empty string.
5210
5288
  try {
@@ -5327,6 +5405,9 @@ var Client = /** @class */ (function () {
5327
5405
  }
5328
5406
  return false;
5329
5407
  };
5408
+ Client.prototype.createPubSubChannel = function (channelId, channelInfo) {
5409
+ return new pubsub_1.PubSubChannel(this, channelId, channelInfo);
5410
+ };
5330
5411
  Client.prototype.connect = function () {
5331
5412
  var _this = this;
5332
5413
  this.phone = iframePhone.getIFrameEndpoint();
@@ -5823,7 +5904,125 @@ Object.defineProperty(exports, "__esModule", { value: true });
5823
5904
  /*! exports provided: name, version, description, main, types, repository, author, license, bugs, homepage, dependencies, peerDependencies, default */
5824
5905
  /***/ (function(module) {
5825
5906
 
5826
- module.exports = JSON.parse("{\"name\":\"@concord-consortium/lara-interactive-api\",\"version\":\"1.10.0-pre.2\",\"description\":\"LARA Interactive API client and types\",\"main\":\"./index.js\",\"types\":\"./index-bundle.d.ts\",\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/concord-consortium/lara.git\"},\"author\":\"Concord Consortium\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/concord-consortium/lara/issues\"},\"homepage\":\"https://github.com/concord-consortium/lara/tree/master/lara-typescript/src/interactive-api-client#readme\",\"dependencies\":{\"iframe-phone\":\"^1.3.1\"},\"peerDependencies\":{\"react\":\">=16.9.0\",\"react-dom\":\">=16.9.0\"}}");
5907
+ module.exports = JSON.parse("{\"name\":\"@concord-consortium/lara-interactive-api\",\"version\":\"1.11.0-pre.0\",\"description\":\"LARA Interactive API client and types\",\"main\":\"./index.js\",\"types\":\"./index-bundle.d.ts\",\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/concord-consortium/lara.git\"},\"author\":\"Concord Consortium\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://github.com/concord-consortium/lara/issues\"},\"homepage\":\"https://github.com/concord-consortium/lara/tree/master/lara-typescript/src/interactive-api-client#readme\",\"dependencies\":{\"iframe-phone\":\"^1.3.1\",\"nanoid\":\"^3.3.7\"},\"peerDependencies\":{\"react\":\">=16.9.0\",\"react-dom\":\">=16.9.0\"}}");
5908
+
5909
+ /***/ }),
5910
+
5911
+ /***/ "./src/interactive-api-client/pubsub.ts":
5912
+ /*!**********************************************!*\
5913
+ !*** ./src/interactive-api-client/pubsub.ts ***!
5914
+ \**********************************************/
5915
+ /*! no static exports found */
5916
+ /***/ (function(module, exports, __webpack_require__) {
5917
+
5918
+ "use strict";
5919
+
5920
+ Object.defineProperty(exports, "__esModule", { value: true });
5921
+ exports.PubSubChannel = void 0;
5922
+ var nanoid_1 = __webpack_require__(/*! nanoid */ "./node_modules/nanoid/index.browser.js");
5923
+ var PubSubChannel = /** @class */ (function () {
5924
+ function PubSubChannel(client, channelId, channelInfo) {
5925
+ this.subscriptions = new Map();
5926
+ this.listenersRegistered = false;
5927
+ this.client = client;
5928
+ this.channelId = channelId;
5929
+ this.channelInfo = channelInfo;
5930
+ // Always create the channel on construction
5931
+ this.createChannel();
5932
+ }
5933
+ PubSubChannel.prototype.publish = function (message) {
5934
+ var publishMessage = {
5935
+ channelId: this.channelId,
5936
+ message: message,
5937
+ timestamp: Date.now()
5938
+ };
5939
+ this.client.post("publish", publishMessage);
5940
+ };
5941
+ PubSubChannel.prototype.subscribe = function (handler, onChannelInfo) {
5942
+ var _this = this;
5943
+ var subscriptionId = (0, nanoid_1.nanoid)();
5944
+ // Store handlers locally
5945
+ this.subscriptions.set(subscriptionId, {
5946
+ handler: handler,
5947
+ channelInfoHandler: onChannelInfo
5948
+ });
5949
+ // Register listeners for pubSubMessage and pubSubChannelInfo if not already done
5950
+ if (!this.listenersRegistered) {
5951
+ this.registerListeners();
5952
+ }
5953
+ // Send subscribe message to host
5954
+ var subscribeMessage = {
5955
+ channelId: this.channelId,
5956
+ subscriptionId: subscriptionId
5957
+ };
5958
+ this.client.post("subscribe", subscribeMessage);
5959
+ // Return unsubscribe function
5960
+ return function () {
5961
+ _this.unsubscribe(subscriptionId);
5962
+ };
5963
+ };
5964
+ PubSubChannel.prototype.dispose = function () {
5965
+ var _this = this;
5966
+ // Unsubscribe all subscriptions
5967
+ var subscriptionIds = Array.from(this.subscriptions.keys());
5968
+ subscriptionIds.forEach(function (subscriptionId) {
5969
+ _this.unsubscribe(subscriptionId);
5970
+ });
5971
+ };
5972
+ PubSubChannel.prototype.getChannelId = function () {
5973
+ return this.channelId;
5974
+ };
5975
+ PubSubChannel.prototype.getChannelInfo = function () {
5976
+ return this.channelInfo;
5977
+ };
5978
+ PubSubChannel.prototype.setChannelInfo = function (channelInfo) {
5979
+ this.channelInfo = channelInfo;
5980
+ this.createChannel();
5981
+ };
5982
+ PubSubChannel.prototype.registerListeners = function () {
5983
+ var _this = this;
5984
+ // Listen for pubSubMessage events for this channel
5985
+ this.client.addListener("pubSubMessage", function (content) {
5986
+ if (content.channelId === _this.channelId) {
5987
+ _this.subscriptions.forEach(function (subscription) {
5988
+ subscription.handler(content.message, content.publisherId);
5989
+ });
5990
+ }
5991
+ });
5992
+ // Listen for pubSubChannelInfo events for this channel
5993
+ this.client.addListener("pubSubChannelInfo", function (content) {
5994
+ if (content.channelId === _this.channelId) {
5995
+ _this.subscriptions.forEach(function (subscription) {
5996
+ if (subscription.channelInfoHandler) {
5997
+ subscription.channelInfoHandler(content.channelInfo, content.publisherId);
5998
+ }
5999
+ });
6000
+ }
6001
+ });
6002
+ this.listenersRegistered = true;
6003
+ };
6004
+ PubSubChannel.prototype.createChannel = function () {
6005
+ var createMessage = {
6006
+ channelId: this.channelId,
6007
+ channelInfo: this.channelInfo,
6008
+ timestamp: Date.now()
6009
+ };
6010
+ this.client.post("createChannel", createMessage);
6011
+ };
6012
+ PubSubChannel.prototype.unsubscribe = function (subscriptionId) {
6013
+ // Remove local reference
6014
+ this.subscriptions.delete(subscriptionId);
6015
+ // Send unsubscribe message to host
6016
+ var unsubscribeMessage = {
6017
+ channelId: this.channelId,
6018
+ subscriptionId: subscriptionId
6019
+ };
6020
+ this.client.post("unsubscribe", unsubscribeMessage);
6021
+ };
6022
+ return PubSubChannel;
6023
+ }());
6024
+ exports.PubSubChannel = PubSubChannel;
6025
+
5827
6026
 
5828
6027
  /***/ }),
5829
6028
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@concord-consortium/lara-interactive-api",
3
- "version": "1.10.0-pre.2",
3
+ "version": "1.11.0-pre.0",
4
4
  "description": "LARA Interactive API client and types",
5
5
  "main": "./index.js",
6
6
  "types": "./index-bundle.d.ts",
@@ -15,7 +15,8 @@
15
15
  },
16
16
  "homepage": "https://github.com/concord-consortium/lara/tree/master/lara-typescript/src/interactive-api-client#readme",
17
17
  "dependencies": {
18
- "iframe-phone": "^1.3.1"
18
+ "iframe-phone": "^1.3.1",
19
+ "nanoid": "^3.3.7"
19
20
  },
20
21
  "peerDependencies": {
21
22
  "react": ">=16.9.0",
package/pubsub.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ import { PubSubMessageHandler, PubSubChannelInfoHandler } from "./types";
2
+ import { Client } from "./client";
3
+ export declare class PubSubChannel {
4
+ private client;
5
+ private channelId;
6
+ private channelInfo;
7
+ private subscriptions;
8
+ private listenersRegistered;
9
+ constructor(client: Client, channelId: string, channelInfo?: any);
10
+ publish(message: any): void;
11
+ subscribe(handler: PubSubMessageHandler, onChannelInfo?: PubSubChannelInfoHandler): () => void;
12
+ dispose(): void;
13
+ getChannelId(): string;
14
+ getChannelInfo(): any;
15
+ setChannelInfo(channelInfo: any): void;
16
+ private registerListeners;
17
+ private createChannel;
18
+ private unsubscribe;
19
+ }
@@ -0,0 +1 @@
1
+ export {};