@monterosa/sdk-interact-kit 2.0.0-rc.3 → 2.0.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1342 @@
1
+ /**
2
+ * Manages interactive elements such as polls, votes, and leaderboards.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ import { Connect as Connect_2 } from '@monterosa/sdk-connect-kit';
8
+ import { Emitter } from '@monterosa/sdk-util';
9
+ import { MonterosaKit } from '@monterosa/sdk-core';
10
+ import { MonterosaSdk } from '@monterosa/sdk-core';
11
+ import { Unsubscribe } from '@monterosa/sdk-util';
12
+
13
+ /**
14
+ * An `Answer` contains data of the user answer. Can be used to manage number of
15
+ * votes that the user placed for a specific option.
16
+ */
17
+ export declare class Answer {
18
+ private _answers;
19
+ constructor(answers?: AnswerValue[]);
20
+ /**
21
+ * The array of user answers
22
+ */
23
+ get answers(): AnswerValue[];
24
+ /**
25
+ * Instantiate Answer class with the provided options indices. Number
26
+ * of votes will be set to 1 for all options
27
+ *
28
+ * @example
29
+ * ```javascript
30
+ * // user votes for the first and fourth options
31
+ * const answer = Answer.fromIndices([0, 3]);
32
+ * ```
33
+ *
34
+ * @param indices - The array of option indices
35
+ */
36
+ static fromIndices(indices: number[]): Answer;
37
+ /**
38
+ * Adds a vote for the provided option index
39
+ *
40
+ * @param option - The index of the option, starting with 0
41
+ * @param value - The number of votes that will be placed against the option
42
+ */
43
+ set(option: number, value: number): Answer;
44
+ /**
45
+ * Removes the vote for the provided option index
46
+ *
47
+ * @param option - The index of the option, starting with 0
48
+ */
49
+ remove(option: number): Answer;
50
+ /** @internal */
51
+ toJSON(): AnswerValue[];
52
+ /** @internal */
53
+ static fromJSON(value: string): Answer;
54
+ }
55
+
56
+ /**
57
+ * Submits an Element answer as a spread of options indices
58
+ *
59
+ * @example
60
+ * ```javascript
61
+ * // vote for the first and third options
62
+ * answer(element, 0, 2);
63
+ * ```
64
+ *
65
+ * @param element - An Element instance
66
+ * @param indices - Spread of options indices (starting with 0) to vote for
67
+ */
68
+ export declare function answer(element: InteractElement, ...indices: number[]): void;
69
+
70
+ /**
71
+ * Submits an Element answer as an array of options indices
72
+ *
73
+ * @example
74
+ * ```javascript
75
+ * // vote for the first and third options
76
+ * answer(element, [0, 2]);
77
+ * ```
78
+ *
79
+ * @param element - An Element instance
80
+ * @param arrayOfIndices - Array of options indices (starting with 0) to vote for
81
+ */
82
+ export declare function answer(element: InteractElement, arrayOfIndices: number[]): void;
83
+
84
+ /**
85
+ * Submits an Element answer as a spread of answer values
86
+ *
87
+ * @example
88
+ * ```javascript
89
+ * // vote for the first and third options
90
+ * answer(element,
91
+ * {option: 0, value: 1},
92
+ * {option: 2, value: 1},
93
+ * );
94
+ * ```
95
+ *
96
+ * @param element - An Element instance
97
+ * @param answerValues - Spread of answer values to vote for
98
+ */
99
+ export declare function answer(element: InteractElement, ...answerValues: AnswerValue[]): void;
100
+
101
+ /**
102
+ * Submits an Element answer as an array of answer values
103
+ *
104
+ * @example
105
+ * ```javascript
106
+ * // vote for the first and third options
107
+ * answer(element, [
108
+ * {option: 0, value: 1},
109
+ * {option: 2, value: 1},
110
+ * ]);
111
+ * ```
112
+ *
113
+ * @param element - An Element instance
114
+ * @param arrayOfAnswerValues - Array of answer values to vote for
115
+ */
116
+ export declare function answer(element: InteractElement, arrayOfAnswerValues: AnswerValue[]): void;
117
+
118
+ /**
119
+ * Submits an Element answer as an Answer instance
120
+ *
121
+ * @example
122
+ * ```javascript
123
+ * // vote for the first and third options
124
+ * const value = new Answer();
125
+ * value.set(0, 1);
126
+ * value.set(2, 1);
127
+ *
128
+ * answer(element, value);
129
+ * ```
130
+ *
131
+ * @param element - An Element instance
132
+ * @param answerObject - Array of answer values to vote for
133
+ */
134
+ export declare function answer(element: InteractElement, answerObject: Answer): void;
135
+
136
+ /**
137
+ * A map of potential error codes to compare with errors thrown by
138
+ * vote() or validateAnswer() functions.
139
+ */
140
+ export declare enum AnswerError {
141
+ /** Selected option index is out of range. */
142
+ OptionIndexOutOfRange = "out_of_range",
143
+ /** Fewer options selected than the minimum required. */
144
+ BelowMinVoteOptions = "below_min_vote_options",
145
+ /** More options selected than the maximum allowed. */
146
+ AboveMaxVoteOptions = "above_max_vote_options",
147
+ /** User has exceeded the maximum votes allowed. */
148
+ AboveMaxVotesPerUser = "above_max_per_user",
149
+ /** A single option received more votes than allowed. */
150
+ AboveMaxVotesPerOption = "above_max_per_option",
151
+ /** Attempted to vote on a non-interactive element. */
152
+ VotedOnNonInteractiveElement = "non_interactive_element",
153
+ /** Attempted to vote on a closed element. */
154
+ VotedOnClosedElement = "closed_element",
155
+ /** No vote value was provided. */
156
+ EmptyVote = "empty_vote"
157
+ }
158
+
159
+ /**
160
+ * @license
161
+ * @monterosa/sdk-interact-kit
162
+ *
163
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
164
+ *
165
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
166
+ */
167
+ /**
168
+ * Declares a user answer object interface. Answer value is a single item of
169
+ * {@link Answer | answer instance}
170
+ */
171
+ export declare interface AnswerValue {
172
+ /**
173
+ * The option index (starting with 0)
174
+ */
175
+ option: number;
176
+ /**
177
+ * The number of votes that will be placed against the option
178
+ */
179
+ value: number;
180
+ }
181
+
182
+ /**
183
+ * @internal
184
+ */
185
+ export declare enum Channel {
186
+ Poll = "p",
187
+ Live = "l"
188
+ }
189
+
190
+ /**
191
+ * @internal
192
+ */
193
+ export declare interface Connect extends Emitter {
194
+ state: State;
195
+ enmasse: Connect_2 | null;
196
+ init(): Promise<void>;
197
+ connect(): Promise<void>;
198
+ disconnect(): void;
199
+ subscribeProject(id: string): Promise<void>;
200
+ subscribeEvent(id: string): Promise<void>;
201
+ unsubscribeProject(id: string): void;
202
+ unsubscribeEvent(id: string): void;
203
+ sendVote(eventId: string, pollId: number, answer: string): void;
204
+ }
205
+
206
+ /**
207
+ * `ConnectionHealth` monitors connection state
208
+ */
209
+ export declare interface ConnectionHealth extends Emitter {
210
+ /**
211
+ * State of the connection
212
+ */
213
+ state: ConnectionHealthState;
214
+ }
215
+
216
+ /**
217
+ * Provides states of the connection health
218
+ */
219
+ export declare enum ConnectionHealthState {
220
+ /**
221
+ * The client is connected and the connection is healthy
222
+ */
223
+ Ok = "ok",
224
+ /**
225
+ * The client is either trying to establish a connection but failing, or
226
+ * the client has been explicitly {@link @monterosa/sdk-connect-kit#disconnect() | disconnected}
227
+ */
228
+ Error = "error"
229
+ }
230
+
231
+ declare interface ElementContext {
232
+ sdk: MonterosaSdk;
233
+ project: InteractProject;
234
+ event: InteractEvent;
235
+ }
236
+
237
+ /**
238
+ * @internal
239
+ */
240
+ export declare class ElementImpl extends Emitter implements InteractElement {
241
+ private _data;
242
+ private _context;
243
+ private _state;
244
+ private _results;
245
+ private _userAnswer;
246
+ private _correctOption;
247
+ private unsubscribeStateHandler;
248
+ constructor(data: ElementOptions, context: ElementContext);
249
+ private calculateState;
250
+ private handleState;
251
+ update(data: ElementOptions): void;
252
+ destroy(): void;
253
+ get context(): ElementContext;
254
+ get id(): string;
255
+ get eventId(): string;
256
+ get state(): ElementState;
257
+ get type(): ElementType;
258
+ get contentType(): string;
259
+ get publishedAt(): number;
260
+ get publishedAtIso(): string;
261
+ get updatedAt(): number;
262
+ get updatedAtIso(): string;
263
+ get duration(): number;
264
+ get fields(): Record<string, unknown>;
265
+ get interactive(): boolean;
266
+ get pollId(): number | null;
267
+ get question(): Record<string, unknown> | null;
268
+ get answerOptions(): Record<string, unknown>[] | null;
269
+ get minOptionsPerVote(): number;
270
+ get maxOptionsPerVote(): number;
271
+ get maxVotesPerOption(): number;
272
+ get maxVotesPerUser(): number | null;
273
+ get userAnswer(): Answer | null;
274
+ set userAnswer(value: Answer | null);
275
+ get hasBeenAnswered(): boolean;
276
+ get showResultsMode(): ShowResultsMode | null;
277
+ get canShowResults(): boolean;
278
+ get results(): ElementResult[] | null;
279
+ set results(results: ElementResult[] | null);
280
+ get correctOption(): number | null;
281
+ set correctOption(value: number | null);
282
+ get isCorrectOptionRevealed(): boolean;
283
+ }
284
+
285
+ declare interface ElementOptions {
286
+ id: string;
287
+ type: ElementType;
288
+ content_type: string;
289
+ fixed: boolean;
290
+ published_at: number;
291
+ published_at_iso: string;
292
+ updated_at: number;
293
+ updated_at_iso: string;
294
+ duration: number;
295
+ custom_fields: Localised<Record<string, unknown>>;
296
+ data: {
297
+ id?: number;
298
+ question?: Localised<Record<string, unknown>>;
299
+ options?: Localised<Record<string, unknown>[]>;
300
+ min_options_per_vote?: number;
301
+ max_options_per_vote?: number;
302
+ max_votes_per_option?: number;
303
+ max_votes_per_user?: number;
304
+ reveal_results_mode?: ShowResultsMode;
305
+ results?: ElementResult[];
306
+ correct_option?: number;
307
+ };
308
+ }
309
+
310
+ /**
311
+ * A dataset that describes the result for a single option
312
+ */
313
+ export declare interface ElementResult {
314
+ /**
315
+ * Total number of votes placed against the Element's option
316
+ */
317
+ votes: number;
318
+ /**
319
+ * Percentage of all votes
320
+ */
321
+ percentage: number;
322
+ }
323
+
324
+ /**
325
+ * The ElementState represents the potential states an Element is in.
326
+ */
327
+ export declare enum ElementState {
328
+ /**
329
+ * Element is opened and active. The user can vote if
330
+ * the Element is `interactive`
331
+ */
332
+ Opened = "opened",
333
+ /**
334
+ * Element is closed and the user can no longer vote for
335
+ * `interactive` Elements
336
+ */
337
+ Closed = "closed"
338
+ }
339
+
340
+ /**
341
+ * Describes Element types
342
+ */
343
+ export declare enum ElementType {
344
+ /**
345
+ * Data Element
346
+ */
347
+ Data = "data",
348
+ /**
349
+ * Poll Element
350
+ */
351
+ Poll = "poll",
352
+ /**
353
+ * Regular poll Element
354
+ */
355
+ RegularPoll = "rpoll",
356
+ /**
357
+ * Diametric poll Element
358
+ */
359
+ DiametricPoll = "dpoll",
360
+ /**
361
+ * Emoting poll Element
362
+ */
363
+ EmotingPoll = "emo",
364
+ /**
365
+ * Powerbar Element
366
+ */
367
+ Powerbar = "powerbar",
368
+ /**
369
+ * Prediction Element
370
+ */
371
+ Prediction = "prediction",
372
+ /**
373
+ * Trivia Element
374
+ */
375
+ Trivia = "trivia"
376
+ }
377
+
378
+ declare interface EventContext {
379
+ sdk: MonterosaSdk;
380
+ project: InteractProject;
381
+ }
382
+
383
+ declare interface EventHistory {
384
+ timeline: ElementOptions[];
385
+ config: EventOptions;
386
+ version: number;
387
+ }
388
+
389
+ /**
390
+ * @internal
391
+ */
392
+ export declare class EventImpl extends Emitter implements InteractEvent {
393
+ readonly _data: EventOptions;
394
+ private _context;
395
+ private _state;
396
+ private _internalState;
397
+ private _initState;
398
+ private _history;
399
+ private boundHandleState;
400
+ private boundHandleInternalState;
401
+ private boundHandleEventsUpdated;
402
+ private unsubscribeStateHandler;
403
+ private unsubscribeInternalStateHandler;
404
+ private unsubscribeListingsHandler;
405
+ constructor(data: EventOptions, context: EventContext);
406
+ private calculateState;
407
+ private calculateInternalState;
408
+ private handleState;
409
+ private handleInternalState;
410
+ private handleEventsUpdated;
411
+ /** @internal */
412
+ destroy(): void;
413
+ get context(): EventContext;
414
+ get id(): string;
415
+ get name(): string;
416
+ get startAt(): number;
417
+ get startAtIso(): string;
418
+ get endAt(): number;
419
+ get endAtIso(): string;
420
+ get duration(): number;
421
+ get fields(): Record<string, unknown>;
422
+ get state(): EventState;
423
+ get internalState(): EventState;
424
+ get initState(): InitState;
425
+ set initState(state: InitState);
426
+ get history(): EventHistory | null;
427
+ set history(value: EventHistory | null);
428
+ get canSubscribe(): boolean;
429
+ get canLoadHistory(): boolean;
430
+ }
431
+
432
+ declare interface EventOptions {
433
+ id: string;
434
+ name: string;
435
+ start_at: number;
436
+ start_at_iso: string;
437
+ end_at: number;
438
+ end_at_iso: string;
439
+ started: boolean;
440
+ custom_fields: Localised<Record<string, unknown>>;
441
+ extra_time: number;
442
+ on_demand_time: number;
443
+ duration: number;
444
+ original_duration: number;
445
+ digest: string;
446
+ }
447
+
448
+ /**
449
+ * Describes the Event state.
450
+ */
451
+ export declare enum EventState {
452
+ /**
453
+ * The Event is in the `upcoming` state when its {@link InteractEvent | startAt}
454
+ * less than the {@link @monterosa/sdk-util#now | current time}.
455
+ */
456
+ Upcoming = "upcoming",
457
+ /**
458
+ * The Event is in the `active` state when its {@link InteractEvent | startAt}
459
+ * equal or more than the {@link @monterosa/sdk-util#now | current time} and less than the
460
+ * {@link InteractEvent | endAt}.
461
+ */
462
+ Active = "active",
463
+ /**
464
+ * @internal
465
+ */
466
+ Prolonged = "prolonged",
467
+ /**
468
+ * The Event is in the `finished` state when its {@link InteractEvent | endAt}
469
+ * equal or more than the {@link @monterosa/sdk-util#now | current time}.
470
+ */
471
+ Finished = "finished"
472
+ }
473
+
474
+ /**
475
+ * Describes an extension asset
476
+ */
477
+ export declare interface ExtensionAsset {
478
+ /**
479
+ * Extension's unique name
480
+ */
481
+ name: string;
482
+ /**
483
+ * An arbitrary data (e.g. url or extension-specific value)
484
+ */
485
+ data: string;
486
+ /**
487
+ * Defines autoload behaviour
488
+ *
489
+ * @remarks
490
+ * - when `js` is set, JS script from the URL in `data` will be injected
491
+ *
492
+ * - when `css` is set, CSS file from the URL in `data` will be injected
493
+ *
494
+ * - when `false` is set, a developer can decide on their own how to handle it
495
+ */
496
+ autoload?: 'js' | 'css' | false;
497
+ }
498
+
499
+ /**
500
+ * @internal
501
+ */
502
+ export declare function getConnect(host: string): Promise<Connect>;
503
+
504
+ /**
505
+ * Returns {@link ConnectionHealth | connection health} instance
506
+ *
507
+ * @param sdk - The SDK instance to monitor
508
+ * @returns The connection health instance.
509
+ */
510
+ export declare function getConnectionHealth(sdk?: MonterosaSdk): Promise<ConnectionHealth>;
511
+
512
+ /**
513
+ * Returns an Element of a specific Event by its id.
514
+ *
515
+ * @param event - The Event that owns the Element
516
+ * @param id - The Element identifier
517
+ */
518
+ export declare function getElement(event: InteractEvent, id: string): Promise<InteractElement | null>;
519
+
520
+ /**
521
+ * @internal
522
+ */
523
+ export declare const getElementMemoized: (...args: any[]) => Promise<InteractElement | null>;
524
+
525
+ /**
526
+ * Returns the list of Elements published in a specific Event
527
+ *
528
+ * @param event - The Event to fetch Elements for
529
+ * @returns The published Elements, sorted oldest first.
530
+ */
531
+ export declare function getElements(event: InteractEvent): Promise<InteractElement[]>;
532
+
533
+ /**
534
+ * @internal
535
+ */
536
+ export declare const getElementsMemoized: (...args: any[]) => Promise<InteractElement[]>;
537
+
538
+ /**
539
+ * Returns an Event by its id
540
+ *
541
+ * @param id - Id of the Event
542
+ * @param project - A Project instance. If not provided,
543
+ * the one from the default SDK will be fetched.
544
+ *
545
+ * @returns The Event associated with the provided id,
546
+ * or null if no such Event exists in the Project.
547
+ */
548
+ export declare function getEvent(id: string, project?: InteractProject): Promise<InteractEvent | null>;
549
+
550
+ /**
551
+ * @internal
552
+ */
553
+ export declare const getEventMemoized: (...args: any[]) => Promise<InteractEvent | null>;
554
+
555
+ /**
556
+ * Returns all Events in a Project, including all active Events and
557
+ * past/upcoming Events, according to Listings settings in Project Setup
558
+ * in Studio.
559
+ *
560
+ * @param project - A Project instance. If not provided,
561
+ * the one from the default SDK will be fetched.
562
+ * @returns A promise that resolves to an array of Events.
563
+ */
564
+ export declare function getEvents(project?: InteractProject): Promise<InteractEvent[]>;
565
+
566
+ /**
567
+ * @internal
568
+ */
569
+ export declare const getEventsMemoized: (...args: any[]) => Promise<InteractEvent[]>;
570
+
571
+ export declare function getPresenceCounter(project?: InteractProject): Promise<PresenceCounter>;
572
+
573
+ /**
574
+ * Returns {@link InteractProject | Project instance} associated
575
+ * with the
576
+ * {@link @monterosa/sdk-core#MonterosaSdk | configured SDK}
577
+ *
578
+ * @param sdk - The SDK instance. Defaults to the default SDK.
579
+ * @returns The Project instance.
580
+ */
581
+ export declare function getProject(sdk?: MonterosaSdk): Promise<InteractProject>;
582
+
583
+ /**
584
+ * @internal
585
+ */
586
+ export declare const getProjectMemoized: (...args: any[]) => Promise<InteractProject>;
587
+
588
+ declare enum InitState {
589
+ Uninitialised = "uninitialised",
590
+ Initialising = "initialising",
591
+ Initialised = "initialised"
592
+ }
593
+
594
+ /**
595
+ * Represents an interactive Element such as a poll,
596
+ * prediction, or trivia question. Obtain via
597
+ * {@link getElements} or {@link getElement}.
598
+ *
599
+ * @remarks
600
+ * Elements are interactive components with configuration
601
+ * fields such as duration, publish time, question, answers,
602
+ * etc. Developers can add custom fields of various
603
+ * types via the
604
+ * {@link https://products.monterosa.co/mic/developer-guides/app-spec/elements-spec | app's Element spec}.
605
+ *
606
+ * Elements are triggered to appear at a certain time and
607
+ * process both the appearance of the content, the way it
608
+ * behaves, and the data sent back from the audience.
609
+ *
610
+ * See {@link https://products.monterosa.co/mic/core-concepts/elements | Elements} in
611
+ * the platform documentation for more details.
612
+ */
613
+ export declare interface InteractElement extends Emitter {
614
+ /**
615
+ * Element uuid.
616
+ */
617
+ id: string;
618
+ /**
619
+ * Element state
620
+ */
621
+ state: ElementState;
622
+ /**
623
+ * Basic type of the Element
624
+ */
625
+ type: ElementType;
626
+ /**
627
+ * Returns `content type` of a custom Element if any is set in
628
+ * the Element spec. Otherwise returns the basic `type`.
629
+ */
630
+ contentType: ElementType | string;
631
+ /**
632
+ * Returns the Element publish time as UNIX time in seconds.
633
+ */
634
+ publishedAt: number;
635
+ /**
636
+ * Returns the Element publish time as ISO string.
637
+ */
638
+ publishedAtIso: string;
639
+ /**
640
+ * Returns the Element update as UNIX time in seconds.
641
+ */
642
+ updatedAt: number;
643
+ /**
644
+ * Returns the Element update time as ISO string.
645
+ */
646
+ updatedAtIso: string;
647
+ /**
648
+ * Returns the total duration in seconds of the Element.
649
+ */
650
+ duration: number;
651
+ /**
652
+ * Studio supports custom fields within Elements. This returns an object
653
+ * populated with the custom fields. Object property names will match keys
654
+ * as provided as part of custom fields definition in the feed and values
655
+ * will be as collected by Studio.
656
+ *
657
+ * @example
658
+ * ```javascript
659
+ * // {
660
+ * // "name": "Canis lupus",
661
+ * // "family": "Canidae",
662
+ * // ...
663
+ * // "species": "C. lupus"
664
+ * // }
665
+ * ```
666
+ */
667
+ fields: Record<string, unknown>;
668
+ /**
669
+ * Returns `true` if the user can vote for the Element
670
+ */
671
+ interactive: boolean;
672
+ /**
673
+ * Returns the question object
674
+ *
675
+ * @example
676
+ * ```javascript
677
+ * {
678
+ * text: "Mumford and Sons is an internationally-famous what?",
679
+ * imageUrl: '//path/to/my/question-image'
680
+ * }
681
+ * ```
682
+ */
683
+ question: Record<string, unknown> | null;
684
+ /**
685
+ * Returns a set of options
686
+ *
687
+ * @example
688
+ * ```javascript
689
+ * [{
690
+ * text: "Option 1",
691
+ * imageUrl: '//path/to/my/image1'
692
+ * },
693
+ * {
694
+ * text: "Option 2",
695
+ * imageUrl: '//path/to/my/image2'
696
+ * }]
697
+ * ```
698
+ */
699
+ answerOptions: Record<string, unknown>[] | null;
700
+ /**
701
+ * Returns the minimum number of options user can vote for.
702
+ */
703
+ minOptionsPerVote: number | null;
704
+ /**
705
+ * Returns the maximum number of options user can vote for.
706
+ */
707
+ maxOptionsPerVote: number | null;
708
+ /**
709
+ * Returns maximum number of votes a user can cast per option.
710
+ */
711
+ maxVotesPerOption: number | null;
712
+ /**
713
+ * Returns maximum number of votes a user can cast.
714
+ */
715
+ maxVotesPerUser: number | null;
716
+ /**
717
+ * Returns Element results if they exist. Otherwise, returns `null`.
718
+ *
719
+ * @example
720
+ * ```javascript
721
+ * [
722
+ * {
723
+ * votes: 15,
724
+ * percentage: 75
725
+ * },
726
+ * {
727
+ * votes: 5,
728
+ * percentage: 25
729
+ * }
730
+ * ]
731
+ * ```
732
+ */
733
+ results: ElementResult[] | null;
734
+ /**
735
+ * Returns user answer object
736
+ */
737
+ userAnswer: Answer | null;
738
+ /**
739
+ * Returns correct option index (starting with 0) if the correct answer has
740
+ * already been revealed. Otherwise, returns `null`.
741
+ *
742
+ * Note that the correct answer reveal is different from the results reveal.
743
+ */
744
+ correctOption: number | null;
745
+ /** @internal */
746
+ pollId: number | null;
747
+ /** @internal */
748
+ showResultsMode: ShowResultsMode | null;
749
+ /**
750
+ * Returns `true` if results present and the state of the Element satisfies
751
+ * reveal mode. Otherwise, returns `false`.
752
+ */
753
+ canShowResults: boolean;
754
+ /**
755
+ * Returns `true` if the user voted and `false` if not. The user answer
756
+ * could be retrieved by calling {@link InteractElement | userAnswer} getter.
757
+ */
758
+ hasBeenAnswered: boolean;
759
+ /**
760
+ * Returns `true` if the correct option has already been revealed.
761
+ */
762
+ isCorrectOptionRevealed: boolean;
763
+ /** @internal */
764
+ context: ElementContext;
765
+ /** @internal */
766
+ eventId: string;
767
+ /** @internal */
768
+ update(options: ElementOptions): void;
769
+ /** @internal */
770
+ destroy(): void;
771
+ }
772
+
773
+ /**
774
+ * Represents an Event, a time-bound period of
775
+ * interactivity. Obtain via {@link getEvent} or
776
+ * {@link getEvents}.
777
+ *
778
+ * @remarks
779
+ * Events represent a sports game, TV show, or any period of time in which you
780
+ * want to push interactivity to users. Each Event has a duration, start time,
781
+ * start mode, and
782
+ * {@link https://products.monterosa.co/mic/developer-guides/app-spec/event-settings-spec | custom fields}
783
+ * that can be configured by developers.
784
+ *
785
+ * See {@link https://products.monterosa.co/mic/core-concepts/schedule-and-events | Events} in
786
+ * the platform documentation for more details.
787
+ */
788
+ export declare interface InteractEvent extends Emitter {
789
+ /**
790
+ * Event uuid.
791
+ */
792
+ id: string;
793
+ /**
794
+ * Event name.
795
+ */
796
+ name: string;
797
+ /**
798
+ * Returns the Event start time as UNIX time in seconds.
799
+ */
800
+ startAt: number;
801
+ /**
802
+ * Returns the Event start time as ISO string.
803
+ */
804
+ startAtIso: string;
805
+ /**
806
+ * Returns the Event end time as UNIX time in seconds.
807
+ */
808
+ endAt: number;
809
+ /**
810
+ * Returns the Event end time as ISO string.
811
+ */
812
+ endAtIso: string;
813
+ /**
814
+ * Studio supports custom fields within an Event. This returns an object
815
+ * populated with the custom fields. Object property names will match keys
816
+ * as provided as part of custom fields definition in the feed and values
817
+ * will be as collected by Studio.
818
+ *
819
+ * @example
820
+ * ```javascript
821
+ * // {
822
+ * // "name": "Canis lupus",
823
+ * // "family": "Canidae",
824
+ * // ...
825
+ * // "species": "C. lupus"
826
+ * // }
827
+ * ```
828
+ */
829
+ fields: Record<string, unknown>;
830
+ /**
831
+ * Event state
832
+ */
833
+ state: EventState;
834
+ /**
835
+ * Returns the total duration in seconds of the Event.
836
+ */
837
+ duration: number;
838
+ /** @internal */
839
+ canSubscribe: boolean;
840
+ /** @internal */
841
+ canLoadHistory: boolean;
842
+ /** @internal */
843
+ internalState: EventState;
844
+ /** @internal */
845
+ initState: InitState;
846
+ /** @internal */
847
+ context: EventContext;
848
+ /** @internal */
849
+ history: EventHistory | null;
850
+ /** @internal */
851
+ destroy(): void;
852
+ }
853
+
854
+ /**
855
+ * Represents a Project, a container for configuration,
856
+ * theming, and Events. Obtain via {@link getProject}.
857
+ *
858
+ * @remarks
859
+ * Every Project in Studio has an id, host, embedUrl, and a set of fields
860
+ * associated with an
861
+ * {@link https://products.monterosa.co/mic/developer-guides/whats-an-app | App}.
862
+ * Project fields are
863
+ * {@link https://products.monterosa.co/mic/producer-guide/studio/app-setup | configuration options}
864
+ * created by the
865
+ * {@link https://products.monterosa.co/mic/developer-guides/app-spec/project-settings-spec | app developer}
866
+ * and vary from App to App.
867
+ *
868
+ * See {@link https://products.monterosa.co/mic/core-concepts | Projects} in
869
+ * the platform documentation for more details.
870
+ */
871
+ export declare interface InteractProject extends MonterosaKit, Emitter {
872
+ /**
873
+ * Project uuid.
874
+ */
875
+ id: string;
876
+ /**
877
+ * Project static host.
878
+ */
879
+ host: string;
880
+ /**
881
+ * Project embed url.
882
+ */
883
+ embedUrl: string;
884
+ /**
885
+ * Returns `true` if the Project supports localisation.
886
+ */
887
+ isLocalisationSupported: boolean;
888
+ /**
889
+ * The list of available locales as configured in Studio
890
+ */
891
+ locales: string[];
892
+ /**
893
+ * Project locale
894
+ */
895
+ locale: string;
896
+ /**
897
+ * Monterosa / Interaction Cloud supports custom fields within a Project.
898
+ * This returns an object populated with the custom fields. Object property
899
+ * names will match keys as provided as part of custom fields definition in
900
+ * the feed and values will be as collected by Studio.
901
+ *
902
+ * @example
903
+ * ```javascript
904
+ * // {
905
+ * // "name": "Canis lupus",
906
+ * // "family": "Canidae",
907
+ * // ...
908
+ * // "species": "C. lupus"
909
+ * // }
910
+ * ```
911
+ */
912
+ fields: Record<string, unknown>;
913
+ /**
914
+ * https://products.monterosa.co/mic/extensions/overview
915
+ * Monterosa / Interaction Cloud functionality can be extended with
916
+ * {@link https://products.monterosa.co/mic/extensions/overview | extensions}
917
+ * without changing the core platform codebase. An Extension can visually integrate
918
+ * into Studio, aid data collection for a Creator and provide data for the App
919
+ * and feeds. Extension can provide assets which Studio passes to the App. Sdk can
920
+ * fetch assets and provide it for the developers.
921
+ *
922
+ * @example
923
+ * ```
924
+ * {
925
+ * "extension-name": [
926
+ * {
927
+ * "name": "js asset",
928
+ * "data": "http://example.com/asset.js",
929
+ * "autoload": "js"
930
+ * },
931
+ * {
932
+ * "name": "css asset",
933
+ * "data": "http://example.com/asset.css",
934
+ * "autoload": "css"
935
+ * }
936
+ * ]
937
+ * }
938
+ * ```
939
+ */
940
+ extensions: Record<string, ExtensionAsset[]>;
941
+ /** @internal */
942
+ eventsChecksum: string | null;
943
+ /** @internal */
944
+ context: ProjectContext;
945
+ /** @internal */
946
+ events: EventOptions[];
947
+ /** @internal */
948
+ listings: Listings;
949
+ /** @internal */
950
+ historyIgnore: number;
951
+ /** @internal */
952
+ delete(): void;
953
+ }
954
+
955
+ /**
956
+ * @internal
957
+ */
958
+ export declare enum Klass {
959
+ Listings = "listings",
960
+ History = "history",
961
+ Create = "create",
962
+ Revoke = "revoke",
963
+ Stop = "stop",
964
+ Reveal = "reveal",
965
+ Poll = "p",
966
+ Feedback = "fb",
967
+ Eoc = "eoc",
968
+ Vote = "v",
969
+ SubsCounter = "subscounter"
970
+ }
971
+
972
+ declare interface Listings {
973
+ project: {
974
+ uuid: string;
975
+ embed: string;
976
+ app_settings: string;
977
+ app_settings_digest: string;
978
+ audio_sync_default_delay: number;
979
+ audio_sync_max_delay: number;
980
+ history_ignore: number;
981
+ is_localisation_supported: boolean;
982
+ locales: ProjectLocale[];
983
+ };
984
+ events: EventOptions[];
985
+ assets: Record<string, ExtensionAsset[]>;
986
+ }
987
+
988
+ declare interface Localised<T> {
989
+ [lang: string]: T;
990
+ all: T;
991
+ }
992
+
993
+ /**
994
+ * @internal
995
+ */
996
+ export declare interface Message {
997
+ id: string;
998
+ klass: Klass;
999
+ data: string[];
1000
+ }
1001
+
1002
+ /**
1003
+ * Adds an observer for when
1004
+ * {@link ConnectionHealth | connection health state} changed
1005
+ *
1006
+ * @param connectionHealth - The instance to observe
1007
+ * @param callback - Called with the new state
1008
+ */
1009
+ export declare function onConnectionHealthState(connectionHealth: ConnectionHealth, callback: (state: ConnectionHealthState) => void): Unsubscribe;
1010
+
1011
+ /**
1012
+ * Adds an observer for when a new Element is published
1013
+ *
1014
+ * @param event - The Event to observe
1015
+ * @param callback - Called with the published Element
1016
+ */
1017
+ export declare function onElementPublished(event: InteractEvent, callback: (element: InteractElement) => void): Unsubscribe;
1018
+
1019
+ /**
1020
+ * Adds an observer for when
1021
+ * {@link InteractElement | Element results} are updated
1022
+ *
1023
+ * @param element - The Element to observe
1024
+ * @param callback - Called when results are updated
1025
+ */
1026
+ export declare function onElementResults(element: InteractElement, callback: () => void): Unsubscribe;
1027
+
1028
+ /**
1029
+ * Adds an observer for when an Element is revoked
1030
+ *
1031
+ * @param event - The Event to observe
1032
+ * @param callback - Called with the revoked Element
1033
+ */
1034
+ export declare function onElementRevoked(event: InteractEvent, callback: (element: InteractElement) => void): Unsubscribe;
1035
+
1036
+ /**
1037
+ * Adds an observer for when
1038
+ * {@link InteractElement | Element state} changed
1039
+ *
1040
+ * @param element - The Element to observe
1041
+ * @param callback - Called when the state changes
1042
+ */
1043
+ export declare function onElementStateChanged(element: InteractElement, callback: () => void): Unsubscribe;
1044
+
1045
+ /**
1046
+ * Adds an observer for when
1047
+ * {@link InteractElement | Element fields} are updated
1048
+ *
1049
+ * @param event - The Event containing the Elements
1050
+ * @param callback - Called with the updated Element
1051
+ */
1052
+ export declare function onElementUpdated(event: InteractEvent, callback: (element: InteractElement) => void): Unsubscribe;
1053
+
1054
+ /**
1055
+ * Adds an observer that is called when an Event is added to listings.
1056
+ *
1057
+ * @remarks
1058
+ * The following actions will result in adding an Event to listings:
1059
+ *
1060
+ * - The start of the Event in Studio
1061
+ *
1062
+ * - The scheduling of a future Event in Studio, when listings are configured
1063
+ * to include future Events in Project Settings.
1064
+ *
1065
+ * - When a future Event starts, a new future Event may be added to the list,
1066
+ * depending on the Project configuration, to ensure a minimum number of
1067
+ * upcoming Events are always available.
1068
+ *
1069
+ * @param project - The Project to observe
1070
+ * @param callback - Called with the added Event
1071
+ */
1072
+ export declare function onEventAdded(project: InteractProject, callback: (event: InteractEvent) => void): Unsubscribe;
1073
+
1074
+ /**
1075
+ * Adds an observer that is called when an Event is removed from listings.
1076
+ *
1077
+ * @remarks
1078
+ * The following actions will result in removing an Event from listings:
1079
+ *
1080
+ * - The deletion of the Event from Studio
1081
+ *
1082
+ * - The change of listings configuration in Project Settings to exclude future
1083
+ * or past Events.
1084
+ *
1085
+ * - The Event is removed after a period of time since its completion. This period
1086
+ * is calculated as 45 seconds plus the Maximum allowed delay (configured in
1087
+ * Project Settings in Studio).
1088
+ *
1089
+ * @param project - The Project to observe
1090
+ * @param callback - Called with the removed Event
1091
+ */
1092
+ export declare function onEventRemoved(project: InteractProject, callback: (event: InteractEvent) => void): Unsubscribe;
1093
+
1094
+ /**
1095
+ * Adds an observer for when
1096
+ * {@link InteractEvent | Event state} changed
1097
+ *
1098
+ * @param event - The Event to observe
1099
+ * @param callback - Called with the new state
1100
+ */
1101
+ export declare function onEventState(event: InteractEvent, callback: (state: EventState) => void): Unsubscribe;
1102
+
1103
+ /**
1104
+ * Adds an observer for when Event's data changed
1105
+ *
1106
+ * @param event - The Event to observe
1107
+ * @param callback - Called when the Event data changes
1108
+ */
1109
+ export declare function onEventUpdated(event: InteractEvent, callback: () => void): Unsubscribe;
1110
+
1111
+ export declare function onPresenceCounterClose(presenceCounter: PresenceCounter, callback: () => void): Unsubscribe;
1112
+
1113
+ export declare function onPresenceCounterOpen(presenceCounter: PresenceCounter, callback: () => void): Unsubscribe;
1114
+
1115
+ export declare function onPresenceCounterUpdate(presenceCounter: PresenceCounter, callback: (count: number) => void): Unsubscribe;
1116
+
1117
+ /**
1118
+ * Adds an observer for when
1119
+ * {@link InteractProject | Project fields} are updated
1120
+ *
1121
+ * @param project - The Project to observe
1122
+ * @param callback - Called when Project fields change
1123
+ */
1124
+ export declare function onProjectFieldsUpdated(project: InteractProject, callback: () => void): Unsubscribe;
1125
+
1126
+ export declare interface PresenceCounter extends Emitter {
1127
+ readonly isOpened: boolean;
1128
+ readonly lastCount: number;
1129
+ }
1130
+
1131
+ export declare enum PresenceCounterState {
1132
+ Opened = "opened",
1133
+ Closed = "closed"
1134
+ }
1135
+
1136
+ declare interface ProjectContext {
1137
+ sdk: MonterosaSdk;
1138
+ }
1139
+
1140
+ /**
1141
+ * @internal
1142
+ */
1143
+ export declare class ProjectImpl extends Emitter implements InteractProject {
1144
+ host: string;
1145
+ id: string;
1146
+ eventsChecksum: string | null;
1147
+ private _context;
1148
+ private _listings;
1149
+ private _fields;
1150
+ private _locales;
1151
+ private _locale;
1152
+ constructor(options: ProjectOptions, context: ProjectContext);
1153
+ get context(): ProjectContext;
1154
+ get embedUrl(): string;
1155
+ get uuid(): string;
1156
+ get events(): EventOptions[];
1157
+ get listings(): Listings;
1158
+ set listings(newListings: Listings);
1159
+ /**
1160
+ * Calculates events that were created (present in new listings but not in old)
1161
+ */
1162
+ private _calculateCreatedEvents;
1163
+ /**
1164
+ * Calculates events that were updated (present in old listings and new,
1165
+ * but with different digest)
1166
+ */
1167
+ private _calculateUpdatedEvents;
1168
+ /**
1169
+ * Calculates events that were deleted (present in old listings but not in new)
1170
+ */
1171
+ private _calculateDeletedEvents;
1172
+ /**
1173
+ * Processes and updates locales from project listings
1174
+ */
1175
+ private _updateLocales;
1176
+ /**
1177
+ * Updates the events checksum based on new listings
1178
+ */
1179
+ private _updateEventsChecksum;
1180
+ /**
1181
+ * Emits events based on created and deleted events
1182
+ */
1183
+ private _emitListingsEvents;
1184
+ get isLocalisationSupported(): boolean;
1185
+ get locale(): string;
1186
+ set locale(locale: string);
1187
+ get locales(): string[];
1188
+ get fields(): Record<string, unknown>;
1189
+ /**
1190
+ * Sets custom fields
1191
+ *
1192
+ * It accepts both Localised<Record<string, unknown>> and Record<string, unknown> to
1193
+ * avoid mistyping between setter and getter
1194
+ *
1195
+ * @internal
1196
+ */
1197
+ set fields(value: Localised<Record<string, unknown>> | Record<string, unknown>);
1198
+ get extensions(): Record<string, ExtensionAsset[]>;
1199
+ get historyIgnore(): number;
1200
+ delete(): void;
1201
+ }
1202
+
1203
+ declare interface ProjectLocale {
1204
+ default: boolean;
1205
+ key: string;
1206
+ name: string;
1207
+ }
1208
+
1209
+ declare interface ProjectOptions {
1210
+ id: string;
1211
+ host: string;
1212
+ }
1213
+
1214
+ declare enum ShowResultsMode {
1215
+ OnVote = "vote",
1216
+ OnClose = "close",
1217
+ OnEventEnd = "event_end",
1218
+ Manual = "manual",
1219
+ Never = "never",
1220
+ Always = "always"
1221
+ }
1222
+
1223
+ /**
1224
+ * @internal
1225
+ */
1226
+ export declare enum State {
1227
+ Ok = "ok",
1228
+ Error = "error"
1229
+ }
1230
+
1231
+ /**
1232
+ * Validates user's answer as a spread of options indices and
1233
+ * throws {@link @monterosa/sdk-util#MonterosaError%20class | error} with one of the
1234
+ * {@link AnswerError | error code} if the answer doesn't match
1235
+ * Element's constraints
1236
+ *
1237
+ *
1238
+ * @example
1239
+ * ```javascript
1240
+ * try {
1241
+ * validateAnswer(element, 0, 2);
1242
+ * } catch (err) {
1243
+ * console.log(err);
1244
+ * }
1245
+ * ```
1246
+ *
1247
+ * @param element - An Element instance
1248
+ * @param indices - Spread of options indices (starting with 0) to vote for
1249
+ */
1250
+ export declare function validateAnswer(element: InteractElement, ...indices: number[]): void;
1251
+
1252
+ /**
1253
+ * Validates user's answer as an array of options indices and
1254
+ * throws {@link @monterosa/sdk-util#MonterosaError%20class | error} with one of the
1255
+ * {@link AnswerError | error code} if the answer doesn't match
1256
+ * Element's constraints
1257
+ *
1258
+ * @example
1259
+ * ```javascript
1260
+ * try {
1261
+ * validateAnswer(element, [0, 2]);
1262
+ * } catch (err) {
1263
+ * console.log(err);
1264
+ * }
1265
+ * ```
1266
+ *
1267
+ * @param element - An Element instance
1268
+ * @param arrayOfIndices - Array of options indices (starting with 0) to vote for
1269
+ */
1270
+ export declare function validateAnswer(element: InteractElement, arrayOfIndices: number[]): void;
1271
+
1272
+ /**
1273
+ * Validates user's answer as a spread of answer values and
1274
+ * throws {@link @monterosa/sdk-util#MonterosaError%20class | error} with one of the
1275
+ * {@link AnswerError | error code} if the answer doesn't match
1276
+ * Element's constraints
1277
+ *
1278
+ * @example
1279
+ * ```javascript
1280
+ * try {
1281
+ * validateAnswer(element,
1282
+ * {option: 0, value: 1},
1283
+ * {option: 2, value: 1},
1284
+ * );
1285
+ * } catch (err) {
1286
+ * console.log(err);
1287
+ * }
1288
+ * ```
1289
+ *
1290
+ * @param element - An Element instance
1291
+ * @param answerValues - Spread of answer values to vote for
1292
+ */
1293
+ export declare function validateAnswer(element: InteractElement, ...answerValues: AnswerValue[]): void;
1294
+
1295
+ /**
1296
+ * Validates user's answer as an array of answer values and
1297
+ * throws {@link @monterosa/sdk-util#MonterosaError%20class | error} with one of the
1298
+ * {@link AnswerError | error code} if the answer doesn't match
1299
+ * Element's constraints
1300
+ *
1301
+ * @example
1302
+ * ```javascript
1303
+ * try {
1304
+ * validateAnswer(element, [
1305
+ * {option: 0, value: 1},
1306
+ * {option: 2, value: 1},
1307
+ * ]);
1308
+ * } catch (err) {
1309
+ * console.log(err);
1310
+ * }
1311
+ * ```
1312
+ *
1313
+ * @param element - An Element instance
1314
+ * @param arrayOfAnswerValues - Array of answer values to vote for
1315
+ */
1316
+ export declare function validateAnswer(element: InteractElement, arrayOfAnswerValues: AnswerValue[]): void;
1317
+
1318
+ /**
1319
+ * Validates user's answer as an Answer instance and
1320
+ * throws {@link @monterosa/sdk-util#MonterosaError%20class | error} with one of the
1321
+ * {@link AnswerError | error code} if the answer doesn't match
1322
+ * Element's constraints
1323
+ *
1324
+ * @example
1325
+ * ```javascript
1326
+ * try {
1327
+ * const value = new Answer();
1328
+ * value.set(0, 1);
1329
+ * value.set(2, 1);
1330
+ *
1331
+ * validateAnswer(element, value);
1332
+ * } catch (err) {
1333
+ * console.log(err);
1334
+ * }
1335
+ * ```
1336
+ *
1337
+ * @param element - An Element instance
1338
+ * @param answerObject - Array of answer values to vote for
1339
+ */
1340
+ export declare function validateAnswer(element: InteractElement, answerObject: Answer): void;
1341
+
1342
+ export { }
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.23.0"
9
+ }
10
+ ]
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monterosa/sdk-interact-kit",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.0-rc.5",
4
4
  "description": "Monterosa JS SDK / Interact Kit",
5
5
  "author": "Monterosa Productions Limited <hello@monterosa.co.uk> (https://www.monterosa.co/)",
6
6
  "main": "./dist/index.cjs",
@@ -32,11 +32,11 @@
32
32
  ],
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "@monterosa/sdk-connect-kit": "2.0.0-rc.3",
36
- "@monterosa/sdk-core": "2.0.0-rc.3",
37
- "@monterosa/sdk-interact-interop": "2.0.0-rc.3",
38
- "@monterosa/sdk-storage-kit": "2.0.0-rc.3",
39
- "@monterosa/sdk-util": "2.0.0-rc.3"
35
+ "@monterosa/sdk-connect-kit": "2.0.0-rc.5",
36
+ "@monterosa/sdk-core": "2.0.0-rc.5",
37
+ "@monterosa/sdk-interact-interop": "2.0.0-rc.5",
38
+ "@monterosa/sdk-storage-kit": "2.0.0-rc.5",
39
+ "@monterosa/sdk-util": "2.0.0-rc.5"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@faker-js/faker": "^6.3.1",
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "access": "public"
60
60
  },
61
- "gitHead": "d692ad26af0b5ea7cd7b664168bffa069f9ab911"
61
+ "gitHead": "4f697a9733d36fb689a35b8e1dd6d589a9ae284c"
62
62
  }