@microsoft/live-share-media 1.0.0-preview.12 → 1.0.0-preview.13
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 +1 -1
- package/bin/IMediaPlayer.d.ts +20 -20
- package/bin/IMediaPlayer.js +6 -6
- package/bin/LiveMediaSession.d.ts +95 -94
- package/bin/LiveMediaSession.d.ts.map +1 -1
- package/bin/LiveMediaSession.js +235 -231
- package/bin/LiveMediaSession.js.map +1 -1
- package/bin/LiveMediaSessionCoordinator.d.ts +238 -227
- package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -1
- package/bin/LiveMediaSessionCoordinator.js +476 -407
- package/bin/LiveMediaSessionCoordinator.js.map +1 -1
- package/bin/LiveMediaSessionCoordinatorSuspension.d.ts +19 -19
- package/bin/LiveMediaSessionCoordinatorSuspension.js +27 -27
- package/bin/MediaPlayerSynchronizer.d.ts +173 -163
- package/bin/MediaPlayerSynchronizer.d.ts.map +1 -1
- package/bin/MediaPlayerSynchronizer.js +491 -468
- package/bin/MediaPlayerSynchronizer.js.map +1 -1
- package/bin/MediaSessionActionThrottler.d.ts +11 -11
- package/bin/MediaSessionActionThrottler.js +13 -13
- package/bin/MediaSessionExtensions.d.ts +34 -34
- package/bin/MediaSessionExtensions.d.ts.map +1 -1
- package/bin/MediaSessionExtensions.js +12 -12
- package/bin/RepeatedActionThrottler.d.ts +19 -19
- package/bin/RepeatedActionThrottler.js +62 -62
- package/bin/RepeatedActionThrottler.js.map +1 -1
- package/bin/VolumeManager.d.ts +83 -83
- package/bin/VolumeManager.js +174 -174
- package/bin/index.d.ts +13 -13
- package/bin/index.js +29 -29
- package/bin/internals/GroupCoordinatorState.d.ts +93 -92
- package/bin/internals/GroupCoordinatorState.d.ts.map +1 -1
- package/bin/internals/GroupCoordinatorState.js +407 -404
- package/bin/internals/GroupCoordinatorState.js.map +1 -1
- package/bin/internals/GroupPlaybackPosition.d.ts +67 -66
- package/bin/internals/GroupPlaybackPosition.d.ts.map +1 -1
- package/bin/internals/GroupPlaybackPosition.js +166 -166
- package/bin/internals/GroupPlaybackPosition.js.map +1 -1
- package/bin/internals/GroupPlaybackTrack.d.ts +45 -45
- package/bin/internals/GroupPlaybackTrack.d.ts.map +1 -1
- package/bin/internals/GroupPlaybackTrack.js +121 -121
- package/bin/internals/GroupPlaybackTrackData.d.ts +39 -39
- package/bin/internals/GroupPlaybackTrackData.d.ts.map +1 -1
- package/bin/internals/GroupPlaybackTrackData.js +69 -69
- package/bin/internals/GroupTransportState.d.ts +49 -48
- package/bin/internals/GroupTransportState.d.ts.map +1 -1
- package/bin/internals/GroupTransportState.js +111 -111
- package/bin/internals/GroupTransportState.js.map +1 -1
- package/bin/internals/consts.d.ts +75 -72
- package/bin/internals/consts.d.ts.map +1 -1
- package/bin/internals/consts.js +84 -81
- package/bin/internals/consts.js.map +1 -1
- package/bin/internals/index.d.ts +10 -10
- package/bin/internals/index.js +26 -26
- package/package.json +4 -4
- package/src/LiveMediaSession.ts +24 -12
- package/src/LiveMediaSessionCoordinator.ts +101 -29
- package/src/MediaPlayerSynchronizer.ts +30 -14
- package/src/internals/GroupCoordinatorState.ts +49 -35
- package/src/internals/GroupPlaybackPosition.ts +6 -2
- package/src/internals/GroupPlaybackTrack.ts +2 -2
- package/src/internals/GroupPlaybackTrackData.ts +2 -2
- package/src/internals/GroupTransportState.ts +11 -4
- package/src/internals/consts.ts +4 -0
- package/src/test/GroupPlaybackPosition.spec.ts +0 -600
- package/src/test/GroupPlaybackTrack.spec.ts +0 -122
- package/src/test/SharedMediaSession.spec.ts +0 -149
- package/src/test/SharedMediaSessionCoordinator.spec.ts +0 -271
- package/src/test/VolumeManager.spec.ts +0 -219
|
@@ -1,122 +0,0 @@
|
|
|
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
|
-
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";
|
|
19
|
-
|
|
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
|
-
};
|
|
29
|
-
|
|
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;
|
|
38
|
-
|
|
39
|
-
it('should fire "trackChange" event when no media', async () => {
|
|
40
|
-
const done = new Deferred();
|
|
41
|
-
const playbackTrack = new GroupPlaybackTrack(() => null);
|
|
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
|
-
}
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
await playbackTrack.updateTrack({
|
|
59
|
-
metadata: track1,
|
|
60
|
-
waitPoints: [],
|
|
61
|
-
timestamp: 1,
|
|
62
|
-
socketId: "a",
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
await done.promise;
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("should switch tracks", async () => {
|
|
69
|
-
let cnt = 0;
|
|
70
|
-
let metadata: ExtendedMediaMetadata = null;
|
|
71
|
-
const playbackTrack = new GroupPlaybackTrack(() => metadata);
|
|
72
|
-
playbackTrack.addEventListener(
|
|
73
|
-
GroupPlaybackTrackEvents.trackChange,
|
|
74
|
-
(event: ITrackChangeEvent) => {
|
|
75
|
-
cnt++;
|
|
76
|
-
metadata = event.metadata;
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
|
|
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
|
-
});
|
|
92
|
-
assert(cnt == 2, `called trackChange event ${cnt} times`);
|
|
93
|
-
assert(metadata.trackIdentifier == "track2", `wrong track set`);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should ignore track changes with older timestamps", async () => {
|
|
97
|
-
let cnt = 0;
|
|
98
|
-
let metadata: ExtendedMediaMetadata = null;
|
|
99
|
-
const playbackTrack = new GroupPlaybackTrack(() => metadata);
|
|
100
|
-
playbackTrack.addEventListener(
|
|
101
|
-
GroupPlaybackTrackEvents.trackChange,
|
|
102
|
-
(event: ITrackChangeEvent) => {
|
|
103
|
-
cnt++;
|
|
104
|
-
metadata = event.metadata;
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
|
|
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
|
-
});
|
|
120
|
-
assert(cnt == 1, `called trackChange event ${cnt} times`);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
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
|
-
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";
|
|
19
|
-
|
|
20
|
-
export class TestMediaSession extends SharedMediaSession {
|
|
21
|
-
private done = new Deferred<ExtendedMediaSessionActionDetails>();
|
|
22
|
-
private space: CollaborationSpace;
|
|
23
|
-
private playbackTimer: any;
|
|
24
|
-
private playbackStarted: number = 0;
|
|
25
|
-
private playbackPosition: number = 0.0;
|
|
26
|
-
|
|
27
|
-
constructor(
|
|
28
|
-
space: CollaborationSpace,
|
|
29
|
-
metadata?: ExtendedMediaMetadata | null,
|
|
30
|
-
playbackState?: MediaSessionPlaybackState,
|
|
31
|
-
positionState?: LastMediaPositionState
|
|
32
|
-
) {
|
|
33
|
-
super(space);
|
|
34
|
-
this.space = space;
|
|
35
|
-
if (metadata) {
|
|
36
|
-
this.metadata = metadata;
|
|
37
|
-
}
|
|
38
|
-
if (playbackState) {
|
|
39
|
-
this.playbackState = playbackState;
|
|
40
|
-
}
|
|
41
|
-
if (positionState) {
|
|
42
|
-
this.playbackPosition =
|
|
43
|
-
positionState.position != undefined
|
|
44
|
-
? positionState.position
|
|
45
|
-
: 0.0;
|
|
46
|
-
this.duration = positionState.duration;
|
|
47
|
-
this.playbackRate =
|
|
48
|
-
positionState.playbackRate != undefined
|
|
49
|
-
? positionState.playbackRate
|
|
50
|
-
: 1;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.setActionHandler("play", (details) => {
|
|
54
|
-
this.play();
|
|
55
|
-
this.done.resolve(details);
|
|
56
|
-
});
|
|
57
|
-
this.setActionHandler("pause", (details) => {
|
|
58
|
-
this.pause();
|
|
59
|
-
this.done.resolve(details);
|
|
60
|
-
});
|
|
61
|
-
this.setActionHandler("seekto", (details) => {
|
|
62
|
-
this.currentTime = details.seekTime;
|
|
63
|
-
this.done.resolve(details);
|
|
64
|
-
});
|
|
65
|
-
this.setActionHandler("settrack", (details) => {
|
|
66
|
-
this.done.resolve(details);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
this.space.addEventListener(CollaborationSpaceEvents.leftSpace, () => {
|
|
70
|
-
if (this.playbackTimer) {
|
|
71
|
-
clearInterval(this.playbackTimer);
|
|
72
|
-
this.playbackTimer = undefined;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public duration?: number;
|
|
78
|
-
public playbackRate: number = 1;
|
|
79
|
-
|
|
80
|
-
public get playing(): boolean {
|
|
81
|
-
return this.playbackState == "playing";
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public get paused(): boolean {
|
|
85
|
-
return this.playbackState != "playing";
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public get currentTime(): number {
|
|
89
|
-
if (this.playbackState == "playing") {
|
|
90
|
-
const now = this.space.clock.getTime();
|
|
91
|
-
return this.playbackPosition + (now - this.playbackStarted) / 1000;
|
|
92
|
-
} else {
|
|
93
|
-
return this.playbackPosition;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public set currentTime(value: number) {
|
|
98
|
-
const startState = this.playbackState;
|
|
99
|
-
this.pause();
|
|
100
|
-
this.playbackPosition = value;
|
|
101
|
-
if (startState == "playing") {
|
|
102
|
-
this.play();
|
|
103
|
-
} else {
|
|
104
|
-
this.setPositionState({
|
|
105
|
-
position: this.currentTime,
|
|
106
|
-
duration: this.duration,
|
|
107
|
-
playbackRate: this.playbackRate,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public play(): void {
|
|
113
|
-
if (this.playbackState != "playing") {
|
|
114
|
-
this.playbackStarted = this.space.clock.getTime();
|
|
115
|
-
this.playbackState = "playing";
|
|
116
|
-
this.playbackTimer = setInterval(() => {
|
|
117
|
-
this.playbackState = "playing";
|
|
118
|
-
this.setPositionState({
|
|
119
|
-
position: this.currentTime,
|
|
120
|
-
duration: this.duration,
|
|
121
|
-
playbackRate: this.playbackRate,
|
|
122
|
-
});
|
|
123
|
-
}, 60);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
public pause(): void {
|
|
128
|
-
if (this.playbackTimer) {
|
|
129
|
-
clearInterval(this.playbackTimer);
|
|
130
|
-
this.playbackTimer = undefined;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
this.playbackPosition = this.currentTime;
|
|
134
|
-
this.playbackState = "paused";
|
|
135
|
-
this.setPositionState({
|
|
136
|
-
position: this.currentTime,
|
|
137
|
-
duration: this.duration,
|
|
138
|
-
playbackRate: this.playbackRate,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
public async waitForAction(
|
|
143
|
-
handler: (details: ExtendedMediaSessionActionDetails) => Promise<void>
|
|
144
|
-
): Promise<void> {
|
|
145
|
-
const details = await this.done.promise;
|
|
146
|
-
this.done = new Deferred<ExtendedMediaSessionActionDetails>();
|
|
147
|
-
await handler(details);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,271 +0,0 @@
|
|
|
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
|
-
});
|