@microsoft/live-share-media 1.0.0-preview.1 → 1.0.0-preview.4
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 +2 -1
- package/bin/IMediaPlayer.d.ts.map +1 -1
- package/bin/LiveMediaSession.d.ts +7 -7
- package/bin/LiveMediaSession.d.ts.map +1 -1
- package/bin/LiveMediaSession.js +28 -17
- package/bin/LiveMediaSession.js.map +1 -1
- package/bin/LiveMediaSessionCoordinator.d.ts +2 -2
- package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -1
- package/bin/LiveMediaSessionCoordinator.js +34 -22
- package/bin/LiveMediaSessionCoordinator.js.map +1 -1
- package/bin/LiveMediaSessionCoordinatorSuspension.d.ts +1 -1
- package/bin/LiveMediaSessionCoordinatorSuspension.d.ts.map +1 -1
- package/bin/LiveMediaSessionCoordinatorSuspension.js.map +1 -1
- package/bin/MediaPlayerSynchronizer.d.ts +7 -7
- package/bin/MediaPlayerSynchronizer.d.ts.map +1 -1
- package/bin/MediaPlayerSynchronizer.js +127 -72
- 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 +1 -1
- package/bin/VolumeManager.d.ts.map +1 -1
- package/bin/VolumeManager.js +4 -2
- package/bin/VolumeManager.js.map +1 -1
- package/bin/index.d.ts +9 -9
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js.map +1 -1
- package/bin/internals/GroupCoordinatorState.d.ts +8 -8
- package/bin/internals/GroupCoordinatorState.d.ts.map +1 -1
- package/bin/internals/GroupCoordinatorState.js +91 -53
- 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 +22 -13
- 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 +27 -12
- 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 +3 -3
- package/src/IMediaPlayer.ts +10 -2
- package/src/LiveMediaSession.ts +133 -71
- package/src/LiveMediaSessionCoordinator.ts +302 -142
- package/src/LiveMediaSessionCoordinatorSuspension.ts +13 -5
- package/src/MediaPlayerSynchronizer.ts +329 -149
- package/src/MediaSessionActionThrottler.ts +5 -3
- package/src/MediaSessionExtensions.ts +15 -5
- package/src/RepeatedActionThrottler.ts +27 -9
- package/src/VolumeManager.ts +24 -12
- package/src/index.ts +9 -10
- package/src/internals/GroupCoordinatorState.ts +274 -114
- package/src/internals/GroupPlaybackPosition.ts +61 -27
- package/src/internals/GroupPlaybackTrack.ts +51 -22
- package/src/internals/GroupPlaybackTrackData.ts +24 -16
- package/src/internals/GroupTransportState.ts +53 -23
- package/src/internals/consts.ts +73 -55
- package/src/internals/index.ts +6 -6
- package/src/test/GroupPlaybackPosition.spec.ts +371 -111
- package/src/test/GroupPlaybackTrack.spec.ts +91 -35
- package/src/test/SharedMediaSession.spec.ts +64 -28
- package/src/test/SharedMediaSessionCoordinator.spec.ts +86 -46
- package/src/test/VolumeManager.spec.ts +38 -31
- package/tsconfig.json +1 -0
- package/bin/EphemeralMediaSession.d.ts +0 -102
- package/bin/EphemeralMediaSession.d.ts.map +0 -1
- package/bin/EphemeralMediaSession.js +0 -226
- package/bin/EphemeralMediaSession.js.map +0 -1
- package/bin/EphemeralMediaSessionCoordinator.d.ts +0 -228
- package/bin/EphemeralMediaSessionCoordinator.d.ts.map +0 -1
- package/bin/EphemeralMediaSessionCoordinator.js +0 -396
- package/bin/EphemeralMediaSessionCoordinator.js.map +0 -1
- package/bin/EphemeralMediaSessionCoordinatorSuspension.d.ts +0 -20
- package/bin/EphemeralMediaSessionCoordinatorSuspension.d.ts.map +0 -1
- package/bin/EphemeralMediaSessionCoordinatorSuspension.js +0 -28
- 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
|
@@ -3,64 +3,120 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import { strict as assert } from
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
import "mocha";
|
|
7
|
+
import { strict as assert } from "assert";
|
|
8
|
+
import {
|
|
9
|
+
IParticipant,
|
|
10
|
+
ParticipantRole,
|
|
11
|
+
Deferred,
|
|
12
|
+
} from "@microsoft/teams-collaboration";
|
|
13
|
+
import {
|
|
14
|
+
GroupPlaybackTrack,
|
|
15
|
+
GroupPlaybackTrackEvents,
|
|
16
|
+
ITrackChangeEvent,
|
|
17
|
+
} from "../internals/GroupPlaybackTrack";
|
|
18
|
+
import { ExtendedMediaMetadata } from "../MediaSessionExtensions";
|
|
11
19
|
|
|
12
|
-
describe(
|
|
13
|
-
const user1: IParticipant = {
|
|
14
|
-
|
|
20
|
+
describe("GroupPlaybackTrack", () => {
|
|
21
|
+
const user1: IParticipant = {
|
|
22
|
+
participantId: "user1",
|
|
23
|
+
role: ParticipantRole.organizer,
|
|
24
|
+
};
|
|
25
|
+
const user2: IParticipant = {
|
|
26
|
+
participantId: "user2",
|
|
27
|
+
role: ParticipantRole.participant,
|
|
28
|
+
};
|
|
15
29
|
|
|
16
|
-
const track1 = {
|
|
17
|
-
|
|
30
|
+
const track1 = {
|
|
31
|
+
trackIdentifier: "track1",
|
|
32
|
+
title: "Test Track 1",
|
|
33
|
+
} as ExtendedMediaMetadata;
|
|
34
|
+
const track2 = {
|
|
35
|
+
trackIdentifier: "track2",
|
|
36
|
+
title: "Test Track 2",
|
|
37
|
+
} as ExtendedMediaMetadata;
|
|
18
38
|
|
|
19
39
|
it('should fire "trackChange" event when no media', async () => {
|
|
20
40
|
const done = new Deferred();
|
|
21
41
|
const playbackTrack = new GroupPlaybackTrack(() => null);
|
|
22
|
-
playbackTrack.addEventListener(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
playbackTrack.addEventListener(
|
|
43
|
+
GroupPlaybackTrackEvents.trackChange,
|
|
44
|
+
(event: ITrackChangeEvent) => {
|
|
45
|
+
try {
|
|
46
|
+
assert(event.metadata, `no metadata`);
|
|
47
|
+
assert(
|
|
48
|
+
event.metadata.trackIdentifier == "track1",
|
|
49
|
+
`wrong track`
|
|
50
|
+
);
|
|
51
|
+
done.resolve();
|
|
52
|
+
} catch (err) {
|
|
53
|
+
done.reject(err);
|
|
54
|
+
}
|
|
29
55
|
}
|
|
56
|
+
);
|
|
30
57
|
|
|
58
|
+
await playbackTrack.updateTrack({
|
|
59
|
+
metadata: track1,
|
|
60
|
+
waitPoints: [],
|
|
61
|
+
timestamp: 1,
|
|
62
|
+
socketId: "a",
|
|
31
63
|
});
|
|
32
64
|
|
|
33
|
-
await playbackTrack.updateTrack({ metadata: track1, waitPoints: [], timestamp: 1, socketId: 'a'});
|
|
34
|
-
|
|
35
65
|
await done.promise;
|
|
36
66
|
});
|
|
37
67
|
|
|
38
|
-
it(
|
|
68
|
+
it("should switch tracks", async () => {
|
|
39
69
|
let cnt = 0;
|
|
40
70
|
let metadata: ExtendedMediaMetadata = null;
|
|
41
71
|
const playbackTrack = new GroupPlaybackTrack(() => metadata);
|
|
42
|
-
playbackTrack.addEventListener(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
72
|
+
playbackTrack.addEventListener(
|
|
73
|
+
GroupPlaybackTrackEvents.trackChange,
|
|
74
|
+
(event: ITrackChangeEvent) => {
|
|
75
|
+
cnt++;
|
|
76
|
+
metadata = event.metadata;
|
|
77
|
+
}
|
|
78
|
+
);
|
|
46
79
|
|
|
47
|
-
await playbackTrack.updateTrack({
|
|
48
|
-
|
|
80
|
+
await playbackTrack.updateTrack({
|
|
81
|
+
metadata: track1,
|
|
82
|
+
waitPoints: [],
|
|
83
|
+
timestamp: 1,
|
|
84
|
+
socketId: "a",
|
|
85
|
+
});
|
|
86
|
+
await playbackTrack.updateTrack({
|
|
87
|
+
metadata: track2,
|
|
88
|
+
waitPoints: [],
|
|
89
|
+
timestamp: 2,
|
|
90
|
+
socketId: "b",
|
|
91
|
+
});
|
|
49
92
|
assert(cnt == 2, `called trackChange event ${cnt} times`);
|
|
50
|
-
assert(metadata.trackIdentifier ==
|
|
93
|
+
assert(metadata.trackIdentifier == "track2", `wrong track set`);
|
|
51
94
|
});
|
|
52
95
|
|
|
53
|
-
it(
|
|
96
|
+
it("should ignore track changes with older timestamps", async () => {
|
|
54
97
|
let cnt = 0;
|
|
55
98
|
let metadata: ExtendedMediaMetadata = null;
|
|
56
99
|
const playbackTrack = new GroupPlaybackTrack(() => metadata);
|
|
57
|
-
playbackTrack.addEventListener(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
100
|
+
playbackTrack.addEventListener(
|
|
101
|
+
GroupPlaybackTrackEvents.trackChange,
|
|
102
|
+
(event: ITrackChangeEvent) => {
|
|
103
|
+
cnt++;
|
|
104
|
+
metadata = event.metadata;
|
|
105
|
+
}
|
|
106
|
+
);
|
|
61
107
|
|
|
62
|
-
await playbackTrack.updateTrack({
|
|
63
|
-
|
|
108
|
+
await playbackTrack.updateTrack({
|
|
109
|
+
metadata: track1,
|
|
110
|
+
waitPoints: [],
|
|
111
|
+
timestamp: 3,
|
|
112
|
+
socketId: "a",
|
|
113
|
+
});
|
|
114
|
+
await playbackTrack.updateTrack({
|
|
115
|
+
metadata: track2,
|
|
116
|
+
waitPoints: [],
|
|
117
|
+
timestamp: 2,
|
|
118
|
+
socketId: "b",
|
|
119
|
+
});
|
|
64
120
|
assert(cnt == 1, `called trackChange event ${cnt} times`);
|
|
65
121
|
});
|
|
66
|
-
});
|
|
122
|
+
});
|
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import { strict as assert } from
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
import "mocha";
|
|
7
|
+
import { strict as assert } from "assert";
|
|
8
|
+
import {
|
|
9
|
+
CollaborationSpace,
|
|
10
|
+
CollaborationSpaceEvents,
|
|
11
|
+
Deferred,
|
|
12
|
+
} from "@microsoft/teams-collaboration";
|
|
13
|
+
import { LastMediaPositionState } from "../LiveMediaSessionCoordinator";
|
|
14
|
+
import {
|
|
15
|
+
ExtendedMediaMetadata,
|
|
16
|
+
ExtendedMediaSessionActionDetails,
|
|
17
|
+
} from "../MediaSessionExtensions";
|
|
18
|
+
import { SharedMediaSession } from "../LiveMediaSession";
|
|
12
19
|
|
|
13
20
|
export class TestMediaSession extends SharedMediaSession {
|
|
14
21
|
private done = new Deferred<ExtendedMediaSessionActionDetails>();
|
|
@@ -17,30 +24,45 @@ export class TestMediaSession extends SharedMediaSession {
|
|
|
17
24
|
private playbackStarted: number = 0;
|
|
18
25
|
private playbackPosition: number = 0.0;
|
|
19
26
|
|
|
20
|
-
constructor(
|
|
27
|
+
constructor(
|
|
28
|
+
space: CollaborationSpace,
|
|
29
|
+
metadata?: ExtendedMediaMetadata | null,
|
|
30
|
+
playbackState?: MediaSessionPlaybackState,
|
|
31
|
+
positionState?: LastMediaPositionState
|
|
32
|
+
) {
|
|
21
33
|
super(space);
|
|
22
34
|
this.space = space;
|
|
23
|
-
if (metadata) {
|
|
24
|
-
|
|
35
|
+
if (metadata) {
|
|
36
|
+
this.metadata = metadata;
|
|
37
|
+
}
|
|
38
|
+
if (playbackState) {
|
|
39
|
+
this.playbackState = playbackState;
|
|
40
|
+
}
|
|
25
41
|
if (positionState) {
|
|
26
|
-
this.playbackPosition =
|
|
42
|
+
this.playbackPosition =
|
|
43
|
+
positionState.position != undefined
|
|
44
|
+
? positionState.position
|
|
45
|
+
: 0.0;
|
|
27
46
|
this.duration = positionState.duration;
|
|
28
|
-
this.playbackRate =
|
|
47
|
+
this.playbackRate =
|
|
48
|
+
positionState.playbackRate != undefined
|
|
49
|
+
? positionState.playbackRate
|
|
50
|
+
: 1;
|
|
29
51
|
}
|
|
30
52
|
|
|
31
|
-
this.setActionHandler(
|
|
53
|
+
this.setActionHandler("play", (details) => {
|
|
32
54
|
this.play();
|
|
33
55
|
this.done.resolve(details);
|
|
34
56
|
});
|
|
35
|
-
this.setActionHandler(
|
|
57
|
+
this.setActionHandler("pause", (details) => {
|
|
36
58
|
this.pause();
|
|
37
59
|
this.done.resolve(details);
|
|
38
60
|
});
|
|
39
|
-
this.setActionHandler(
|
|
61
|
+
this.setActionHandler("seekto", (details) => {
|
|
40
62
|
this.currentTime = details.seekTime;
|
|
41
63
|
this.done.resolve(details);
|
|
42
64
|
});
|
|
43
|
-
this.setActionHandler(
|
|
65
|
+
this.setActionHandler("settrack", (details) => {
|
|
44
66
|
this.done.resolve(details);
|
|
45
67
|
});
|
|
46
68
|
|
|
@@ -56,17 +78,17 @@ export class TestMediaSession extends SharedMediaSession {
|
|
|
56
78
|
public playbackRate: number = 1;
|
|
57
79
|
|
|
58
80
|
public get playing(): boolean {
|
|
59
|
-
return this.playbackState ==
|
|
81
|
+
return this.playbackState == "playing";
|
|
60
82
|
}
|
|
61
83
|
|
|
62
84
|
public get paused(): boolean {
|
|
63
|
-
return this.playbackState !=
|
|
85
|
+
return this.playbackState != "playing";
|
|
64
86
|
}
|
|
65
87
|
|
|
66
88
|
public get currentTime(): number {
|
|
67
|
-
if (this.playbackState ==
|
|
89
|
+
if (this.playbackState == "playing") {
|
|
68
90
|
const now = this.space.clock.getTime();
|
|
69
|
-
return this.playbackPosition + (
|
|
91
|
+
return this.playbackPosition + (now - this.playbackStarted) / 1000;
|
|
70
92
|
} else {
|
|
71
93
|
return this.playbackPosition;
|
|
72
94
|
}
|
|
@@ -76,20 +98,28 @@ export class TestMediaSession extends SharedMediaSession {
|
|
|
76
98
|
const startState = this.playbackState;
|
|
77
99
|
this.pause();
|
|
78
100
|
this.playbackPosition = value;
|
|
79
|
-
if (startState ==
|
|
101
|
+
if (startState == "playing") {
|
|
80
102
|
this.play();
|
|
81
103
|
} else {
|
|
82
|
-
this.setPositionState({
|
|
104
|
+
this.setPositionState({
|
|
105
|
+
position: this.currentTime,
|
|
106
|
+
duration: this.duration,
|
|
107
|
+
playbackRate: this.playbackRate,
|
|
108
|
+
});
|
|
83
109
|
}
|
|
84
110
|
}
|
|
85
111
|
|
|
86
112
|
public play(): void {
|
|
87
|
-
if (this.playbackState !=
|
|
113
|
+
if (this.playbackState != "playing") {
|
|
88
114
|
this.playbackStarted = this.space.clock.getTime();
|
|
89
|
-
this.playbackState =
|
|
115
|
+
this.playbackState = "playing";
|
|
90
116
|
this.playbackTimer = setInterval(() => {
|
|
91
|
-
this.playbackState =
|
|
92
|
-
this.setPositionState({
|
|
117
|
+
this.playbackState = "playing";
|
|
118
|
+
this.setPositionState({
|
|
119
|
+
position: this.currentTime,
|
|
120
|
+
duration: this.duration,
|
|
121
|
+
playbackRate: this.playbackRate,
|
|
122
|
+
});
|
|
93
123
|
}, 60);
|
|
94
124
|
}
|
|
95
125
|
}
|
|
@@ -101,11 +131,17 @@ export class TestMediaSession extends SharedMediaSession {
|
|
|
101
131
|
}
|
|
102
132
|
|
|
103
133
|
this.playbackPosition = this.currentTime;
|
|
104
|
-
this.playbackState =
|
|
105
|
-
this.setPositionState({
|
|
134
|
+
this.playbackState = "paused";
|
|
135
|
+
this.setPositionState({
|
|
136
|
+
position: this.currentTime,
|
|
137
|
+
duration: this.duration,
|
|
138
|
+
playbackRate: this.playbackRate,
|
|
139
|
+
});
|
|
106
140
|
}
|
|
107
141
|
|
|
108
|
-
public async waitForAction(
|
|
142
|
+
public async waitForAction(
|
|
143
|
+
handler: (details: ExtendedMediaSessionActionDetails) => Promise<void>
|
|
144
|
+
): Promise<void> {
|
|
109
145
|
const details = await this.done.promise;
|
|
110
146
|
this.done = new Deferred<ExtendedMediaSessionActionDetails>();
|
|
111
147
|
await handler(details);
|
|
@@ -3,33 +3,45 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import { strict as assert } from
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
};
|
|
16
28
|
const testTrack: ExtendedMediaMetadata = {
|
|
17
|
-
trackIdentifier:
|
|
18
|
-
title:
|
|
19
|
-
album:
|
|
20
|
-
artist:
|
|
21
|
-
artwork: []
|
|
29
|
+
trackIdentifier: "https://example.org/test.mp3",
|
|
30
|
+
title: "Test Title",
|
|
31
|
+
album: "Test Album",
|
|
32
|
+
artist: "The Testers",
|
|
33
|
+
artwork: [],
|
|
22
34
|
};
|
|
23
35
|
const leaderPosition: Partial<ICurrentPlaybackPosition> = {
|
|
24
|
-
playbackState:
|
|
36
|
+
playbackState: "playing",
|
|
25
37
|
position: 25.0,
|
|
26
|
-
duration: 600.0
|
|
38
|
+
duration: 600.0,
|
|
27
39
|
};
|
|
28
40
|
|
|
29
41
|
const laggerPosition: Partial<ICurrentPlaybackPosition> = {
|
|
30
|
-
playbackState:
|
|
42
|
+
playbackState: "playing",
|
|
31
43
|
position: 20.0,
|
|
32
|
-
duration: 600.0
|
|
44
|
+
duration: 600.0,
|
|
33
45
|
};
|
|
34
46
|
|
|
35
47
|
it('should send "joined" event when joined.', async () => {
|
|
@@ -41,10 +53,14 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
41
53
|
let cnt = 0;
|
|
42
54
|
const session = new TestMediaSession(space1);
|
|
43
55
|
await space2.join();
|
|
44
|
-
space2.socket.addBroadcastListener(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
space2.socket.addBroadcastListener(
|
|
57
|
+
session.name,
|
|
58
|
+
"joined",
|
|
59
|
+
async (event) => {
|
|
60
|
+
cnt++;
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
48
64
|
await space1.join();
|
|
49
65
|
assert(cnt == 1, `joined event not sent`);
|
|
50
66
|
} finally {
|
|
@@ -64,12 +80,16 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
64
80
|
const session = new TestMediaSession(space1, testTrack);
|
|
65
81
|
session.coordinator.positionUpdateInterval = 0.02;
|
|
66
82
|
await space2.join();
|
|
67
|
-
space2.socket.addBroadcastListener(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
space2.socket.addBroadcastListener(
|
|
84
|
+
session.name,
|
|
85
|
+
"positionUpdate",
|
|
86
|
+
async (event) => {
|
|
87
|
+
cnt++;
|
|
88
|
+
if (cnt > 1) {
|
|
89
|
+
done.resolve();
|
|
90
|
+
}
|
|
71
91
|
}
|
|
72
|
-
|
|
92
|
+
);
|
|
73
93
|
|
|
74
94
|
await session.coordinator.join();
|
|
75
95
|
await session.coordinator.play();
|
|
@@ -88,7 +108,7 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
88
108
|
try {
|
|
89
109
|
const session1 = new TestMediaSession(space1, testTrack);
|
|
90
110
|
const session2 = new TestMediaSession(space2, testTrack);
|
|
91
|
-
|
|
111
|
+
|
|
92
112
|
await space1.join();
|
|
93
113
|
await space2.join();
|
|
94
114
|
|
|
@@ -100,7 +120,7 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
100
120
|
|
|
101
121
|
// Wait for action to be broadcast
|
|
102
122
|
await session2.waitForAction(async (details) => {
|
|
103
|
-
assert(details.action ==
|
|
123
|
+
assert(details.action == "play", `wrong action received`);
|
|
104
124
|
});
|
|
105
125
|
} finally {
|
|
106
126
|
await space1.leave();
|
|
@@ -116,7 +136,7 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
116
136
|
try {
|
|
117
137
|
const session1 = new TestMediaSession(space1, testTrack);
|
|
118
138
|
const session2 = new TestMediaSession(space2, testTrack);
|
|
119
|
-
|
|
139
|
+
|
|
120
140
|
await session1.coordinator.join();
|
|
121
141
|
await space2.join();
|
|
122
142
|
|
|
@@ -125,12 +145,12 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
125
145
|
|
|
126
146
|
// Wait for action to be broadcast
|
|
127
147
|
await session2.waitForAction(async (details) => {
|
|
128
|
-
assert(details.action ==
|
|
129
|
-
|
|
148
|
+
assert(details.action == "play", `didn't start playback`);
|
|
149
|
+
|
|
130
150
|
// Pause playback
|
|
131
151
|
await session1.coordinator.pause();
|
|
132
152
|
await session2.waitForAction(async (details) => {
|
|
133
|
-
assert(details.action ==
|
|
153
|
+
assert(details.action == "pause", `didn't pause playback`);
|
|
134
154
|
});
|
|
135
155
|
});
|
|
136
156
|
} finally {
|
|
@@ -147,7 +167,7 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
147
167
|
try {
|
|
148
168
|
const session1 = new TestMediaSession(space1, testTrack);
|
|
149
169
|
const session2 = new TestMediaSession(space2, testTrack);
|
|
150
|
-
|
|
170
|
+
|
|
151
171
|
await session1.coordinator.join();
|
|
152
172
|
await space2.join();
|
|
153
173
|
|
|
@@ -156,13 +176,19 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
156
176
|
|
|
157
177
|
// Wait for action to be broadcast
|
|
158
178
|
await session2.waitForAction(async (details) => {
|
|
159
|
-
assert(details.action ==
|
|
160
|
-
|
|
179
|
+
assert(details.action == "play", `didn't start playback`);
|
|
180
|
+
|
|
161
181
|
// Seek to position
|
|
162
182
|
await session1.coordinator.seekTo(2.3);
|
|
163
183
|
await session2.waitForAction(async (details) => {
|
|
164
|
-
assert(
|
|
165
|
-
|
|
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
|
+
);
|
|
166
192
|
});
|
|
167
193
|
});
|
|
168
194
|
} finally {
|
|
@@ -179,7 +205,7 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
179
205
|
try {
|
|
180
206
|
const session1 = new TestMediaSession(space1);
|
|
181
207
|
const session2 = new TestMediaSession(space2);
|
|
182
|
-
|
|
208
|
+
|
|
183
209
|
await space1.join();
|
|
184
210
|
await space2.join();
|
|
185
211
|
|
|
@@ -188,9 +214,24 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
188
214
|
|
|
189
215
|
// Wait for action to be broadcast
|
|
190
216
|
await session2.waitForAction(async (details) => {
|
|
191
|
-
assert(
|
|
192
|
-
|
|
193
|
-
|
|
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
|
+
);
|
|
194
235
|
});
|
|
195
236
|
} finally {
|
|
196
237
|
await space1.leave();
|
|
@@ -210,7 +251,7 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
210
251
|
// const session2 = new TestMediaSession(testTrack, laggerPosition);
|
|
211
252
|
// const coordinator2 = new SharedMediaSessionCoordinator(space2, session2, session2.name);
|
|
212
253
|
// coordinator2.positionUpdateInterval = 0.02;
|
|
213
|
-
|
|
254
|
+
|
|
214
255
|
// await session1.coordinator.join();
|
|
215
256
|
// await coordinator2.join();
|
|
216
257
|
|
|
@@ -227,5 +268,4 @@ describe('SharedMediaSessionCoordinator', () => {
|
|
|
227
268
|
// await space2.leave();
|
|
228
269
|
// }
|
|
229
270
|
// });
|
|
230
|
-
|
|
231
|
-
});
|
|
271
|
+
});
|