@microsoft/live-share-media 0.5.1 → 1.0.0-preview.10

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.
Files changed (88) hide show
  1. package/.nycrc.json +10 -10
  2. package/LICENSE +86 -86
  3. package/README.md +141 -137
  4. package/bin/IMediaPlayer.d.ts.map +1 -1
  5. package/bin/LiveMediaSession.d.ts +95 -0
  6. package/bin/LiveMediaSession.d.ts.map +1 -0
  7. package/bin/LiveMediaSession.js +232 -0
  8. package/bin/LiveMediaSession.js.map +1 -0
  9. package/bin/LiveMediaSessionCoordinator.d.ts +228 -0
  10. package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -0
  11. package/bin/LiveMediaSessionCoordinator.js +408 -0
  12. package/bin/LiveMediaSessionCoordinator.js.map +1 -0
  13. package/bin/LiveMediaSessionCoordinatorSuspension.d.ts +20 -0
  14. package/bin/LiveMediaSessionCoordinatorSuspension.d.ts.map +1 -0
  15. package/bin/LiveMediaSessionCoordinatorSuspension.js +28 -0
  16. package/bin/LiveMediaSessionCoordinatorSuspension.js.map +1 -0
  17. package/bin/MediaPlayerSynchronizer.d.ts +11 -11
  18. package/bin/MediaPlayerSynchronizer.d.ts.map +1 -1
  19. package/bin/MediaPlayerSynchronizer.js +136 -76
  20. package/bin/MediaPlayerSynchronizer.js.map +1 -1
  21. package/bin/MediaSessionActionThrottler.d.ts +1 -1
  22. package/bin/MediaSessionActionThrottler.d.ts.map +1 -1
  23. package/bin/MediaSessionActionThrottler.js.map +1 -1
  24. package/bin/MediaSessionExtensions.d.ts.map +1 -1
  25. package/bin/RepeatedActionThrottler.d.ts +2 -2
  26. package/bin/RepeatedActionThrottler.d.ts.map +1 -1
  27. package/bin/RepeatedActionThrottler.js +9 -3
  28. package/bin/RepeatedActionThrottler.js.map +1 -1
  29. package/bin/VolumeManager.d.ts +84 -0
  30. package/bin/VolumeManager.d.ts.map +1 -0
  31. package/bin/VolumeManager.js +175 -0
  32. package/bin/VolumeManager.js.map +1 -0
  33. package/bin/index.d.ts +9 -9
  34. package/bin/index.d.ts.map +1 -1
  35. package/bin/index.js +4 -4
  36. package/bin/index.js.map +1 -1
  37. package/bin/internals/GroupCoordinatorState.d.ts +12 -12
  38. package/bin/internals/GroupCoordinatorState.d.ts.map +1 -1
  39. package/bin/internals/GroupCoordinatorState.js +94 -56
  40. package/bin/internals/GroupCoordinatorState.js.map +1 -1
  41. package/bin/internals/GroupPlaybackPosition.d.ts +3 -3
  42. package/bin/internals/GroupPlaybackPosition.d.ts.map +1 -1
  43. package/bin/internals/GroupPlaybackPosition.js +24 -15
  44. package/bin/internals/GroupPlaybackPosition.js.map +1 -1
  45. package/bin/internals/GroupPlaybackTrack.d.ts +4 -4
  46. package/bin/internals/GroupPlaybackTrack.d.ts.map +1 -1
  47. package/bin/internals/GroupPlaybackTrack.js +14 -4
  48. package/bin/internals/GroupPlaybackTrack.js.map +1 -1
  49. package/bin/internals/GroupPlaybackTrackData.d.ts +3 -3
  50. package/bin/internals/GroupPlaybackTrackData.d.ts.map +1 -1
  51. package/bin/internals/GroupPlaybackTrackData.js +8 -4
  52. package/bin/internals/GroupPlaybackTrackData.js.map +1 -1
  53. package/bin/internals/GroupTransportState.d.ts +5 -5
  54. package/bin/internals/GroupTransportState.d.ts.map +1 -1
  55. package/bin/internals/GroupTransportState.js +28 -13
  56. package/bin/internals/GroupTransportState.js.map +1 -1
  57. package/bin/internals/consts.d.ts.map +1 -1
  58. package/bin/internals/consts.js +54 -54
  59. package/bin/internals/consts.js.map +1 -1
  60. package/bin/internals/index.d.ts +6 -6
  61. package/package.json +38 -38
  62. package/src/IMediaPlayer.ts +29 -21
  63. package/src/LiveMediaSession.ts +305 -0
  64. package/src/LiveMediaSessionCoordinator.ts +621 -0
  65. package/src/{EphemeralMediaSessionCoordinatorSuspension.ts → LiveMediaSessionCoordinatorSuspension.ts} +39 -31
  66. package/src/MediaPlayerSynchronizer.ts +636 -450
  67. package/src/MediaSessionActionThrottler.ts +16 -14
  68. package/src/MediaSessionExtensions.ts +52 -42
  69. package/src/RepeatedActionThrottler.ts +74 -56
  70. package/src/VolumeManager.ts +197 -0
  71. package/src/index.ts +14 -15
  72. package/src/internals/GroupCoordinatorState.ts +606 -446
  73. package/src/internals/GroupPlaybackPosition.ts +227 -193
  74. package/src/internals/GroupPlaybackTrack.ts +176 -147
  75. package/src/internals/GroupPlaybackTrackData.ts +98 -90
  76. package/src/internals/GroupTransportState.ts +157 -127
  77. package/src/internals/consts.ts +98 -80
  78. package/src/internals/index.ts +11 -11
  79. package/src/test/GroupPlaybackPosition.spec.ts +600 -340
  80. package/src/test/GroupPlaybackTrack.spec.ts +122 -66
  81. package/src/test/SharedMediaSession.spec.ts +149 -113
  82. package/src/test/SharedMediaSessionCoordinator.spec.ts +271 -231
  83. package/src/test/VolumeManager.spec.ts +219 -0
  84. package/tsconfig.build.json +8 -8
  85. package/tsconfig.json +76 -75
  86. package/src/EphemeralMediaSession.ts +0 -248
  87. package/src/EphemeralMediaSessionCoordinator.ts +0 -461
  88. package/src/VolumeLimiter.ts +0 -182
@@ -1,231 +1,271 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
-
6
- import 'mocha';
7
- import { strict as assert } from 'assert';
8
- import { SimulatedBroadcastHub, SimulatedCollaborationSpace, IParticipant, ParticipantRole, Deferred } from '@microsoft/teams-collaboration';
9
- import { ExtendedMediaMetadata } from './MediaSessionExtensions';
10
- import { ICurrentPlaybackPosition } from './coordinatorState';
11
- import { TestMediaSession } from './SharedMediaSession.spec';
12
-
13
- describe('SharedMediaSessionCoordinator', () => {
14
- const user1: IParticipant = { participantId: 'user1', role: ParticipantRole.organizer };
15
- const user2: IParticipant = { participantId: 'user2', role: ParticipantRole.participant };
16
- const testTrack: ExtendedMediaMetadata = {
17
- trackIdentifier: 'https://example.org/test.mp3',
18
- title: 'Test Title',
19
- album: 'Test Album',
20
- artist: 'The Testers',
21
- artwork: []
22
- };
23
- const leaderPosition: Partial<ICurrentPlaybackPosition> = {
24
- playbackState: 'playing',
25
- position: 25.0,
26
- duration: 600.0
27
- };
28
-
29
- const laggerPosition: Partial<ICurrentPlaybackPosition> = {
30
- playbackState: 'playing',
31
- position: 20.0,
32
- duration: 600.0
33
- };
34
-
35
- it('should send "joined" event when joined.', async () => {
36
- const hub = new SimulatedBroadcastHub();
37
- const space1 = new SimulatedCollaborationSpace(user1, hub);
38
- const space2 = new SimulatedCollaborationSpace(user2, hub);
39
-
40
- try {
41
- let cnt = 0;
42
- const session = new TestMediaSession(space1);
43
- await space2.join();
44
- space2.socket.addBroadcastListener(session.name, 'joined', async (event) => {
45
- cnt++;
46
- });
47
-
48
- await space1.join();
49
- assert(cnt == 1, `joined event not sent`);
50
- } finally {
51
- await space1.leave();
52
- await space2.leave();
53
- }
54
- });
55
-
56
- it('should send "positionUpdate" event regularly.', async () => {
57
- const hub = new SimulatedBroadcastHub();
58
- const space1 = new SimulatedCollaborationSpace(user1, hub);
59
- const space2 = new SimulatedCollaborationSpace(user2, hub);
60
-
61
- try {
62
- let cnt = 0;
63
- const done = new Deferred();
64
- const session = new TestMediaSession(space1, testTrack);
65
- session.coordinator.positionUpdateInterval = 0.02;
66
- await space2.join();
67
- space2.socket.addBroadcastListener(session.name, 'positionUpdate', async (event) => {
68
- cnt++;
69
- if (cnt > 1) {
70
- done.resolve();
71
- }
72
- });
73
-
74
- await session.coordinator.join();
75
- await session.coordinator.play();
76
- await done.promise;
77
- } finally {
78
- await space1.leave();
79
- await space2.leave();
80
- }
81
- });
82
-
83
- it('should broadcast "play" transport command.', async () => {
84
- const hub = new SimulatedBroadcastHub();
85
- const space1 = new SimulatedCollaborationSpace(user1, hub);
86
- const space2 = new SimulatedCollaborationSpace(user2, hub);
87
-
88
- try {
89
- const session1 = new TestMediaSession(space1, testTrack);
90
- const session2 = new TestMediaSession(space2, testTrack);
91
-
92
- await space1.join();
93
- await space2.join();
94
-
95
- // Listen for action
96
- const done = new Deferred();
97
-
98
- // Start playback
99
- await session1.coordinator.play();
100
-
101
- // Wait for action to be broadcast
102
- await session2.waitForAction(async (details) => {
103
- assert(details.action == 'play', `wrong action received`);
104
- });
105
- } finally {
106
- await space1.leave();
107
- await space2.leave();
108
- }
109
- });
110
-
111
- it('should broadcast "pause" transport command.', async () => {
112
- const hub = new SimulatedBroadcastHub();
113
- const space1 = new SimulatedCollaborationSpace(user1, hub);
114
- const space2 = new SimulatedCollaborationSpace(user2, hub);
115
-
116
- try {
117
- const session1 = new TestMediaSession(space1, testTrack);
118
- const session2 = new TestMediaSession(space2, testTrack);
119
-
120
- await session1.coordinator.join();
121
- await space2.join();
122
-
123
- // Start playback
124
- await session1.coordinator.play();
125
-
126
- // Wait for action to be broadcast
127
- await session2.waitForAction(async (details) => {
128
- assert(details.action == 'play', `didn't start playback`);
129
-
130
- // Pause playback
131
- await session1.coordinator.pause();
132
- await session2.waitForAction(async (details) => {
133
- assert(details.action == 'pause', `didn't pause playback`);
134
- });
135
- });
136
- } finally {
137
- await space1.leave();
138
- await space2.leave();
139
- }
140
- });
141
-
142
- it('should broadcast "seekTo" transport command.', async () => {
143
- const hub = new SimulatedBroadcastHub();
144
- const space1 = new SimulatedCollaborationSpace(user1, hub);
145
- const space2 = new SimulatedCollaborationSpace(user2, hub);
146
-
147
- try {
148
- const session1 = new TestMediaSession(space1, testTrack);
149
- const session2 = new TestMediaSession(space2, testTrack);
150
-
151
- await session1.coordinator.join();
152
- await space2.join();
153
-
154
- // Start playback
155
- await session1.coordinator.play();
156
-
157
- // Wait for action to be broadcast
158
- await session2.waitForAction(async (details) => {
159
- assert(details.action == 'play', `didn't start playback`);
160
-
161
- // Seek to position
162
- await session1.coordinator.seekTo(2.3);
163
- await session2.waitForAction(async (details) => {
164
- assert(details.action == 'seekto', `wong action received "${details.action}"`);
165
- assert(details.seekTime >= 2.3, `wrong seek position "${details.seekTime}"`)
166
- });
167
- });
168
- } finally {
169
- await space1.leave();
170
- await space2.leave();
171
- }
172
- });
173
-
174
- it('should broadcast "setTrack" transport command.', async () => {
175
- const hub = new SimulatedBroadcastHub();
176
- const space1 = new SimulatedCollaborationSpace(user1, hub);
177
- const space2 = new SimulatedCollaborationSpace(user2, hub);
178
-
179
- try {
180
- const session1 = new TestMediaSession(space1);
181
- const session2 = new TestMediaSession(space2);
182
-
183
- await space1.join();
184
- await space2.join();
185
-
186
- // Change tracks
187
- await session1.coordinator.setTrack(testTrack);
188
-
189
- // Wait for action to be broadcast
190
- await session2.waitForAction(async (details) => {
191
- assert(details.action == 'settrack', `wrong action received "${details.action}"`);
192
- assert(JSON.stringify(session1.metadata) == JSON.stringify(testTrack), `session1 has wrong track: ${JSON.stringify(session1.metadata)}`);
193
- assert(JSON.stringify(session2.metadata) == JSON.stringify(testTrack), `session2 has wrong track: ${JSON.stringify(session2.metadata)}`);
194
- });
195
- } finally {
196
- await space1.leave();
197
- await space2.leave();
198
- }
199
- });
200
-
201
- // it('should trigger "catchup" action.', async () => {
202
- // const hub = new SimulatedBroadcastHub();
203
- // const space1 = new SimulatedCollaborationSpace(user1, hub);
204
- // const space2 = new SimulatedCollaborationSpace(user2, hub);
205
-
206
- // try {
207
- // const session1 = new TestMediaSession(testTrack, leaderPosition);
208
- // const session1.coordinator = new SharedMediaSessionCoordinator(space1, session1, session1.name);
209
- // session1.coordinator.positionUpdateInterval = 0.02;
210
- // const session2 = new TestMediaSession(testTrack, laggerPosition);
211
- // const coordinator2 = new SharedMediaSessionCoordinator(space2, session2, session2.name);
212
- // coordinator2.positionUpdateInterval = 0.02;
213
-
214
- // await session1.coordinator.join();
215
- // await coordinator2.join();
216
-
217
- // await session1.coordinator.play();
218
-
219
- // // Wait for action to be broadcast
220
- // session2.reset();
221
- // await session2.waitForAction(async () => {
222
- // assert(session2.isOutOfSync, `session2 should be out of sync`);
223
- // assert(session2.targetPosition >= leaderPosition.position, `session2 returned target position of ${session2.targetPosition}`);
224
- // });
225
- // } finally {
226
- // await space1.leave();
227
- // await space2.leave();
228
- // }
229
- // });
230
-
231
- });
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+
6
+ import "mocha";
7
+ import { strict as assert } from "assert";
8
+ import {
9
+ SimulatedBroadcastHub,
10
+ SimulatedCollaborationSpace,
11
+ IParticipant,
12
+ ParticipantRole,
13
+ Deferred,
14
+ } from "@microsoft/teams-collaboration";
15
+ import { ExtendedMediaMetadata } from "./MediaSessionExtensions";
16
+ import { ICurrentPlaybackPosition } from "./coordinatorState";
17
+ import { TestMediaSession } from "./SharedMediaSession.spec";
18
+
19
+ describe("SharedMediaSessionCoordinator", () => {
20
+ const user1: IParticipant = {
21
+ participantId: "user1",
22
+ role: ParticipantRole.organizer,
23
+ };
24
+ const user2: IParticipant = {
25
+ participantId: "user2",
26
+ role: ParticipantRole.participant,
27
+ };
28
+ const testTrack: ExtendedMediaMetadata = {
29
+ trackIdentifier: "https://example.org/test.mp3",
30
+ title: "Test Title",
31
+ album: "Test Album",
32
+ artist: "The Testers",
33
+ artwork: [],
34
+ };
35
+ const leaderPosition: Partial<ICurrentPlaybackPosition> = {
36
+ playbackState: "playing",
37
+ position: 25.0,
38
+ duration: 600.0,
39
+ };
40
+
41
+ const laggerPosition: Partial<ICurrentPlaybackPosition> = {
42
+ playbackState: "playing",
43
+ position: 20.0,
44
+ duration: 600.0,
45
+ };
46
+
47
+ it('should send "joined" event when joined.', async () => {
48
+ const hub = new SimulatedBroadcastHub();
49
+ const space1 = new SimulatedCollaborationSpace(user1, hub);
50
+ const space2 = new SimulatedCollaborationSpace(user2, hub);
51
+
52
+ try {
53
+ let cnt = 0;
54
+ const session = new TestMediaSession(space1);
55
+ await space2.join();
56
+ space2.socket.addBroadcastListener(
57
+ session.name,
58
+ "joined",
59
+ async (event) => {
60
+ cnt++;
61
+ }
62
+ );
63
+
64
+ await space1.join();
65
+ assert(cnt == 1, `joined event not sent`);
66
+ } finally {
67
+ await space1.leave();
68
+ await space2.leave();
69
+ }
70
+ });
71
+
72
+ it('should send "positionUpdate" event regularly.', async () => {
73
+ const hub = new SimulatedBroadcastHub();
74
+ const space1 = new SimulatedCollaborationSpace(user1, hub);
75
+ const space2 = new SimulatedCollaborationSpace(user2, hub);
76
+
77
+ try {
78
+ let cnt = 0;
79
+ const done = new Deferred();
80
+ const session = new TestMediaSession(space1, testTrack);
81
+ session.coordinator.positionUpdateInterval = 0.02;
82
+ await space2.join();
83
+ space2.socket.addBroadcastListener(
84
+ session.name,
85
+ "positionUpdate",
86
+ async (event) => {
87
+ cnt++;
88
+ if (cnt > 1) {
89
+ done.resolve();
90
+ }
91
+ }
92
+ );
93
+
94
+ await session.coordinator.join();
95
+ await session.coordinator.play();
96
+ await done.promise;
97
+ } finally {
98
+ await space1.leave();
99
+ await space2.leave();
100
+ }
101
+ });
102
+
103
+ it('should broadcast "play" transport command.', async () => {
104
+ const hub = new SimulatedBroadcastHub();
105
+ const space1 = new SimulatedCollaborationSpace(user1, hub);
106
+ const space2 = new SimulatedCollaborationSpace(user2, hub);
107
+
108
+ try {
109
+ const session1 = new TestMediaSession(space1, testTrack);
110
+ const session2 = new TestMediaSession(space2, testTrack);
111
+
112
+ await space1.join();
113
+ await space2.join();
114
+
115
+ // Listen for action
116
+ const done = new Deferred();
117
+
118
+ // Start playback
119
+ await session1.coordinator.play();
120
+
121
+ // Wait for action to be broadcast
122
+ await session2.waitForAction(async (details) => {
123
+ assert(details.action == "play", `wrong action received`);
124
+ });
125
+ } finally {
126
+ await space1.leave();
127
+ await space2.leave();
128
+ }
129
+ });
130
+
131
+ it('should broadcast "pause" transport command.', async () => {
132
+ const hub = new SimulatedBroadcastHub();
133
+ const space1 = new SimulatedCollaborationSpace(user1, hub);
134
+ const space2 = new SimulatedCollaborationSpace(user2, hub);
135
+
136
+ try {
137
+ const session1 = new TestMediaSession(space1, testTrack);
138
+ const session2 = new TestMediaSession(space2, testTrack);
139
+
140
+ await session1.coordinator.join();
141
+ await space2.join();
142
+
143
+ // Start playback
144
+ await session1.coordinator.play();
145
+
146
+ // Wait for action to be broadcast
147
+ await session2.waitForAction(async (details) => {
148
+ assert(details.action == "play", `didn't start playback`);
149
+
150
+ // Pause playback
151
+ await session1.coordinator.pause();
152
+ await session2.waitForAction(async (details) => {
153
+ assert(details.action == "pause", `didn't pause playback`);
154
+ });
155
+ });
156
+ } finally {
157
+ await space1.leave();
158
+ await space2.leave();
159
+ }
160
+ });
161
+
162
+ it('should broadcast "seekTo" transport command.', async () => {
163
+ const hub = new SimulatedBroadcastHub();
164
+ const space1 = new SimulatedCollaborationSpace(user1, hub);
165
+ const space2 = new SimulatedCollaborationSpace(user2, hub);
166
+
167
+ try {
168
+ const session1 = new TestMediaSession(space1, testTrack);
169
+ const session2 = new TestMediaSession(space2, testTrack);
170
+
171
+ await session1.coordinator.join();
172
+ await space2.join();
173
+
174
+ // Start playback
175
+ await session1.coordinator.play();
176
+
177
+ // Wait for action to be broadcast
178
+ await session2.waitForAction(async (details) => {
179
+ assert(details.action == "play", `didn't start playback`);
180
+
181
+ // Seek to position
182
+ await session1.coordinator.seekTo(2.3);
183
+ await session2.waitForAction(async (details) => {
184
+ assert(
185
+ details.action == "seekto",
186
+ `wong action received "${details.action}"`
187
+ );
188
+ assert(
189
+ details.seekTime >= 2.3,
190
+ `wrong seek position "${details.seekTime}"`
191
+ );
192
+ });
193
+ });
194
+ } finally {
195
+ await space1.leave();
196
+ await space2.leave();
197
+ }
198
+ });
199
+
200
+ it('should broadcast "setTrack" transport command.', async () => {
201
+ const hub = new SimulatedBroadcastHub();
202
+ const space1 = new SimulatedCollaborationSpace(user1, hub);
203
+ const space2 = new SimulatedCollaborationSpace(user2, hub);
204
+
205
+ try {
206
+ const session1 = new TestMediaSession(space1);
207
+ const session2 = new TestMediaSession(space2);
208
+
209
+ await space1.join();
210
+ await space2.join();
211
+
212
+ // Change tracks
213
+ await session1.coordinator.setTrack(testTrack);
214
+
215
+ // Wait for action to be broadcast
216
+ await session2.waitForAction(async (details) => {
217
+ assert(
218
+ details.action == "settrack",
219
+ `wrong action received "${details.action}"`
220
+ );
221
+ assert(
222
+ JSON.stringify(session1.metadata) ==
223
+ JSON.stringify(testTrack),
224
+ `session1 has wrong track: ${JSON.stringify(
225
+ session1.metadata
226
+ )}`
227
+ );
228
+ assert(
229
+ JSON.stringify(session2.metadata) ==
230
+ JSON.stringify(testTrack),
231
+ `session2 has wrong track: ${JSON.stringify(
232
+ session2.metadata
233
+ )}`
234
+ );
235
+ });
236
+ } finally {
237
+ await space1.leave();
238
+ await space2.leave();
239
+ }
240
+ });
241
+
242
+ // it('should trigger "catchup" action.', async () => {
243
+ // const hub = new SimulatedBroadcastHub();
244
+ // const space1 = new SimulatedCollaborationSpace(user1, hub);
245
+ // const space2 = new SimulatedCollaborationSpace(user2, hub);
246
+
247
+ // try {
248
+ // const session1 = new TestMediaSession(testTrack, leaderPosition);
249
+ // const session1.coordinator = new SharedMediaSessionCoordinator(space1, session1, session1.name);
250
+ // session1.coordinator.positionUpdateInterval = 0.02;
251
+ // const session2 = new TestMediaSession(testTrack, laggerPosition);
252
+ // const coordinator2 = new SharedMediaSessionCoordinator(space2, session2, session2.name);
253
+ // coordinator2.positionUpdateInterval = 0.02;
254
+
255
+ // await session1.coordinator.join();
256
+ // await coordinator2.join();
257
+
258
+ // await session1.coordinator.play();
259
+
260
+ // // Wait for action to be broadcast
261
+ // session2.reset();
262
+ // await session2.waitForAction(async () => {
263
+ // assert(session2.isOutOfSync, `session2 should be out of sync`);
264
+ // assert(session2.targetPosition >= leaderPosition.position, `session2 returned target position of ${session2.targetPosition}`);
265
+ // });
266
+ // } finally {
267
+ // await space1.leave();
268
+ // await space2.leave();
269
+ // }
270
+ // });
271
+ });