@microsoft/live-share-media 1.0.0-preview.3 → 1.0.0-preview.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.
package/README.md CHANGED
@@ -112,11 +112,12 @@ The Live Share SDK contains dependencies for [@microsoft/teams-js](https://www.n
112
112
 
113
113
  **It is critical that your app use the package dependencies listed in the table below.** Lookup the version of the `@microsoft/live-share` you're using and set any other dependencies in your package.json file to match:
114
114
 
115
- | @microsoft/live-share | @microsoft/teams-js | fluid-framework | @microsoft/live-share-(media or canvas) | @fluidframework/azure-client | @microsoft/TeamsFx | @microsoft/TeamsFx-react |
116
- | --------------------- | -------------------- | --------------- | --------------------------- | ---------------------------- | ------------------------------- | ------------------------------- |
117
- | 1.0.0-preview.3 | 2.0.0-experimental.1 | ~1.2.3 | 1.0.0-preview.3 (optional) | ~1.0.2 (optional) | 2.0.0-experimental.0 (optional) | 2.0.0-experimental.0 (optional) |
118
- | ~0.5.1 | 2.0.0-experimental.1 | ~1.2.3 | ~0.5.1 (optional) | ~1.0.2 (optional) | 2.0.0-experimental.0 (optional) | 2.0.0-experimental.0 (optional) |
119
- | ~0.3.1 | 2.0.0-experimental.0 | ~0.59.0 | ~0.3.1 (optional) | ~0.59.0 (optional) | 2.0.0-experimental.0 (optional) | 2.0.0-experimental.0 (optional) |
115
+ | @microsoft/live-share | @microsoft/teams-js | fluid-framework | @microsoft/live-share-\* | @fluidframework/azure-client | @microsoft/TeamsFx | @microsoft/TeamsFx-react |
116
+ | --------------------- | -------------------- | --------------- | -------------------------- | ---------------------------- | ------------------------------- | ------------------------------- |
117
+ | 1.0.0-preview.5 | ^2.5.0 | ~1.2.3 | 1.0.0-preview.5 (optional) | ~1.0.2 (optional) | ^2.5.0 (optional) | ^2.5.0 (optional) |
118
+ | 1.0.0-preview.3 | 2.0.0-experimental.1 | ~1.2.3 | 1.0.0-preview.3 (optional) | ~1.0.2 (optional) | 2.0.0-experimental.0 (optional) | 2.0.0-experimental.0 (optional) |
119
+ | ~0.5.1 | 2.0.0-experimental.1 | ~1.2.3 | ~0.5.1 (optional) | ~1.0.2 (optional) | 2.0.0-experimental.0 (optional) | 2.0.0-experimental.0 (optional) |
120
+ | ~0.3.1 | 2.0.0-experimental.0 | ~0.59.0 | ~0.3.1 (optional) | ~0.59.0 (optional) | 2.0.0-experimental.0 (optional) | 2.0.0-experimental.0 (optional) |
120
121
 
121
122
  ## Contributing
122
123
 
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ import { DataObject, DataObjectFactory } from '@fluidframework/aqueduct';
6
+ import { EphemeralTelemetryLogger, UserMeetingRole } from '@microsoft/live-share';
7
+ import { MediaPlayerSynchronizer } from './MediaPlayerSynchronizer';
8
+ import { ExtendedMediaSessionAction } from './MediaSessionExtensions';
9
+ import { EphemeralMediaSessionCoordinator, IMediaPlayerState } from './EphemeralMediaSessionCoordinator';
10
+ import { MediaSessionActionThrottler } from './MediaSessionActionThrottler';
11
+ import { IMediaPlayer } from './IMediaPlayer';
12
+ /**
13
+ * Ephemeral fluid object that synchronizes media playback across multiple clients.
14
+ */
15
+ export declare class EphemeralMediaSession extends DataObject {
16
+ private _actionThrottler;
17
+ private _logger?;
18
+ private _requestPlayerStateHandler?;
19
+ private _coordinator?;
20
+ private readonly _actionHandlers;
21
+ private _synchronizing?;
22
+ private _updateTimer;
23
+ private _lastUpdateTime;
24
+ /**
25
+ * The objects fluid type name.
26
+ */
27
+ static readonly TypeName = "@microsoft/fluid-media:SharedMediaSession";
28
+ /**
29
+ * The objects fluid type factory.
30
+ */
31
+ static readonly factory: DataObjectFactory<EphemeralMediaSession, import("@fluidframework/aqueduct").DataObjectTypes>;
32
+ /**
33
+ * Extension point that lets applications replace the default logic for throttling the sessions
34
+ * local sync behavior.
35
+ *
36
+ * @remarks
37
+ * The `EphemeralMediaCoordinator` is fairly aggressive at wanting to keep the local media player
38
+ * in sync with the rest of the group. This aggressiveness can result in the coordinator sending
39
+ * new sync actions before the local player has finished responding to the previous sync action.
40
+ * The `ActionThrottler` gives apps fine grain control over how aggressive they want sync to be.
41
+ *
42
+ * By default, a `RepeatedAction` throttler is used which prevents the same sync action from
43
+ * being sent within an adjustable time period.
44
+ */
45
+ get actionThrottler(): MediaSessionActionThrottler;
46
+ set actionThrottler(value: MediaSessionActionThrottler);
47
+ /**
48
+ * Returns true if the object has been initialized.
49
+ */
50
+ get isInitialized(): boolean;
51
+ /**
52
+ * @deprecated isInitialized should be used instead
53
+ * Returns true if the object has been initialized.
54
+ */
55
+ get isStarted(): boolean;
56
+ /**
57
+ * The group coordinator for the session.
58
+ */
59
+ get coordinator(): EphemeralMediaSessionCoordinator;
60
+ /**
61
+ * Returns the logger used by the session and coordinator.
62
+ *
63
+ * @remarks
64
+ * This is used by the `MediaPlayerSynchronizer` to log events.
65
+ */
66
+ get logger(): EphemeralTelemetryLogger;
67
+ /**
68
+ * initialize the object.
69
+ * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
70
+ * operations like play/pause/seek/setTrack.
71
+ */
72
+ initialize(acceptTransportChangesFrom?: UserMeetingRole[]): Promise<void>;
73
+ /**
74
+ * @deprecated initialize should be used instead
75
+ * initialize the object.
76
+ * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
77
+ * operations like play/pause/seek/setTrack.
78
+ */
79
+ start(acceptTransportChangesFrom?: UserMeetingRole[]): Promise<void>;
80
+ /**
81
+ * Registers an action handler with the session.
82
+ * @param action Name of the action to register a handler for.
83
+ * @param handler Function called when the action is triggered.
84
+ */
85
+ setActionHandler(action: ExtendedMediaSessionAction, handler: MediaSessionActionHandler | null): void;
86
+ /**
87
+ * Registers a handler that will be queried anytime the group coordinate needs to know the
88
+ * local players transport state and position.
89
+ */
90
+ setRequestPlayerStateHandler(handler: () => IMediaPlayerState): void;
91
+ /**
92
+ * Begins synchronizing the playback of a media element.
93
+ * @param player Something that "looks like" and HTML Media Element.
94
+ * @returns A new synchronizer instance. Call `synchronizer.end()` to stop synchronizing the elements playback.
95
+ */
96
+ synchronize(player: IMediaPlayer): MediaPlayerSynchronizer;
97
+ protected hasInitialized(): Promise<void>;
98
+ private checkWaitPointHit;
99
+ private getCurrentPlayerState;
100
+ private dispatchAction;
101
+ }
102
+ //# sourceMappingURL=EphemeralMediaSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EphemeralMediaSession.d.ts","sourceRoot":"","sources":["../src/EphemeralMediaSession.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAiC,0BAA0B,EAAqC,MAAM,0BAA0B,CAAC;AACxI,OAAO,EAAE,gCAAgC,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACF,qBAAa,qBAAsB,SAAQ,UAAU;IAClD,OAAO,CAAC,gBAAgB,CAA8D;IACtF,OAAO,CAAC,OAAO,CAAC,CAA2B;IAC3C,OAAO,CAAC,0BAA0B,CAAC,CAA0B;IAC7D,OAAO,CAAC,YAAY,CAAC,CAAmC;IACxD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqD;IACrF,OAAO,CAAC,cAAc,CAAC,CAA0B;IAGjD,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,eAAe,CAAa;IAEpC;;OAEG;IACF,gBAAuB,QAAQ,+CAA+C;IAE/E;;OAEG;IACF,gBAAuB,OAAO,+FAK7B;IAEF;;;;;;;;;;;;OAYG;IACH,IAAW,eAAe,IAAI,2BAA2B,CAExD;IAED,IAAW,eAAe,CAAC,KAAK,EAAE,2BAA2B,EAE5D;IAED;;OAEG;IACH,IAAW,aAAa,IAAI,OAAO,CAElC;IAED;;;OAGG;IACH,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED;;OAEG;IACH,IAAW,WAAW,IAAI,gCAAgC,CAEzD;IAED;;;;;OAKG;IACH,IAAW,MAAM,IAAI,wBAAwB,CAE5C;IAED;;;;OAIG;IACK,UAAU,CAAC,0BAA0B,CAAC,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjF;;;;;OAKG;IACI,KAAK,CAAC,0BAA0B,CAAC,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3E;;;;OAIG;IACI,gBAAgB,CAAC,MAAM,EAAE,0BAA0B,EAAE,OAAO,EAAE,yBAAyB,GAAG,IAAI,GAAG,IAAI;IAW5G;;;OAGG;IACI,4BAA4B,CAAC,OAAO,EAAE,MAAM,iBAAiB;IAIpE;;;;OAIG;IACI,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,uBAAuB;cA+BjD,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAuC/C,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,cAAc;CAMzB"}
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the Microsoft Live Share SDK License.
5
+ */
6
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
13
+ });
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.EphemeralMediaSession = void 0;
17
+ const aqueduct_1 = require("@fluidframework/aqueduct");
18
+ const live_share_1 = require("@microsoft/live-share");
19
+ const MediaPlayerSynchronizer_1 = require("./MediaPlayerSynchronizer");
20
+ const internals_1 = require("./internals");
21
+ const MediaSessionExtensions_1 = require("./MediaSessionExtensions");
22
+ const EphemeralMediaSessionCoordinator_1 = require("./EphemeralMediaSessionCoordinator");
23
+ const RepeatedActionThrottler_1 = require("./RepeatedActionThrottler");
24
+ /**
25
+ * Ephemeral fluid object that synchronizes media playback across multiple clients.
26
+ */
27
+ class EphemeralMediaSession extends aqueduct_1.DataObject {
28
+ constructor() {
29
+ super(...arguments);
30
+ this._actionThrottler = new RepeatedActionThrottler_1.RepeatedActionThrottler();
31
+ this._actionHandlers = new Map();
32
+ this._lastUpdateTime = 0;
33
+ }
34
+ /**
35
+ * Extension point that lets applications replace the default logic for throttling the sessions
36
+ * local sync behavior.
37
+ *
38
+ * @remarks
39
+ * The `EphemeralMediaCoordinator` is fairly aggressive at wanting to keep the local media player
40
+ * in sync with the rest of the group. This aggressiveness can result in the coordinator sending
41
+ * new sync actions before the local player has finished responding to the previous sync action.
42
+ * The `ActionThrottler` gives apps fine grain control over how aggressive they want sync to be.
43
+ *
44
+ * By default, a `RepeatedAction` throttler is used which prevents the same sync action from
45
+ * being sent within an adjustable time period.
46
+ */
47
+ get actionThrottler() {
48
+ return this._actionThrottler;
49
+ }
50
+ set actionThrottler(value) {
51
+ this._actionThrottler = value;
52
+ }
53
+ /**
54
+ * Returns true if the object has been initialized.
55
+ */
56
+ get isInitialized() {
57
+ return this.coordinator.isInitialized;
58
+ }
59
+ /**
60
+ * @deprecated isInitialized should be used instead
61
+ * Returns true if the object has been initialized.
62
+ */
63
+ get isStarted() {
64
+ return this.isInitialized;
65
+ }
66
+ /**
67
+ * The group coordinator for the session.
68
+ */
69
+ get coordinator() {
70
+ return this._coordinator;
71
+ }
72
+ /**
73
+ * Returns the logger used by the session and coordinator.
74
+ *
75
+ * @remarks
76
+ * This is used by the `MediaPlayerSynchronizer` to log events.
77
+ */
78
+ get logger() {
79
+ return this._logger;
80
+ }
81
+ /**
82
+ * initialize the object.
83
+ * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
84
+ * operations like play/pause/seek/setTrack.
85
+ */
86
+ initialize(acceptTransportChangesFrom) {
87
+ return this.coordinator.initialize(acceptTransportChangesFrom);
88
+ }
89
+ /**
90
+ * @deprecated initialize should be used instead
91
+ * initialize the object.
92
+ * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
93
+ * operations like play/pause/seek/setTrack.
94
+ */
95
+ start(acceptTransportChangesFrom) {
96
+ return this.initialize(acceptTransportChangesFrom);
97
+ }
98
+ /**
99
+ * Registers an action handler with the session.
100
+ * @param action Name of the action to register a handler for.
101
+ * @param handler Function called when the action is triggered.
102
+ */
103
+ setActionHandler(action, handler) {
104
+ if (handler) {
105
+ // add handler
106
+ this._actionHandlers.set(action, handler);
107
+ }
108
+ else if (this._actionHandlers.has(action)) {
109
+ // remove handler
110
+ this._actionHandlers.delete(action);
111
+ }
112
+ }
113
+ /**
114
+ * Registers a handler that will be queried anytime the group coordinate needs to know the
115
+ * local players transport state and position.
116
+ */
117
+ setRequestPlayerStateHandler(handler) {
118
+ this._requestPlayerStateHandler = handler;
119
+ }
120
+ /**
121
+ * Begins synchronizing the playback of a media element.
122
+ * @param player Something that "looks like" and HTML Media Element.
123
+ * @returns A new synchronizer instance. Call `synchronizer.end()` to stop synchronizing the elements playback.
124
+ */
125
+ synchronize(player) {
126
+ // A session can only synchronize one player at a time
127
+ if (this._synchronizing) {
128
+ this._synchronizing.end();
129
+ }
130
+ // Start position update timer
131
+ if (!this._updateTimer) {
132
+ this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.BeginPositionUpdateTimer);
133
+ this._updateTimer = setInterval(() => {
134
+ // Get current state
135
+ const state = this.getCurrentPlayerState();
136
+ // Check for hit wait point
137
+ this.checkWaitPointHit(state);
138
+ // Send position update if interval hit
139
+ const now = new Date().getTime();
140
+ const delta = (now - this._lastUpdateTime) / 1000;
141
+ if (this.coordinator.isInitialized && delta >= this.coordinator.positionUpdateInterval) {
142
+ this._lastUpdateTime = now;
143
+ this.coordinator.sendPositionUpdate(state);
144
+ }
145
+ }, 500);
146
+ }
147
+ return new MediaPlayerSynchronizer_1.MediaPlayerSynchronizer(player, this, () => {
148
+ this._synchronizing = undefined;
149
+ });
150
+ }
151
+ hasInitialized() {
152
+ return __awaiter(this, void 0, void 0, function* () {
153
+ this._logger = new live_share_1.EphemeralTelemetryLogger(this.runtime);
154
+ // Create coordinator and listen for triggered actions
155
+ this._coordinator = new EphemeralMediaSessionCoordinator_1.EphemeralMediaSessionCoordinator(this.runtime, () => this.getCurrentPlayerState());
156
+ this._coordinator.on(MediaSessionExtensions_1.MediaSessionCoordinatorEvents.triggeraction, (event) => {
157
+ // Pre-process actions
158
+ const details = event.details;
159
+ const seekTime = typeof details.seekTime == 'number' ? details.seekTime : -1;
160
+ switch (details.action) {
161
+ case 'play':
162
+ this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.PlayAction, null, { position: seekTime });
163
+ break;
164
+ case 'pause':
165
+ this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.PauseAction, null, { position: seekTime });
166
+ break;
167
+ case 'seekto':
168
+ this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.SeekToAction, null, { position: seekTime });
169
+ break;
170
+ case 'settrack':
171
+ this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.SetTrackAction);
172
+ break;
173
+ case 'datachange':
174
+ this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.DataChangeAction);
175
+ break;
176
+ case 'catchup':
177
+ // Default to seekto if catchup not implemented
178
+ this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.CatchUpAction, null, { position: seekTime });
179
+ if (!this._actionHandlers.has('catchup')) {
180
+ details.action = 'seekto';
181
+ }
182
+ break;
183
+ }
184
+ // Dispatch action
185
+ this.dispatchAction(details);
186
+ });
187
+ });
188
+ }
189
+ checkWaitPointHit(state) {
190
+ // Was a wait point hit?
191
+ if (state.positionState && this.coordinator.isInitialized) {
192
+ const waitPoint = this.coordinator.findNextWaitPoint();
193
+ if (waitPoint && state.positionState.position != undefined && state.positionState.position >= waitPoint.position) {
194
+ // Ensure handler registered
195
+ if (!this._actionHandlers.has('wait')) {
196
+ throw new Error(`SharedMediaSession: wait point hit but no 'wait' action registered.`);
197
+ }
198
+ // Begin suspension for wait point
199
+ const suspension = this.coordinator.beginSuspension(waitPoint);
200
+ this.dispatchAction({ action: 'wait', suspension: suspension });
201
+ }
202
+ }
203
+ }
204
+ getCurrentPlayerState() {
205
+ if (!this._requestPlayerStateHandler) {
206
+ throw new Error(`SharedMediaSession: no getPlayerState callback configured.`);
207
+ }
208
+ return this._requestPlayerStateHandler();
209
+ }
210
+ dispatchAction(details) {
211
+ if (this._actionHandlers.has(details.action)) {
212
+ const handler = this._actionHandlers.get(details.action);
213
+ this._actionThrottler.throttled(details, handler);
214
+ }
215
+ }
216
+ }
217
+ exports.EphemeralMediaSession = EphemeralMediaSession;
218
+ /**
219
+ * The objects fluid type name.
220
+ */
221
+ EphemeralMediaSession.TypeName = `@microsoft/fluid-media:SharedMediaSession`;
222
+ /**
223
+ * The objects fluid type factory.
224
+ */
225
+ EphemeralMediaSession.factory = new aqueduct_1.DataObjectFactory(EphemeralMediaSession.TypeName, EphemeralMediaSession, [], {});
226
+ //# sourceMappingURL=EphemeralMediaSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EphemeralMediaSession.js","sourceRoot":"","sources":["../src/EphemeralMediaSession.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,uDAAy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;aACjE;SACJ;IACL,CAAC;IAEO,qBAAqB;QACzB,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;SACjF;QAED,OAAO,IAAI,CAAC,0BAA0B,EAAE,CAAC;IAC7C,CAAC;IAEO,cAAc,CAAC,OAAoE;QACvF,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACzD,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;SACrD;IACL,CAAC;;AApOJ,sDAqOA;AAzNG;;GAEG;AACqB,8BAAQ,GAAG,2CAA2C,CAAC;AAE/E;;GAEG;AACqB,6BAAO,GAAG,IAAI,4BAAiB,CACnD,qBAAqB,CAAC,QAAQ,EAC9B,qBAAqB,EACrB,EAAE,EACF,EAAE,CACL,CAAC"}
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+ /// <reference types="node" />
6
+ import { IRuntimeSignaler, UserMeetingRole } from '@microsoft/live-share';
7
+ import { CoordinationWaitPoint, ExtendedMediaMetadata, ExtendedMediaSessionPlaybackState, MediaSessionCoordinatorSuspension } from './MediaSessionExtensions';
8
+ import EventEmitter from "events";
9
+ /**
10
+ * Most recent state of the media session.
11
+ */
12
+ export interface IMediaPlayerState {
13
+ /**
14
+ * Metadata for the sessions current track.
15
+ */
16
+ metadata: ExtendedMediaMetadata | null;
17
+ /**
18
+ * Optional track data object being synchronized.
19
+ *
20
+ * @remarks
21
+ * This can be used to sync things like pitch, roll, and yaw when watching 360 videos together.
22
+ */
23
+ trackData: object | null;
24
+ /**
25
+ * Sessions current playback state.
26
+ */
27
+ playbackState: ExtendedMediaSessionPlaybackState;
28
+ /**
29
+ * Sessions current position state if known.
30
+ */
31
+ positionState?: MediaPositionState;
32
+ }
33
+ /**
34
+ * The `EphemeralMediaSessionCoordinator` tracks the playback & position state of all other
35
+ * clients being synchronized with. It is responsible for keeping the local media player
36
+ * in sync with the group.
37
+ */
38
+ export declare class EphemeralMediaSessionCoordinator extends EventEmitter {
39
+ private readonly _runtime;
40
+ private readonly _logger;
41
+ private readonly _getPlayerState;
42
+ private _positionUpdateInterval;
43
+ private _maxPlaybackDrift;
44
+ private _lastWaitPoint?;
45
+ private _hasInitialized;
46
+ private _playEvent?;
47
+ private _pauseEvent?;
48
+ private _seekToEvent?;
49
+ private _setTrackEvent?;
50
+ private _setTrackDataEvent?;
51
+ private _positionUpdateEvent?;
52
+ private _joinedEvent?;
53
+ private _groupState?;
54
+ /**
55
+ * @hidden
56
+ * Applications shouldn't directly create new coordinator instances.
57
+ */
58
+ constructor(runtime: IRuntimeSignaler, getPlayerState: () => IMediaPlayerState);
59
+ /**
60
+ * Controls whether or not the local client is allowed to instruct the group to play or pause.
61
+ *
62
+ * @remarks
63
+ * This flag largely meant to influence decisions made by the coordinator and can be used by
64
+ * the UI to determine what controls should be shown to the user. It does not provide any
65
+ * security in itself.
66
+ *
67
+ * If your app is running in a semi-trusted environment where only some clients are allowed
68
+ * to play/pause media, you should use "role based verification" to enforce those policies.
69
+ */
70
+ canPlayPause: boolean;
71
+ /**
72
+ * Controls whether or not the local client is allowed to seek the group to a new playback
73
+ * position.
74
+ *
75
+ * @remarks
76
+ * This flag largely meant to influence decisions made by the coordinator and can be used by
77
+ * the UI to determine what controls should be shown to the user. It does not provide any
78
+ * security in itself.
79
+ *
80
+ * If your app is running in a semi-trusted environment where only some clients are allowed
81
+ * to change the playback position, you should use "role based verification" to enforce those policies.
82
+ */
83
+ canSeek: boolean;
84
+ /**
85
+ * Controls whether or not the local client is allowed to change tracks.
86
+ *
87
+ * @remarks
88
+ * This flag largely meant to influence decisions made by the coordinator and can be used by
89
+ * the UI to determine what controls should be shown to the user. It does not provide any
90
+ * security in itself.
91
+ *
92
+ * If your app is running in a semi-trusted environment where only some clients are allowed
93
+ * to change tracks, you should use "role based verification" to enforce those policies.
94
+ */
95
+ canSetTrack: boolean;
96
+ /**
97
+ * Controls whether or not the local client is allowed to change the tracks custom data object.
98
+ *
99
+ * @remarks
100
+ * This flag largely meant to influence decisions made by the coordinator and can be used by
101
+ * the UI to determine what controls should be shown to the user. It does not provide any
102
+ * security in itself.
103
+ *
104
+ * If your app is running in a semi-trusted environment where only some clients are allowed
105
+ * to change the tracks data object, you should use "role based verification" to enforce those
106
+ * policies.
107
+ */
108
+ canSetTrackData: boolean;
109
+ /**
110
+ * Returns true if the local client is in a suspended state.
111
+ */
112
+ get isSuspended(): boolean;
113
+ /**
114
+ * Max amount of playback drift allowed in seconds.
115
+ *
116
+ * @remarks
117
+ * Should the local clients playback position lag by more than the specified value, the
118
+ * coordinator will trigger a `catchup` action.
119
+ *
120
+ * Defaults to a value of `1` second.
121
+ */
122
+ get maxPlaybackDrift(): number;
123
+ set maxPlaybackDrift(value: number);
124
+ /**
125
+ * Frequency with which position updates are broadcast to the rest of the group in
126
+ * seconds.
127
+ *
128
+ * @remarks
129
+ * Defaults to a value of `2` seconds.
130
+ */
131
+ get positionUpdateInterval(): number;
132
+ set positionUpdateInterval(value: number);
133
+ /**
134
+ * Instructs the group to play the current track.
135
+ *
136
+ * @remarks
137
+ * Throws an exception if the session/coordinator hasn't been initialized, no track has been
138
+ * loaded, or `canPlayPause` is false.
139
+ */
140
+ play(): void;
141
+ /**
142
+ * Instructs the group to pause the current track.
143
+ *
144
+ * @remarks
145
+ * Throws an exception if the session/coordinator hasn't been initialized, no track has been
146
+ * loaded, or `canPlayPause` is false.
147
+ */
148
+ pause(): void;
149
+ /**
150
+ * Instructs the group to seek to a new position within the current track.
151
+ *
152
+ * @remarks
153
+ * Throws an exception if the session/coordinator hasn't been initialized, no track has been
154
+ * loaded, or `canSeek` is false.
155
+ * @param time Playback position in seconds to seek to.
156
+ */
157
+ seekTo(time: number): void;
158
+ /**
159
+ * Instructs the group to load a new track.
160
+ *
161
+ * @remarks
162
+ * Throws an exception if the session/coordinator hasn't been initialized or `canSetTrack` is
163
+ * false.
164
+ * @param metadata The track to load or `null` to indicate that the end of the track is reached.
165
+ * @param waitPoints Optional. List of static wait points to configure for the track. Dynamic wait points can be added via the `beginSuspension()` call.
166
+ */
167
+ setTrack(metadata: ExtendedMediaMetadata | null, waitPoints?: CoordinationWaitPoint[]): void;
168
+ /**
169
+ * Updates the track data object for the current track.
170
+ *
171
+ * @remarks
172
+ * The track data object can be used by applications to synchronize things like pitch, roll,
173
+ * and yaw of a 360 video. This data object will be reset to null anytime the track changes.
174
+ *
175
+ * Throws an exception if the session/coordinator hasn't been initialized or `canSetTrackData` is
176
+ * false.
177
+ * @param data New data object to sync with the group. This value will be synchronized using a last writer wins strategy.
178
+ */
179
+ setTrackData(data: object | null): void;
180
+ /**
181
+ * Begins a new local suspension.
182
+ *
183
+ * @remarks
184
+ * Suspension temporarily suspend the clients local synchronization with the group. This can
185
+ * be useful for displaying ads to users or temporarily disconnecting from the session while
186
+ * the user seeks the video using a timeline scrubber.
187
+ *
188
+ * Multiple simultaneous suspensions are allowed and when the last suspension ends the local
189
+ * client will be immediately re-synchronized with the group.
190
+ *
191
+ * A "Dynamic Wait Point" can be specified when `beginSuspension()` is called and the wait
192
+ * point will be broadcast to all other clients in the group. Those clients will then
193
+ * automatically enter a suspension state once they reach the positions specified by the
194
+ * wait point. Clients that are passed the wait point will immediately suspend.
195
+ *
196
+ * Any wait point based suspension (dynamic or static) will result in all clients remaining
197
+ * in a suspension state until the list client ends their suspension. This behavior can be
198
+ * conditionally bypassed by settings the wait points `maxClients` value.
199
+ *
200
+ * Throws an exception if the session/coordinator hasn't been initialized.
201
+ * @param waitPoint Optional. Dynamic wait point to broadcast to all of the clients.
202
+ * @returns The suspension object. Call `end()` on the returned suspension to end the suspension.
203
+ */
204
+ beginSuspension(waitPoint?: CoordinationWaitPoint): MediaSessionCoordinatorSuspension;
205
+ /**
206
+ * @hidden
207
+ * Called by MediaSession to verify the coordinator has been initialized.
208
+ */
209
+ get isInitialized(): boolean;
210
+ /**
211
+ * @hidden
212
+ * Called by MediaSession to start coordinator.
213
+ */
214
+ initialize(acceptTransportChangesFrom?: UserMeetingRole[]): Promise<void>;
215
+ /**
216
+ * @hidden
217
+ * Called by the MediaSession to detect if a wait point has been hit.
218
+ */
219
+ findNextWaitPoint(): CoordinationWaitPoint | null;
220
+ /**
221
+ * @hidden
222
+ * Called by MediaSession to trigger the sending of a position update.
223
+ */
224
+ sendPositionUpdate(state: IMediaPlayerState): void;
225
+ protected createChildren(acceptTransportChangesFrom?: UserMeetingRole[]): Promise<void>;
226
+ private getPlayerPosition;
227
+ }
228
+ //# sourceMappingURL=EphemeralMediaSessionCoordinator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EphemeralMediaSessionCoordinator.d.ts","sourceRoot":"","sources":["../src/EphemeralMediaSessionCoordinator.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,EAAwF,gBAAgB,EAAgB,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC9K,OAAO,EAAE,qBAAqB,EAAqC,qBAAqB,EAAE,iCAAiC,EAA+D,iCAAiC,EAAE,MAAM,0BAA0B,CAAC;AAG9P,OAAO,YAAY,MAAM,QAAQ,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B;;OAEG;IACH,QAAQ,EAAE,qBAAqB,GAAC,IAAI,CAAC;IAErC;;;;;OAKG;IACH,SAAS,EAAE,MAAM,GAAC,IAAI,CAAC;IAEvB;;OAEG;IACH,aAAa,EAAE,iCAAiC,CAAC;IAEjD;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACtC;AAED;;;;GAIG;AACH,qBAAa,gCAAiC,SAAQ,YAAY;IAC9D,OAAO,CAA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