@microsoft/live-share-media 0.5.1 → 1.0.0-preview.3
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/.nycrc.json +10 -10
- package/.vscode/launch.json +29 -0
- package/.vscode/settings.json +2 -0
- package/LICENSE +86 -86
- package/README.md +138 -137
- package/bin/IMediaPlayer.d.ts.map +1 -1
- package/bin/{EphemeralMediaSession.d.ts → LiveMediaSession.d.ts} +14 -21
- package/bin/LiveMediaSession.d.ts.map +1 -0
- package/bin/{EphemeralMediaSession.js → LiveMediaSession.js} +39 -37
- package/bin/LiveMediaSession.js.map +1 -0
- package/bin/{EphemeralMediaSessionCoordinator.d.ts → LiveMediaSessionCoordinator.d.ts} +5 -5
- package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -0
- package/bin/{EphemeralMediaSessionCoordinator.js → LiveMediaSessionCoordinator.js} +60 -48
- package/bin/LiveMediaSessionCoordinator.js.map +1 -0
- package/bin/{EphemeralMediaSessionCoordinatorSuspension.d.ts → LiveMediaSessionCoordinatorSuspension.d.ts} +3 -3
- package/bin/LiveMediaSessionCoordinatorSuspension.d.ts.map +1 -0
- package/bin/{EphemeralMediaSessionCoordinatorSuspension.js → LiveMediaSessionCoordinatorSuspension.js} +4 -4
- package/bin/LiveMediaSessionCoordinatorSuspension.js.map +1 -0
- package/bin/MediaPlayerSynchronizer.d.ts +11 -11
- package/bin/MediaPlayerSynchronizer.d.ts.map +1 -1
- package/bin/MediaPlayerSynchronizer.js +132 -75
- package/bin/MediaPlayerSynchronizer.js.map +1 -1
- package/bin/MediaSessionActionThrottler.d.ts +1 -1
- package/bin/MediaSessionActionThrottler.d.ts.map +1 -1
- package/bin/MediaSessionActionThrottler.js.map +1 -1
- package/bin/MediaSessionExtensions.d.ts.map +1 -1
- package/bin/RepeatedActionThrottler.d.ts +2 -2
- package/bin/RepeatedActionThrottler.d.ts.map +1 -1
- package/bin/RepeatedActionThrottler.js +9 -3
- package/bin/RepeatedActionThrottler.js.map +1 -1
- 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 +9 -9
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +4 -4
- package/bin/index.js.map +1 -1
- package/bin/internals/GroupCoordinatorState.d.ts +12 -12
- package/bin/internals/GroupCoordinatorState.d.ts.map +1 -1
- package/bin/internals/GroupCoordinatorState.js +94 -56
- package/bin/internals/GroupCoordinatorState.js.map +1 -1
- package/bin/internals/GroupPlaybackPosition.d.ts +3 -3
- package/bin/internals/GroupPlaybackPosition.d.ts.map +1 -1
- package/bin/internals/GroupPlaybackPosition.js +24 -15
- package/bin/internals/GroupPlaybackPosition.js.map +1 -1
- package/bin/internals/GroupPlaybackTrack.d.ts +4 -4
- package/bin/internals/GroupPlaybackTrack.d.ts.map +1 -1
- package/bin/internals/GroupPlaybackTrack.js +14 -4
- package/bin/internals/GroupPlaybackTrack.js.map +1 -1
- package/bin/internals/GroupPlaybackTrackData.d.ts +3 -3
- package/bin/internals/GroupPlaybackTrackData.d.ts.map +1 -1
- package/bin/internals/GroupPlaybackTrackData.js +8 -4
- package/bin/internals/GroupPlaybackTrackData.js.map +1 -1
- package/bin/internals/GroupTransportState.d.ts +5 -5
- package/bin/internals/GroupTransportState.d.ts.map +1 -1
- package/bin/internals/GroupTransportState.js +28 -13
- package/bin/internals/GroupTransportState.js.map +1 -1
- package/bin/internals/consts.d.ts.map +1 -1
- package/bin/internals/consts.js +54 -54
- package/bin/internals/consts.js.map +1 -1
- package/bin/internals/index.d.ts +6 -6
- package/package.json +38 -38
- package/src/IMediaPlayer.ts +29 -21
- package/src/LiveMediaSession.ts +300 -0
- package/src/LiveMediaSessionCoordinator.ts +621 -0
- package/src/{EphemeralMediaSessionCoordinatorSuspension.ts → LiveMediaSessionCoordinatorSuspension.ts} +39 -31
- package/src/MediaPlayerSynchronizer.ts +627 -450
- package/src/MediaSessionActionThrottler.ts +16 -14
- package/src/MediaSessionExtensions.ts +52 -42
- package/src/RepeatedActionThrottler.ts +74 -56
- package/src/VolumeManager.ts +197 -0
- package/src/index.ts +14 -15
- package/src/internals/GroupCoordinatorState.ts +606 -446
- package/src/internals/GroupPlaybackPosition.ts +227 -193
- package/src/internals/GroupPlaybackTrack.ts +176 -147
- package/src/internals/GroupPlaybackTrackData.ts +98 -90
- package/src/internals/GroupTransportState.ts +157 -127
- package/src/internals/consts.ts +98 -80
- package/src/internals/index.ts +11 -11
- package/src/test/GroupPlaybackPosition.spec.ts +600 -340
- package/src/test/GroupPlaybackTrack.spec.ts +122 -66
- package/src/test/SharedMediaSession.spec.ts +149 -113
- package/src/test/SharedMediaSessionCoordinator.spec.ts +271 -231
- package/src/test/VolumeManager.spec.ts +219 -0
- package/tsconfig.build.json +8 -8
- package/tsconfig.json +76 -75
- package/bin/EphemeralMediaSession.d.ts.map +0 -1
- package/bin/EphemeralMediaSession.js.map +0 -1
- package/bin/EphemeralMediaSessionCoordinator.d.ts.map +0 -1
- package/bin/EphemeralMediaSessionCoordinator.js.map +0 -1
- package/bin/EphemeralMediaSessionCoordinatorSuspension.d.ts.map +0 -1
- package/bin/EphemeralMediaSessionCoordinatorSuspension.js.map +0 -1
- package/bin/VolumeLimiter.d.ts +0 -70
- package/bin/VolumeLimiter.d.ts.map +0 -1
- package/bin/VolumeLimiter.js +0 -170
- package/bin/VolumeLimiter.js.map +0 -1
- package/src/EphemeralMediaSession.ts +0 -248
- package/src/EphemeralMediaSessionCoordinator.ts +0 -461
- package/src/VolumeLimiter.ts +0 -182
package/bin/internals/consts.js
CHANGED
|
@@ -12,66 +12,66 @@ exports.TelemetryEvents = void 0;
|
|
|
12
12
|
*/
|
|
13
13
|
exports.TelemetryEvents = {
|
|
14
14
|
MediaPlayerSynchronizer: {
|
|
15
|
-
SynchronizationStarted:
|
|
16
|
-
PlayerEvent:
|
|
17
|
-
PlayAction:
|
|
18
|
-
PauseAction:
|
|
19
|
-
SeekToAction:
|
|
20
|
-
CatchupAction:
|
|
21
|
-
SetTrackAction:
|
|
22
|
-
DataChangeAction:
|
|
23
|
-
UserTappedVideoToPlay: transmit(
|
|
24
|
-
PlaybackRateChangeBlocked:
|
|
25
|
-
PlayerBlockedOperation: transmit(
|
|
26
|
-
SeekingPlayerToStartPosition:
|
|
27
|
-
BeginSeekCalled:
|
|
28
|
-
EndSeekCalled:
|
|
29
|
-
PlayCalled:
|
|
30
|
-
PauseCalled:
|
|
31
|
-
SeekToCalled:
|
|
32
|
-
SetTrackCalled:
|
|
33
|
-
SetTrackDataCalled:
|
|
15
|
+
SynchronizationStarted: "MediaPlayerSynchronizer:SynchronizationStarted",
|
|
16
|
+
PlayerEvent: "MediaPlayerSynchronizer:PlayerEvent",
|
|
17
|
+
PlayAction: "MediaPlayerSynchronizer:PlayAction",
|
|
18
|
+
PauseAction: "MediaPlayerSynchronizer:PauseAction",
|
|
19
|
+
SeekToAction: "MediaPlayerSynchronizer:SeekToAction",
|
|
20
|
+
CatchupAction: "MediaPlayerSynchronizer:CatchupAction",
|
|
21
|
+
SetTrackAction: "MediaPlayerSynchronizer:SetTrackAction",
|
|
22
|
+
DataChangeAction: "MediaPlayerSynchronizer:DataChangeAction",
|
|
23
|
+
UserTappedVideoToPlay: transmit("MediaPlayerSynchronizer:UserTappedVideoToPlay"),
|
|
24
|
+
PlaybackRateChangeBlocked: "MediaPlayerSynchronizer:PlaybackRateChangeBlocked",
|
|
25
|
+
PlayerBlockedOperation: transmit("MediaPlayerSynchronizer:PlayerBlockedOperation"),
|
|
26
|
+
SeekingPlayerToStartPosition: "MediaPlayerSynchronizer:SeekingPlayerToStartPosition",
|
|
27
|
+
BeginSeekCalled: "MediaPlayerSynchronizer:BeginSeekCalled",
|
|
28
|
+
EndSeekCalled: "MediaPlayerSynchronizer:EndSeekCalled",
|
|
29
|
+
PlayCalled: "MediaPlayerSynchronizer:PlayCalled",
|
|
30
|
+
PauseCalled: "MediaPlayerSynchronizer:PauseCalled",
|
|
31
|
+
SeekToCalled: "MediaPlayerSynchronizer:SeekToCalled",
|
|
32
|
+
SetTrackCalled: "MediaPlayerSynchronizer:SetTrackCalled",
|
|
33
|
+
SetTrackDataCalled: "MediaPlayerSynchronizer:SetTrackDataCalled",
|
|
34
34
|
},
|
|
35
35
|
MediaSession: {
|
|
36
|
-
PlayAction: transmit(
|
|
37
|
-
PauseAction: transmit(
|
|
38
|
-
SeekToAction: transmit(
|
|
39
|
-
CatchUpAction: transmit(
|
|
40
|
-
SetTrackAction: transmit(
|
|
41
|
-
DataChangeAction:
|
|
42
|
-
BeginPositionUpdateTimer:
|
|
36
|
+
PlayAction: transmit("MediaSession:PlayAction"),
|
|
37
|
+
PauseAction: transmit("MediaSession:PauseAction"),
|
|
38
|
+
SeekToAction: transmit("MediaSession:SeekToAction"),
|
|
39
|
+
CatchUpAction: transmit("MediaSession:CatchUpAction"),
|
|
40
|
+
SetTrackAction: transmit("MediaSession:SetTrackAction"),
|
|
41
|
+
DataChangeAction: "MediaSession:DataChangeAction",
|
|
42
|
+
BeginPositionUpdateTimer: "MediaSession:BeginPositionUpdateTimer",
|
|
43
43
|
},
|
|
44
44
|
SessionCoordinator: {
|
|
45
|
-
PlayCalled: transmit(
|
|
46
|
-
PauseCalled: transmit(
|
|
47
|
-
SeekToCalled: transmit(
|
|
48
|
-
SetTrackCalled: transmit(
|
|
49
|
-
SetTrackDataCalled:
|
|
50
|
-
BeginSuspension:
|
|
51
|
-
BeginSuspensionAndWait: transmit(
|
|
52
|
-
EndSuspension:
|
|
53
|
-
EndSuspensionAndWait: transmit(
|
|
54
|
-
RemoteJoinReceived:
|
|
55
|
-
RemoteSetTrackReceived: transmit(
|
|
56
|
-
RemoteSetTrackDataReceived: transmit(
|
|
57
|
-
RemotePlayReceived: transmit(
|
|
58
|
-
RemotePauseReceived: transmit(
|
|
59
|
-
RemoteSeekToReceived: transmit(
|
|
45
|
+
PlayCalled: transmit("SessionCoordinator:PlayCalled"),
|
|
46
|
+
PauseCalled: transmit("SessionCoordinator:PauseCalled"),
|
|
47
|
+
SeekToCalled: transmit("SessionCoordinator:SeekToCalled"),
|
|
48
|
+
SetTrackCalled: transmit("SessionCoordinator:SetTrackCalled"),
|
|
49
|
+
SetTrackDataCalled: "SessionCoordinator:SetTrackDataCalled",
|
|
50
|
+
BeginSuspension: "SessionCoordinator:BeginSuspension",
|
|
51
|
+
BeginSuspensionAndWait: transmit("SessionCoordinator:BeginSuspensionAndWait"),
|
|
52
|
+
EndSuspension: "SessionCoordinator:EndSuspension",
|
|
53
|
+
EndSuspensionAndWait: transmit("SessionCoordinator:EndSuspensionAndWait"),
|
|
54
|
+
RemoteJoinReceived: "SessionCoordinator:RemoteJoinReceived",
|
|
55
|
+
RemoteSetTrackReceived: transmit("SessionCoordinator:RemoteSetTrackReceived"),
|
|
56
|
+
RemoteSetTrackDataReceived: transmit("SessionCoordinator:RemoteSetTrackDataReceived"),
|
|
57
|
+
RemotePlayReceived: transmit("SessionCoordinator:RemotePlayReceived"),
|
|
58
|
+
RemotePauseReceived: transmit("SessionCoordinator:RemotePauseReceived"),
|
|
59
|
+
RemoteSeekToReceived: transmit("SessionCoordinator:RemoteSeekToReceived"),
|
|
60
60
|
},
|
|
61
61
|
GroupCoordinator: {
|
|
62
|
-
TrackChanged:
|
|
63
|
-
TrackChangeDelayed:
|
|
64
|
-
TrackDataChanged:
|
|
65
|
-
TrackDataChangeDelayed:
|
|
66
|
-
TransportStateChanged:
|
|
67
|
-
TransportStateChangeDelayed:
|
|
68
|
-
BeginSoftSuspension:
|
|
69
|
-
CheckingForSyncIssues:
|
|
70
|
-
TrackOutOfSync: transmit(
|
|
71
|
-
TrackDataOutOfSync: transmit(
|
|
72
|
-
TransportOutOfSync: transmit(
|
|
73
|
-
PositionOutOfSync: transmit(
|
|
74
|
-
}
|
|
62
|
+
TrackChanged: "GroupCoordinator:TrackChanged",
|
|
63
|
+
TrackChangeDelayed: "GroupCoordinator:TrackChangeDelayed",
|
|
64
|
+
TrackDataChanged: "GroupCoordinator:TrackDataChanged",
|
|
65
|
+
TrackDataChangeDelayed: "GroupCoordinator:TrackDataChangeDelayed",
|
|
66
|
+
TransportStateChanged: "GroupCoordinator:TransportStateChanged",
|
|
67
|
+
TransportStateChangeDelayed: "GroupCoordinator:TransportStateChangeDelayed",
|
|
68
|
+
BeginSoftSuspension: "GroupCoordinator:BeginSoftSuspension",
|
|
69
|
+
CheckingForSyncIssues: "GroupCoordinator:CheckingForSyncIssues",
|
|
70
|
+
TrackOutOfSync: transmit("GroupCoordinator:TrackOutOfSync"),
|
|
71
|
+
TrackDataOutOfSync: transmit("GroupCoordinator:TrackDataOutOfSync"),
|
|
72
|
+
TransportOutOfSync: transmit("GroupCoordinator:TransportOutOfSync"),
|
|
73
|
+
PositionOutOfSync: transmit("GroupCoordinator:PositionOutOfSync"),
|
|
74
|
+
},
|
|
75
75
|
};
|
|
76
76
|
/**
|
|
77
77
|
* @hidden
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/internals/consts.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AACU,QAAA,eAAe,GAAG;IAC3B,uBAAuB,EAAE;QACrB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/internals/consts.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;GAIG;AACU,QAAA,eAAe,GAAG;IAC3B,uBAAuB,EAAE;QACrB,sBAAsB,EAClB,gDAAgD;QACpD,WAAW,EAAE,qCAAqC;QAClD,UAAU,EAAE,oCAAoC;QAChD,WAAW,EAAE,qCAAqC;QAClD,YAAY,EAAE,sCAAsC;QACpD,aAAa,EAAE,uCAAuC;QACtD,cAAc,EAAE,wCAAwC;QACxD,gBAAgB,EAAE,0CAA0C;QAC5D,qBAAqB,EAAE,QAAQ,CAC3B,+CAA+C,CAClD;QACD,yBAAyB,EACrB,mDAAmD;QACvD,sBAAsB,EAAE,QAAQ,CAC5B,gDAAgD,CACnD;QACD,4BAA4B,EACxB,sDAAsD;QAC1D,eAAe,EAAE,yCAAyC;QAC1D,aAAa,EAAE,uCAAuC;QACtD,UAAU,EAAE,oCAAoC;QAChD,WAAW,EAAE,qCAAqC;QAClD,YAAY,EAAE,sCAAsC;QACpD,cAAc,EAAE,wCAAwC;QACxD,kBAAkB,EAAE,4CAA4C;KACnE;IACD,YAAY,EAAE;QACV,UAAU,EAAE,QAAQ,CAAC,yBAAyB,CAAC;QAC/C,WAAW,EAAE,QAAQ,CAAC,0BAA0B,CAAC;QACjD,YAAY,EAAE,QAAQ,CAAC,2BAA2B,CAAC;QACnD,aAAa,EAAE,QAAQ,CAAC,4BAA4B,CAAC;QACrD,cAAc,EAAE,QAAQ,CAAC,6BAA6B,CAAC;QACvD,gBAAgB,EAAE,+BAA+B;QACjD,wBAAwB,EAAE,uCAAuC;KACpE;IACD,kBAAkB,EAAE;QAChB,UAAU,EAAE,QAAQ,CAAC,+BAA+B,CAAC;QACrD,WAAW,EAAE,QAAQ,CAAC,gCAAgC,CAAC;QACvD,YAAY,EAAE,QAAQ,CAAC,iCAAiC,CAAC;QACzD,cAAc,EAAE,QAAQ,CAAC,mCAAmC,CAAC;QAC7D,kBAAkB,EAAE,uCAAuC;QAC3D,eAAe,EAAE,oCAAoC;QACrD,sBAAsB,EAAE,QAAQ,CAC5B,2CAA2C,CAC9C;QACD,aAAa,EAAE,kCAAkC;QACjD,oBAAoB,EAAE,QAAQ,CAC1B,yCAAyC,CAC5C;QACD,kBAAkB,EAAE,uCAAuC;QAC3D,sBAAsB,EAAE,QAAQ,CAC5B,2CAA2C,CAC9C;QACD,0BAA0B,EAAE,QAAQ,CAChC,+CAA+C,CAClD;QACD,kBAAkB,EAAE,QAAQ,CAAC,uCAAuC,CAAC;QACrE,mBAAmB,EAAE,QAAQ,CAAC,wCAAwC,CAAC;QACvE,oBAAoB,EAAE,QAAQ,CAC1B,yCAAyC,CAC5C;KACJ;IACD,gBAAgB,EAAE;QACd,YAAY,EAAE,+BAA+B;QAC7C,kBAAkB,EAAE,qCAAqC;QACzD,gBAAgB,EAAE,mCAAmC;QACrD,sBAAsB,EAAE,yCAAyC;QACjE,qBAAqB,EAAE,wCAAwC;QAC/D,2BAA2B,EACvB,8CAA8C;QAClD,mBAAmB,EAAE,sCAAsC;QAC3D,qBAAqB,EAAE,wCAAwC;QAC/D,cAAc,EAAE,QAAQ,CAAC,iCAAiC,CAAC;QAC3D,kBAAkB,EAAE,QAAQ,CAAC,qCAAqC,CAAC;QACnE,kBAAkB,EAAE,QAAQ,CAAC,qCAAqC,CAAC;QACnE,iBAAiB,EAAE,QAAQ,CAAC,oCAAoC,CAAC;KACpE;CACJ,CAAC;AAEF;;GAEG;AACH,SAAS,QAAQ,CAAC,SAAiB;IAC/B,OAAO,GAAG,SAAS,WAAW,CAAC;AACnC,CAAC"}
|
package/bin/internals/index.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
5
|
+
export * from "./consts";
|
|
6
|
+
export * from "./GroupCoordinatorState";
|
|
7
|
+
export * from "./GroupPlaybackPosition";
|
|
8
|
+
export * from "./GroupPlaybackTrack";
|
|
9
|
+
export * from "./GroupPlaybackTrackData";
|
|
10
|
+
export * from "./GroupTransportState";
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@microsoft/live-share-media",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Live Share classes that synchronize media playback across clients.",
|
|
5
|
-
"author": "Microsoft",
|
|
6
|
-
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
-
"main": "./bin/index.js",
|
|
8
|
-
"types": "./bin/index.d.ts",
|
|
9
|
-
"scripts": {
|
|
10
|
-
"clean": "npx shx rm -rf bin",
|
|
11
|
-
"build": "tsc -p tsconfig.build.json",
|
|
12
|
-
"test": "ts-mocha src/**/*.spec.ts --timeout 10000",
|
|
13
|
-
"test:debug": "ts-mocha src/**/*.spec.ts --inspect-brk",
|
|
14
|
-
"test:coverage": "nyc --reporter=html --reporter=text --reporter=text-summary npm test"
|
|
15
|
-
},
|
|
16
|
-
"dependencies": {
|
|
17
|
-
"fluid-framework": "~1.2.3",
|
|
18
|
-
"@microsoft/live-share": "0.
|
|
19
|
-
},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@types/assert": "^1.5.6",
|
|
22
|
-
"@types/mocha": "^9.0.0",
|
|
23
|
-
"@types/node": "^
|
|
24
|
-
"mocha": "^9.1.1",
|
|
25
|
-
"nyc": "^15.1.0",
|
|
26
|
-
"ts-mocha": "^9.0.2",
|
|
27
|
-
"typescript": "^4.6.4"
|
|
28
|
-
},
|
|
29
|
-
"repository": {
|
|
30
|
-
"directory": "packages/live-share-media",
|
|
31
|
-
"type": "git",
|
|
32
|
-
"url": "https://github.com/microsoft/live-share-sdk"
|
|
33
|
-
},
|
|
34
|
-
"homepage": "https://aka.ms/teamsliveshare",
|
|
35
|
-
"bugs": {
|
|
36
|
-
"url": "https://github.com/microsoft/live-share-sdk/issues"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@microsoft/live-share-media",
|
|
3
|
+
"version": "1.0.0-preview.3",
|
|
4
|
+
"description": "Live Share classes that synchronize media playback across clients.",
|
|
5
|
+
"author": "Microsoft",
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
|
+
"main": "./bin/index.js",
|
|
8
|
+
"types": "./bin/index.d.ts",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"clean": "npx shx rm -rf bin",
|
|
11
|
+
"build": "tsc -p tsconfig.build.json",
|
|
12
|
+
"test": "ts-mocha src/**/*.spec.ts --timeout 10000",
|
|
13
|
+
"test:debug": "ts-mocha src/**/*.spec.ts --inspect-brk",
|
|
14
|
+
"test:coverage": "nyc --reporter=html --reporter=text --reporter=text-summary npm test"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"fluid-framework": "~1.2.3",
|
|
18
|
+
"@microsoft/live-share": "1.0.0-preview.3"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/assert": "^1.5.6",
|
|
22
|
+
"@types/mocha": "^9.0.0",
|
|
23
|
+
"@types/node": "^18.11.0",
|
|
24
|
+
"mocha": "^9.1.1",
|
|
25
|
+
"nyc": "^15.1.0",
|
|
26
|
+
"ts-mocha": "^9.0.2",
|
|
27
|
+
"typescript": "^4.6.4"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"directory": "packages/live-share-media",
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/microsoft/live-share-sdk"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://aka.ms/teamsliveshare",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/microsoft/live-share-sdk/issues"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/IMediaPlayer.ts
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export interface IMediaPlayer {
|
|
7
|
-
readonly currentSrc: string;
|
|
8
|
-
currentTime: number;
|
|
9
|
-
readonly duration: number;
|
|
10
|
-
readonly ended: boolean;
|
|
11
|
-
muted: boolean;
|
|
12
|
-
readonly paused: boolean;
|
|
13
|
-
playbackRate: number;
|
|
14
|
-
src: string;
|
|
15
|
-
volume: number;
|
|
16
|
-
load(): void;
|
|
17
|
-
pause(): void;
|
|
18
|
-
play(): Promise<void>;
|
|
19
|
-
addEventListener(
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface IMediaPlayer {
|
|
7
|
+
readonly currentSrc: string;
|
|
8
|
+
currentTime: number;
|
|
9
|
+
readonly duration: number;
|
|
10
|
+
readonly ended: boolean;
|
|
11
|
+
muted: boolean;
|
|
12
|
+
readonly paused: boolean;
|
|
13
|
+
playbackRate: number;
|
|
14
|
+
src: string;
|
|
15
|
+
volume: number;
|
|
16
|
+
load(): void;
|
|
17
|
+
pause(): void;
|
|
18
|
+
play(): Promise<void>;
|
|
19
|
+
addEventListener(
|
|
20
|
+
type: string,
|
|
21
|
+
listener: EventListenerOrEventListenerObject,
|
|
22
|
+
options?: boolean | AddEventListenerOptions
|
|
23
|
+
): void;
|
|
24
|
+
removeEventListener(
|
|
25
|
+
type: string,
|
|
26
|
+
listener: EventListenerOrEventListenerObject,
|
|
27
|
+
options?: boolean | EventListenerOptions
|
|
28
|
+
): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { DataObject, DataObjectFactory } from "@fluidframework/aqueduct";
|
|
7
|
+
import { LiveTelemetryLogger, UserMeetingRole } from "@microsoft/live-share";
|
|
8
|
+
import { MediaPlayerSynchronizer } from "./MediaPlayerSynchronizer";
|
|
9
|
+
import { ITriggerActionEvent, TelemetryEvents } from "./internals";
|
|
10
|
+
import {
|
|
11
|
+
MediaSessionCoordinatorEvents,
|
|
12
|
+
ExtendedMediaSessionAction,
|
|
13
|
+
ExtendedMediaSessionActionDetails,
|
|
14
|
+
} from "./MediaSessionExtensions";
|
|
15
|
+
import {
|
|
16
|
+
LiveMediaSessionCoordinator,
|
|
17
|
+
IMediaPlayerState,
|
|
18
|
+
} from "./LiveMediaSessionCoordinator";
|
|
19
|
+
import { MediaSessionActionThrottler } from "./MediaSessionActionThrottler";
|
|
20
|
+
import { RepeatedActionThrottler } from "./RepeatedActionThrottler";
|
|
21
|
+
import { IMediaPlayer } from "./IMediaPlayer";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Live fluid object that synchronizes media playback across multiple clients.
|
|
25
|
+
*/
|
|
26
|
+
export class LiveMediaSession extends DataObject {
|
|
27
|
+
private _actionThrottler: MediaSessionActionThrottler =
|
|
28
|
+
new RepeatedActionThrottler();
|
|
29
|
+
private _logger?: LiveTelemetryLogger;
|
|
30
|
+
private _requestPlayerStateHandler?: () => IMediaPlayerState;
|
|
31
|
+
private _coordinator?: LiveMediaSessionCoordinator;
|
|
32
|
+
private readonly _actionHandlers: Map<string, MediaSessionActionHandler> =
|
|
33
|
+
new Map();
|
|
34
|
+
private _synchronizing?: MediaPlayerSynchronizer;
|
|
35
|
+
|
|
36
|
+
// Position update timer
|
|
37
|
+
private _updateTimer: any;
|
|
38
|
+
private _lastUpdateTime: number = 0;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The objects fluid type name.
|
|
42
|
+
*/
|
|
43
|
+
public static readonly TypeName = `@microsoft/fluid-media:SharedMediaSession`;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The objects fluid type factory.
|
|
47
|
+
*/
|
|
48
|
+
public static readonly factory = new DataObjectFactory(
|
|
49
|
+
LiveMediaSession.TypeName,
|
|
50
|
+
LiveMediaSession,
|
|
51
|
+
[],
|
|
52
|
+
{}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Extension point that lets applications replace the default logic for throttling the sessions
|
|
57
|
+
* local sync behavior.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* The `LiveMediaCoordinator` is fairly aggressive at wanting to keep the local media player
|
|
61
|
+
* in sync with the rest of the group. This aggressiveness can result in the coordinator sending
|
|
62
|
+
* new sync actions before the local player has finished responding to the previous sync action.
|
|
63
|
+
* The `ActionThrottler` gives apps fine grain control over how aggressive they want sync to be.
|
|
64
|
+
*
|
|
65
|
+
* By default, a `RepeatedAction` throttler is used which prevents the same sync action from
|
|
66
|
+
* being sent within an adjustable time period.
|
|
67
|
+
*/
|
|
68
|
+
public get actionThrottler(): MediaSessionActionThrottler {
|
|
69
|
+
return this._actionThrottler;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public set actionThrottler(value: MediaSessionActionThrottler) {
|
|
73
|
+
this._actionThrottler = value;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns true if the object has been initialized.
|
|
78
|
+
*/
|
|
79
|
+
public get isInitialized(): boolean {
|
|
80
|
+
return this.coordinator.isInitialized;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated isInitialized should be used instead
|
|
85
|
+
* Returns true if the object has been initialized.
|
|
86
|
+
*/
|
|
87
|
+
public get isStarted(): boolean {
|
|
88
|
+
return this.isInitialized;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The group coordinator for the session.
|
|
93
|
+
*/
|
|
94
|
+
public get coordinator(): LiveMediaSessionCoordinator {
|
|
95
|
+
return this._coordinator!;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Returns the logger used by the session and coordinator.
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* This is used by the `MediaPlayerSynchronizer` to log events.
|
|
103
|
+
*/
|
|
104
|
+
public get logger(): LiveTelemetryLogger {
|
|
105
|
+
return this._logger!;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* initialize the object.
|
|
110
|
+
* @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
|
|
111
|
+
* operations like play/pause/seek/setTrack.
|
|
112
|
+
*/
|
|
113
|
+
public initialize(
|
|
114
|
+
acceptTransportChangesFrom?: UserMeetingRole[]
|
|
115
|
+
): Promise<void> {
|
|
116
|
+
return this.coordinator.initialize(acceptTransportChangesFrom);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Registers an action handler with the session.
|
|
121
|
+
* @param action Name of the action to register a handler for.
|
|
122
|
+
* @param handler Function called when the action is triggered.
|
|
123
|
+
*/
|
|
124
|
+
public setActionHandler(
|
|
125
|
+
action: ExtendedMediaSessionAction,
|
|
126
|
+
handler: MediaSessionActionHandler | null
|
|
127
|
+
): void {
|
|
128
|
+
if (handler) {
|
|
129
|
+
// add handler
|
|
130
|
+
this._actionHandlers.set(action, handler);
|
|
131
|
+
} else if (this._actionHandlers.has(action)) {
|
|
132
|
+
// remove handler
|
|
133
|
+
this._actionHandlers.delete(action);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Registers a handler that will be queried anytime the group coordinate needs to know the
|
|
139
|
+
* local players transport state and position.
|
|
140
|
+
*/
|
|
141
|
+
public setRequestPlayerStateHandler(handler: () => IMediaPlayerState) {
|
|
142
|
+
this._requestPlayerStateHandler = handler;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Begins synchronizing the playback of a media element.
|
|
147
|
+
* @param player Something that "looks like" and HTML Media Element.
|
|
148
|
+
* @returns A new synchronizer instance. Call `synchronizer.end()` to stop synchronizing the elements playback.
|
|
149
|
+
*/
|
|
150
|
+
public synchronize(player: IMediaPlayer): MediaPlayerSynchronizer {
|
|
151
|
+
// A session can only synchronize one player at a time
|
|
152
|
+
if (this._synchronizing) {
|
|
153
|
+
this._synchronizing.end();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Start position update timer
|
|
157
|
+
if (!this._updateTimer) {
|
|
158
|
+
this.logger.sendTelemetryEvent(
|
|
159
|
+
TelemetryEvents.MediaSession.BeginPositionUpdateTimer
|
|
160
|
+
);
|
|
161
|
+
this._updateTimer = setInterval(() => {
|
|
162
|
+
// Get current state
|
|
163
|
+
const state = this.getCurrentPlayerState();
|
|
164
|
+
|
|
165
|
+
// Check for hit wait point
|
|
166
|
+
this.checkWaitPointHit(state);
|
|
167
|
+
|
|
168
|
+
// Send position update if interval hit
|
|
169
|
+
const now = new Date().getTime();
|
|
170
|
+
const delta = (now - this._lastUpdateTime) / 1000;
|
|
171
|
+
if (
|
|
172
|
+
this.coordinator.isInitialized &&
|
|
173
|
+
delta >= this.coordinator.positionUpdateInterval
|
|
174
|
+
) {
|
|
175
|
+
this._lastUpdateTime = now;
|
|
176
|
+
this.coordinator.sendPositionUpdate(state);
|
|
177
|
+
}
|
|
178
|
+
}, 500);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return new MediaPlayerSynchronizer(player, this, () => {
|
|
182
|
+
this._synchronizing = undefined;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
protected async hasInitialized(): Promise<void> {
|
|
187
|
+
this._logger = new LiveTelemetryLogger(this.runtime);
|
|
188
|
+
|
|
189
|
+
// Create coordinator and listen for triggered actions
|
|
190
|
+
this._coordinator = new LiveMediaSessionCoordinator(this.runtime, () =>
|
|
191
|
+
this.getCurrentPlayerState()
|
|
192
|
+
);
|
|
193
|
+
this._coordinator.on(
|
|
194
|
+
MediaSessionCoordinatorEvents.triggeraction,
|
|
195
|
+
(event: ITriggerActionEvent) => {
|
|
196
|
+
// Pre-process actions
|
|
197
|
+
const details = event.details;
|
|
198
|
+
const seekTime =
|
|
199
|
+
typeof details.seekTime == "number" ? details.seekTime : -1;
|
|
200
|
+
switch (details.action) {
|
|
201
|
+
case "play":
|
|
202
|
+
this.logger.sendTelemetryEvent(
|
|
203
|
+
TelemetryEvents.MediaSession.PlayAction,
|
|
204
|
+
null,
|
|
205
|
+
{
|
|
206
|
+
position: seekTime,
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
break;
|
|
210
|
+
case "pause":
|
|
211
|
+
this.logger.sendTelemetryEvent(
|
|
212
|
+
TelemetryEvents.MediaSession.PauseAction,
|
|
213
|
+
null,
|
|
214
|
+
{
|
|
215
|
+
position: seekTime,
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
break;
|
|
219
|
+
case "seekto":
|
|
220
|
+
this.logger.sendTelemetryEvent(
|
|
221
|
+
TelemetryEvents.MediaSession.SeekToAction,
|
|
222
|
+
null,
|
|
223
|
+
{
|
|
224
|
+
position: seekTime,
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
break;
|
|
228
|
+
case "settrack":
|
|
229
|
+
this.logger.sendTelemetryEvent(
|
|
230
|
+
TelemetryEvents.MediaSession.SetTrackAction
|
|
231
|
+
);
|
|
232
|
+
break;
|
|
233
|
+
case "datachange":
|
|
234
|
+
this.logger.sendTelemetryEvent(
|
|
235
|
+
TelemetryEvents.MediaSession.DataChangeAction
|
|
236
|
+
);
|
|
237
|
+
break;
|
|
238
|
+
case "catchup":
|
|
239
|
+
// Default to seekto if catchup not implemented
|
|
240
|
+
this.logger.sendTelemetryEvent(
|
|
241
|
+
TelemetryEvents.MediaSession.CatchUpAction,
|
|
242
|
+
null,
|
|
243
|
+
{
|
|
244
|
+
position: seekTime,
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
if (!this._actionHandlers.has("catchup")) {
|
|
248
|
+
details.action = "seekto";
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Dispatch action
|
|
254
|
+
this.dispatchAction(details);
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private checkWaitPointHit(state: IMediaPlayerState): void {
|
|
260
|
+
// Was a wait point hit?
|
|
261
|
+
if (state.positionState && this.coordinator.isInitialized) {
|
|
262
|
+
const waitPoint = this.coordinator.findNextWaitPoint();
|
|
263
|
+
if (
|
|
264
|
+
waitPoint &&
|
|
265
|
+
state.positionState.position != undefined &&
|
|
266
|
+
state.positionState.position >= waitPoint.position
|
|
267
|
+
) {
|
|
268
|
+
// Ensure handler registered
|
|
269
|
+
if (!this._actionHandlers.has("wait")) {
|
|
270
|
+
throw new Error(
|
|
271
|
+
`SharedMediaSession: wait point hit but no 'wait' action registered.`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Begin suspension for wait point
|
|
276
|
+
const suspension = this.coordinator.beginSuspension(waitPoint);
|
|
277
|
+
this.dispatchAction({ action: "wait", suspension: suspension });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private getCurrentPlayerState(): IMediaPlayerState {
|
|
283
|
+
if (!this._requestPlayerStateHandler) {
|
|
284
|
+
throw new Error(
|
|
285
|
+
`SharedMediaSession: no getPlayerState callback configured.`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return this._requestPlayerStateHandler();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private dispatchAction(
|
|
293
|
+
details: MediaSessionActionDetails | ExtendedMediaSessionActionDetails
|
|
294
|
+
): void {
|
|
295
|
+
if (this._actionHandlers.has(details.action)) {
|
|
296
|
+
const handler = this._actionHandlers.get(details.action);
|
|
297
|
+
this._actionThrottler.throttled(details, handler);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|