@microsoft/live-share-media 2.0.0-internal.10 → 2.0.0-internal.12
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 +4 -4
- package/bin/IMediaPlayer.d.ts +21 -0
- package/bin/IMediaPlayer.d.ts.map +1 -0
- package/bin/IMediaPlayer.js +7 -0
- package/bin/IMediaPlayer.js.map +1 -0
- package/bin/LiveMediaSession.d.ts +90 -0
- package/bin/LiveMediaSession.d.ts.map +1 -0
- package/bin/LiveMediaSession.js +255 -0
- package/bin/LiveMediaSession.js.map +1 -0
- package/bin/LiveMediaSessionCoordinator.d.ts +260 -0
- package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -0
- package/bin/LiveMediaSessionCoordinator.js +472 -0
- package/bin/LiveMediaSessionCoordinator.js.map +1 -0
- package/bin/LiveMediaSessionCoordinatorSuspension.d.ts +20 -0
- package/bin/LiveMediaSessionCoordinatorSuspension.d.ts.map +1 -0
- package/bin/LiveMediaSessionCoordinatorSuspension.js +28 -0
- package/bin/LiveMediaSessionCoordinatorSuspension.js.map +1 -0
- package/bin/MediaPlayerSynchronizer.d.ts +190 -0
- package/bin/MediaPlayerSynchronizer.d.ts.map +1 -0
- package/bin/MediaPlayerSynchronizer.js +577 -0
- package/bin/MediaPlayerSynchronizer.js.map +1 -0
- package/bin/MediaSessionActionThrottler.d.ts +12 -0
- package/bin/MediaSessionActionThrottler.d.ts.map +1 -0
- package/bin/MediaSessionActionThrottler.js +14 -0
- package/bin/MediaSessionActionThrottler.js.map +1 -0
- package/bin/MediaSessionExtensions.d.ts +177 -0
- package/bin/MediaSessionExtensions.d.ts.map +1 -0
- package/bin/MediaSessionExtensions.js +26 -0
- package/bin/MediaSessionExtensions.js.map +1 -0
- package/bin/RepeatedActionThrottler.d.ts +20 -0
- package/bin/RepeatedActionThrottler.d.ts.map +1 -0
- package/bin/RepeatedActionThrottler.js +63 -0
- package/bin/RepeatedActionThrottler.js.map +1 -0
- package/bin/VolumeManager.d.ts +84 -0
- package/bin/VolumeManager.d.ts.map +1 -0
- package/bin/VolumeManager.js +175 -0
- package/bin/VolumeManager.js.map +1 -0
- package/bin/index.d.ts +14 -0
- package/bin/index.d.ts.map +1 -0
- package/bin/index.js +30 -0
- package/bin/index.js.map +1 -0
- package/bin/internals/GroupCoordinatorState.d.ts +108 -0
- package/bin/internals/GroupCoordinatorState.d.ts.map +1 -0
- package/bin/internals/GroupCoordinatorState.js +519 -0
- package/bin/internals/GroupCoordinatorState.js.map +1 -0
- package/bin/internals/GroupPlaybackPosition.d.ts +70 -0
- package/bin/internals/GroupPlaybackPosition.d.ts.map +1 -0
- package/bin/internals/GroupPlaybackPosition.js +170 -0
- package/bin/internals/GroupPlaybackPosition.js.map +1 -0
- package/bin/internals/GroupPlaybackRate.d.ts +39 -0
- package/bin/internals/GroupPlaybackRate.d.ts.map +1 -0
- package/bin/internals/GroupPlaybackRate.js +62 -0
- package/bin/internals/GroupPlaybackRate.js.map +1 -0
- package/bin/internals/GroupPlaybackTrack.d.ts +46 -0
- package/bin/internals/GroupPlaybackTrack.d.ts.map +1 -0
- package/bin/internals/GroupPlaybackTrack.js +125 -0
- package/bin/internals/GroupPlaybackTrack.js.map +1 -0
- package/bin/internals/GroupPlaybackTrackData.d.ts +41 -0
- package/bin/internals/GroupPlaybackTrackData.d.ts.map +1 -0
- package/bin/internals/GroupPlaybackTrackData.js +73 -0
- package/bin/internals/GroupPlaybackTrackData.js.map +1 -0
- package/bin/internals/GroupTransportState.d.ts +53 -0
- package/bin/internals/GroupTransportState.d.ts.map +1 -0
- package/bin/internals/GroupTransportState.js +123 -0
- package/bin/internals/GroupTransportState.js.map +1 -0
- package/bin/internals/consts.d.ts +83 -0
- package/bin/internals/consts.d.ts.map +1 -0
- package/bin/internals/consts.js +92 -0
- package/bin/internals/consts.js.map +1 -0
- package/bin/internals/errors.d.ts +17 -0
- package/bin/internals/errors.d.ts.map +1 -0
- package/bin/internals/errors.js +34 -0
- package/bin/internals/errors.js.map +1 -0
- package/bin/internals/index.d.ts +13 -0
- package/bin/internals/index.d.ts.map +1 -0
- package/bin/internals/index.js +29 -0
- package/bin/internals/index.js.map +1 -0
- package/bin/internals/interfaces.d.ts +10 -0
- package/bin/internals/interfaces.d.ts.map +1 -0
- package/bin/internals/interfaces.js +3 -0
- package/bin/internals/interfaces.js.map +1 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -118,10 +118,10 @@ The Live Share SDK contains dependencies for [@microsoft/teams-js](https://www.n
|
|
|
118
118
|
|
|
119
119
|
There are several ways you can [contribute](../../CONTRIBUTING.md) to this project:
|
|
120
120
|
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
121
|
+
- [Submit bugs](https://github.com/microsoft/live-share-sdk/issues) and help us verify fixes as they are checked in.
|
|
122
|
+
- Review the source code changes.
|
|
123
|
+
- Engage with other Live Share developers on [StackOverflow](https://stackoverflow.com/questions/tagged/live-share).
|
|
124
|
+
- [Contribute bug fixes](../../CONTRIBUTING.md).
|
|
125
125
|
|
|
126
126
|
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact <opencode@microsoft.com> with any additional questions or comments.
|
|
127
127
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
export interface IMediaPlayer {
|
|
6
|
+
readonly currentSrc: string;
|
|
7
|
+
currentTime: number;
|
|
8
|
+
readonly duration: number;
|
|
9
|
+
readonly ended: boolean;
|
|
10
|
+
muted: boolean;
|
|
11
|
+
readonly paused: boolean;
|
|
12
|
+
playbackRate: number;
|
|
13
|
+
src: string;
|
|
14
|
+
volume: number;
|
|
15
|
+
load(): void;
|
|
16
|
+
pause(): void;
|
|
17
|
+
play(): Promise<void>;
|
|
18
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
19
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=IMediaPlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMediaPlayer.d.ts","sourceRoot":"","sources":["../src/IMediaPlayer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,IAAI,CAAC;IACd,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,gBAAgB,CACZ,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC5C,IAAI,CAAC;IACR,mBAAmB,CACf,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,OAAO,CAAC,EAAE,OAAO,GAAG,oBAAoB,GACzC,IAAI,CAAC;CACX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMediaPlayer.js","sourceRoot":"","sources":["../src/IMediaPlayer.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
import { DataObjectFactory } from "@fluidframework/aqueduct";
|
|
6
|
+
import { LiveDataObject, LiveTelemetryLogger, UserMeetingRole } from "@microsoft/live-share";
|
|
7
|
+
import { MediaPlayerSynchronizer } from "./MediaPlayerSynchronizer";
|
|
8
|
+
import { ExtendedMediaSessionAction, ExtendedMediaSessionActionHandler } from "./MediaSessionExtensions";
|
|
9
|
+
import { LiveMediaSessionCoordinator, IMediaPlayerState } from "./LiveMediaSessionCoordinator";
|
|
10
|
+
import { MediaSessionActionThrottler } from "./MediaSessionActionThrottler";
|
|
11
|
+
import { IMediaPlayer } from "./IMediaPlayer";
|
|
12
|
+
/**
|
|
13
|
+
* Live fluid object that synchronizes media playback across multiple clients.
|
|
14
|
+
*/
|
|
15
|
+
export declare class LiveMediaSession extends LiveDataObject {
|
|
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<LiveMediaSession, 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 `LiveMediaCoordinator` 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
|
+
* The group coordinator for the session.
|
|
49
|
+
*/
|
|
50
|
+
get coordinator(): LiveMediaSessionCoordinator;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the logger used by the session and coordinator.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* This is used by the `MediaPlayerSynchronizer` to log events.
|
|
56
|
+
*/
|
|
57
|
+
get logger(): LiveTelemetryLogger;
|
|
58
|
+
/**
|
|
59
|
+
* Initialize the object to begin sending/receiving group playback updates through this DDS.
|
|
60
|
+
*
|
|
61
|
+
* @param allowedRoles Optional. List of roles allowed to group transport operations like play/pause/seek/setTrack.
|
|
62
|
+
*
|
|
63
|
+
* @returns a void promise that resolves once complete.
|
|
64
|
+
*
|
|
65
|
+
* @throws error when `.initialize()` has already been called for this class instance.
|
|
66
|
+
*/
|
|
67
|
+
initialize(allowedRoles?: UserMeetingRole[]): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Registers an action handler with the session.
|
|
70
|
+
* @param action Name of the action to register a handler for.
|
|
71
|
+
* @param handler Function called when the action is triggered.
|
|
72
|
+
*/
|
|
73
|
+
setActionHandler(action: ExtendedMediaSessionAction, handler: ExtendedMediaSessionActionHandler | MediaSessionActionHandler | null): void;
|
|
74
|
+
/**
|
|
75
|
+
* Registers a handler that will be queried anytime the group coordinate needs to know the
|
|
76
|
+
* local players transport state and position.
|
|
77
|
+
*/
|
|
78
|
+
setRequestPlayerStateHandler(handler: () => IMediaPlayerState): void;
|
|
79
|
+
/**
|
|
80
|
+
* Begins synchronizing the playback of a media element.
|
|
81
|
+
* @param player Something that "looks like" and HTML Media Element.
|
|
82
|
+
* @returns A new synchronizer instance. Call `synchronizer.end()` to stop synchronizing the elements playback.
|
|
83
|
+
*/
|
|
84
|
+
synchronize(player: IMediaPlayer): MediaPlayerSynchronizer;
|
|
85
|
+
protected hasInitialized(): Promise<void>;
|
|
86
|
+
private checkWaitPointHit;
|
|
87
|
+
private getCurrentPlayerState;
|
|
88
|
+
private dispatchAction;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=LiveMediaSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveMediaSession.d.ts","sourceRoot":"","sources":["../src/LiveMediaSession.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAEH,cAAc,EAGd,mBAAmB,EACnB,eAAe,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAEH,0BAA0B,EAE1B,iCAAiC,EACpC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACH,2BAA2B,EAC3B,iBAAiB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,cAAc;IAChD,OAAO,CAAC,gBAAgB,CACU;IAClC,OAAO,CAAC,OAAO,CAAC,CAAsB;IACtC,OAAO,CAAC,0BAA0B,CAAC,CAA0B;IAC7D,OAAO,CAAC,YAAY,CAAC,CAA8B;IACnD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAGlB;IACd,OAAO,CAAC,cAAc,CAAC,CAA0B;IAGjD,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,eAAe,CAAa;IAEpC;;OAEG;IACH,gBAAuB,QAAQ,+CAA+C;IAE9E;;OAEG;IACH,gBAAuB,OAAO,0FAK5B;IAEF;;;;;;;;;;;;OAYG;IACH,IAAW,eAAe,IAAI,2BAA2B,CAExD;IAED,IAAW,eAAe,CAAC,KAAK,EAAE,2BAA2B,EAE5D;IAED;;OAEG;IACH,IAAW,WAAW,IAAI,2BAA2B,CAEpD;IAED;;;;;OAKG;IACH,IAAW,MAAM,IAAI,mBAAmB,CAEvC;IAED;;;;;;;;OAQG;IACU,UAAU,CAAC,YAAY,CAAC,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBxE;;;;OAIG;IACI,gBAAgB,CACnB,MAAM,EAAE,0BAA0B,EAClC,OAAO,EACD,iCAAiC,GACjC,yBAAyB,GACzB,IAAI,GACX,IAAI;IAUP;;;OAGG;IACI,4BAA4B,CAAC,OAAO,EAAE,MAAM,iBAAiB;IAIpE;;;;OAIG;IACI,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,uBAAuB;cAoCjD,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAwF/C,OAAO,CAAC,iBAAiB;IAgCzB,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,cAAc;CAQzB"}
|
|
@@ -0,0 +1,255 @@
|
|
|
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.LiveMediaSession = 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 LiveMediaSessionCoordinator_1 = require("./LiveMediaSessionCoordinator");
|
|
23
|
+
const RepeatedActionThrottler_1 = require("./RepeatedActionThrottler");
|
|
24
|
+
/**
|
|
25
|
+
* Live fluid object that synchronizes media playback across multiple clients.
|
|
26
|
+
*/
|
|
27
|
+
class LiveMediaSession extends live_share_1.LiveDataObject {
|
|
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 `LiveMediaCoordinator` 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
|
+
* The group coordinator for the session.
|
|
55
|
+
*/
|
|
56
|
+
get coordinator() {
|
|
57
|
+
return this._coordinator;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns the logger used by the session and coordinator.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* This is used by the `MediaPlayerSynchronizer` to log events.
|
|
64
|
+
*/
|
|
65
|
+
get logger() {
|
|
66
|
+
return this._logger;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Initialize the object to begin sending/receiving group playback updates through this DDS.
|
|
70
|
+
*
|
|
71
|
+
* @param allowedRoles Optional. List of roles allowed to group transport operations like play/pause/seek/setTrack.
|
|
72
|
+
*
|
|
73
|
+
* @returns a void promise that resolves once complete.
|
|
74
|
+
*
|
|
75
|
+
* @throws error when `.initialize()` has already been called for this class instance.
|
|
76
|
+
*/
|
|
77
|
+
initialize(allowedRoles) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
live_share_1.LiveDataObjectInitializeNotNeededError.assert("LiveMediaSession:initialize", this.initializeState);
|
|
80
|
+
// Update initialize state as pending
|
|
81
|
+
this.initializeState = live_share_1.LiveDataObjectInitializeState.pending;
|
|
82
|
+
if (allowedRoles) {
|
|
83
|
+
this._allowedRoles = allowedRoles;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
yield this.coordinator.initialize(allowedRoles);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
this.initializeState = live_share_1.LiveDataObjectInitializeState.needed;
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
// Update initialize state as succeeded
|
|
93
|
+
this.initializeState = live_share_1.LiveDataObjectInitializeState.succeeded;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Registers an action handler with the session.
|
|
98
|
+
* @param action Name of the action to register a handler for.
|
|
99
|
+
* @param handler Function called when the action is triggered.
|
|
100
|
+
*/
|
|
101
|
+
setActionHandler(action, handler) {
|
|
102
|
+
if (handler) {
|
|
103
|
+
// add handler
|
|
104
|
+
this._actionHandlers.set(action, handler);
|
|
105
|
+
}
|
|
106
|
+
else if (this._actionHandlers.has(action)) {
|
|
107
|
+
// remove handler
|
|
108
|
+
this._actionHandlers.delete(action);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Registers a handler that will be queried anytime the group coordinate needs to know the
|
|
113
|
+
* local players transport state and position.
|
|
114
|
+
*/
|
|
115
|
+
setRequestPlayerStateHandler(handler) {
|
|
116
|
+
this._requestPlayerStateHandler = handler;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Begins synchronizing the playback of a media element.
|
|
120
|
+
* @param player Something that "looks like" and HTML Media Element.
|
|
121
|
+
* @returns A new synchronizer instance. Call `synchronizer.end()` to stop synchronizing the elements playback.
|
|
122
|
+
*/
|
|
123
|
+
synchronize(player) {
|
|
124
|
+
// A session can only synchronize one player at a time
|
|
125
|
+
if (this._synchronizing) {
|
|
126
|
+
this._synchronizing.end();
|
|
127
|
+
}
|
|
128
|
+
// Start position update timer
|
|
129
|
+
if (!this._updateTimer) {
|
|
130
|
+
this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.BeginPositionUpdateTimer);
|
|
131
|
+
this._updateTimer = setInterval(() => {
|
|
132
|
+
// Get current state
|
|
133
|
+
const state = this.getCurrentPlayerState();
|
|
134
|
+
// Check for hit wait point
|
|
135
|
+
this.checkWaitPointHit(state);
|
|
136
|
+
// Send position update if interval hit
|
|
137
|
+
const now = new Date().getTime();
|
|
138
|
+
const delta = (now - this._lastUpdateTime) / 1000;
|
|
139
|
+
if (this.coordinator.isInitialized &&
|
|
140
|
+
delta >= this.coordinator.positionUpdateInterval) {
|
|
141
|
+
this._lastUpdateTime = now;
|
|
142
|
+
this.coordinator.sendPositionUpdate(state);
|
|
143
|
+
}
|
|
144
|
+
}, 500);
|
|
145
|
+
}
|
|
146
|
+
return new MediaPlayerSynchronizer_1.MediaPlayerSynchronizer(player, this, this.runtime, () => {
|
|
147
|
+
this._synchronizing = undefined;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
hasInitialized() {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
this._logger = new live_share_1.LiveTelemetryLogger(this.runtime, this.liveRuntime);
|
|
153
|
+
// Create coordinator and listen for triggered actions
|
|
154
|
+
this._coordinator = new LiveMediaSessionCoordinator_1.LiveMediaSessionCoordinator(this.id, this.runtime, this.liveRuntime, () => this.getCurrentPlayerState());
|
|
155
|
+
this._coordinator.on(MediaSessionExtensions_1.MediaSessionCoordinatorEvents.triggeraction, (event) => {
|
|
156
|
+
// Pre-process actions
|
|
157
|
+
const details = event.details;
|
|
158
|
+
const seekTime = typeof details.seekTime == "number" ? details.seekTime : -1;
|
|
159
|
+
switch (details.action) {
|
|
160
|
+
case "play":
|
|
161
|
+
this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.PlayAction, null, {
|
|
162
|
+
position: seekTime,
|
|
163
|
+
});
|
|
164
|
+
break;
|
|
165
|
+
case "pause":
|
|
166
|
+
this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.PauseAction, null, {
|
|
167
|
+
position: seekTime,
|
|
168
|
+
});
|
|
169
|
+
break;
|
|
170
|
+
case "ratechange":
|
|
171
|
+
if (!details.playbackRate) {
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.RateChangeAction, null, {
|
|
175
|
+
playbackRate: details.playbackRate,
|
|
176
|
+
});
|
|
177
|
+
break;
|
|
178
|
+
case "seekto":
|
|
179
|
+
this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.SeekToAction, null, {
|
|
180
|
+
position: seekTime,
|
|
181
|
+
});
|
|
182
|
+
break;
|
|
183
|
+
case "settrack":
|
|
184
|
+
this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.SetTrackAction);
|
|
185
|
+
break;
|
|
186
|
+
case "datachange":
|
|
187
|
+
this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.DataChangeAction);
|
|
188
|
+
break;
|
|
189
|
+
case "catchup":
|
|
190
|
+
// Default to seekto if catchup not implemented
|
|
191
|
+
this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.CatchUpAction, null, {
|
|
192
|
+
position: seekTime,
|
|
193
|
+
});
|
|
194
|
+
if (!this._actionHandlers.has("catchup")) {
|
|
195
|
+
details.action = "seekto";
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
// Dispatch action
|
|
200
|
+
this.dispatchAction(details);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
checkWaitPointHit(state) {
|
|
205
|
+
// Was a wait point hit?
|
|
206
|
+
if (state.positionState && this.coordinator.isInitialized) {
|
|
207
|
+
const waitPoint = this.coordinator.findNextWaitPoint();
|
|
208
|
+
if (waitPoint &&
|
|
209
|
+
state.positionState.position != undefined &&
|
|
210
|
+
state.positionState.position >= waitPoint.position) {
|
|
211
|
+
// Ensure handler registered
|
|
212
|
+
if (!this._actionHandlers.has("wait")) {
|
|
213
|
+
throw new Error(`LiveMediaSession:checkWaitPointHit - wait point hit but no 'wait' action registered.\nTo fix this error, set a \`wait\` action using the \`setActionHandler()\` function.`);
|
|
214
|
+
}
|
|
215
|
+
// Begin suspension for wait point
|
|
216
|
+
this.waitUntilConnected().then((clientId) => {
|
|
217
|
+
const suspension = this.coordinator.beginSuspension(waitPoint);
|
|
218
|
+
this.dispatchAction({
|
|
219
|
+
action: "wait",
|
|
220
|
+
source: "system",
|
|
221
|
+
clientId,
|
|
222
|
+
local: true,
|
|
223
|
+
suspension,
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
getCurrentPlayerState() {
|
|
230
|
+
if (!this._requestPlayerStateHandler) {
|
|
231
|
+
throw new Error("LiveMediaSession:getCurrentPlayerState - no `requestPlayerStateHandler` callback configured.\nTo fix this error, ensure `setRequestPlayerStateHandler()` has been set with a delegate to retrieve your player's state, or use the `synchronize()` function to create a new `MediaPlayerSynchronizer` instance tied to your `IMediaPlayer` instance.");
|
|
232
|
+
}
|
|
233
|
+
return this._requestPlayerStateHandler();
|
|
234
|
+
}
|
|
235
|
+
dispatchAction(details) {
|
|
236
|
+
if (this._actionHandlers.has(details.action)) {
|
|
237
|
+
const handler = this._actionHandlers.get(details.action);
|
|
238
|
+
this._actionThrottler.throttled(details, handler);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* The objects fluid type name.
|
|
244
|
+
*/
|
|
245
|
+
LiveMediaSession.TypeName = `@microsoft/fluid-media:SharedMediaSession`;
|
|
246
|
+
/**
|
|
247
|
+
* The objects fluid type factory.
|
|
248
|
+
*/
|
|
249
|
+
LiveMediaSession.factory = new aqueduct_1.DataObjectFactory(LiveMediaSession.TypeName, LiveMediaSession, [], {});
|
|
250
|
+
exports.LiveMediaSession = LiveMediaSession;
|
|
251
|
+
/**
|
|
252
|
+
* Register `LiveMediaSession` as an available `LoadableObjectClass` for use in packages that support dynamic object loading, such as `@microsoft/live-share-turbo`.
|
|
253
|
+
*/
|
|
254
|
+
live_share_1.DynamicObjectRegistry.registerObjectClass(LiveMediaSession, LiveMediaSession.TypeName);
|
|
255
|
+
//# sourceMappingURL=LiveMediaSession.js.map
|
|
@@ -0,0 +1 @@
|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