@microsoft/live-share-media 1.0.0-preview.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/README.md +1 -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 +121 -69
- 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 +317 -146
- 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,12 +3,14 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { ExtendedMediaSessionActionDetails } from
|
|
6
|
+
import { ExtendedMediaSessionActionDetails } from "./MediaSessionExtensions";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Base class for action throttlers.
|
|
10
10
|
*/
|
|
11
11
|
export abstract class MediaSessionActionThrottler {
|
|
12
|
-
public abstract throttled(
|
|
12
|
+
public abstract throttled(
|
|
13
|
+
details: ExtendedMediaSessionActionDetails,
|
|
14
|
+
handler?: MediaSessionActionHandler
|
|
15
|
+
): void;
|
|
13
16
|
}
|
|
14
|
-
|
|
@@ -11,13 +11,23 @@ export interface MediaSessionCoordinatorSuspension {
|
|
|
11
11
|
export type MediaSessionCoordinatorState = "closed" | "waiting" | "joined";
|
|
12
12
|
|
|
13
13
|
export enum MediaSessionCoordinatorEvents {
|
|
14
|
-
coordinatorstatechange =
|
|
15
|
-
triggeraction =
|
|
14
|
+
coordinatorstatechange = "coordinatorstatechange",
|
|
15
|
+
triggeraction = "triggeraction",
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export type ExtendedMediaSessionAction =
|
|
18
|
+
export type ExtendedMediaSessionAction =
|
|
19
|
+
| MediaSessionAction
|
|
20
|
+
| "settrack"
|
|
21
|
+
| "wait"
|
|
22
|
+
| "catchup"
|
|
23
|
+
| "datachange"
|
|
24
|
+
| "blocked";
|
|
19
25
|
|
|
20
|
-
export type ExtendedMediaSessionPlaybackState =
|
|
26
|
+
export type ExtendedMediaSessionPlaybackState =
|
|
27
|
+
| MediaSessionPlaybackState
|
|
28
|
+
| "suspended"
|
|
29
|
+
| "waiting"
|
|
30
|
+
| "ended";
|
|
21
31
|
|
|
22
32
|
export interface ExtendedMediaMetadata extends MediaMetadata {
|
|
23
33
|
trackIdentifier: string;
|
|
@@ -30,7 +40,7 @@ export interface CoordinationWaitPoint {
|
|
|
30
40
|
maxClients?: number;
|
|
31
41
|
}
|
|
32
42
|
|
|
33
|
-
export interface ExtendedMediaSessionActionDetails
|
|
43
|
+
export interface ExtendedMediaSessionActionDetails {
|
|
34
44
|
action: ExtendedMediaSessionAction;
|
|
35
45
|
fastSeek?: boolean | null;
|
|
36
46
|
seekOffset?: number | null;
|
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { TimeInterval } from
|
|
7
|
-
import { MediaSessionActionThrottler } from
|
|
8
|
-
import {
|
|
6
|
+
import { TimeInterval } from "@microsoft/live-share";
|
|
7
|
+
import { MediaSessionActionThrottler } from "./MediaSessionActionThrottler";
|
|
8
|
+
import {
|
|
9
|
+
ExtendedMediaSessionActionDetails,
|
|
10
|
+
ExtendedMediaSessionAction,
|
|
11
|
+
} from "./MediaSessionExtensions";
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* A Throttler that passes through all actions but will only let an action be repeated once every 2 seconds.
|
|
12
15
|
*/
|
|
13
16
|
export class RepeatedActionThrottler extends MediaSessionActionThrottler {
|
|
14
|
-
private static FILTERED_ACTIONS: ExtendedMediaSessionAction[] = [
|
|
17
|
+
private static FILTERED_ACTIONS: ExtendedMediaSessionAction[] = [
|
|
18
|
+
"play",
|
|
19
|
+
"pause",
|
|
20
|
+
"seekto",
|
|
21
|
+
"catchup",
|
|
22
|
+
];
|
|
15
23
|
private _repeatInterval = new TimeInterval(2000);
|
|
16
24
|
private _lastActionSentTime?: number;
|
|
17
25
|
private _lastActionSent?: string;
|
|
@@ -24,13 +32,23 @@ export class RepeatedActionThrottler extends MediaSessionActionThrottler {
|
|
|
24
32
|
this._repeatInterval.seconds = value;
|
|
25
33
|
}
|
|
26
34
|
|
|
27
|
-
public throttled(
|
|
35
|
+
public throttled(
|
|
36
|
+
details: ExtendedMediaSessionActionDetails,
|
|
37
|
+
handler?: MediaSessionActionHandler
|
|
38
|
+
): void {
|
|
28
39
|
if (handler) {
|
|
29
|
-
if (
|
|
40
|
+
if (
|
|
41
|
+
RepeatedActionThrottler.FILTERED_ACTIONS.indexOf(
|
|
42
|
+
details.action
|
|
43
|
+
) >= 0
|
|
44
|
+
) {
|
|
30
45
|
const changeKey = this.getChangeKey(details);
|
|
31
46
|
const now = new Date().getTime();
|
|
32
47
|
if (this._lastActionSent && changeKey == this._lastActionSent) {
|
|
33
|
-
if (
|
|
48
|
+
if (
|
|
49
|
+
now - this._lastActionSentTime! >=
|
|
50
|
+
this._repeatInterval.milliseconds
|
|
51
|
+
) {
|
|
34
52
|
handler(details as MediaSessionActionDetails);
|
|
35
53
|
this._lastActionSentTime = now;
|
|
36
54
|
}
|
|
@@ -47,10 +65,10 @@ export class RepeatedActionThrottler extends MediaSessionActionThrottler {
|
|
|
47
65
|
|
|
48
66
|
private getChangeKey(details: ExtendedMediaSessionActionDetails): string {
|
|
49
67
|
switch (details.action) {
|
|
50
|
-
case
|
|
68
|
+
case "seekto":
|
|
51
69
|
return `seekto:${details.seekTime}`;
|
|
52
70
|
default:
|
|
53
71
|
return details.action;
|
|
54
72
|
}
|
|
55
73
|
}
|
|
56
|
-
}
|
|
74
|
+
}
|
package/src/VolumeManager.ts
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { TimeInterval } from
|
|
7
|
-
import { IMediaPlayer } from
|
|
6
|
+
import { TimeInterval } from "@microsoft/live-share";
|
|
7
|
+
import { IMediaPlayer } from "./IMediaPlayer";
|
|
8
8
|
|
|
9
|
-
export enum LimitLevelType {
|
|
9
|
+
export enum LimitLevelType {
|
|
10
|
+
fixed,
|
|
11
|
+
percentage,
|
|
12
|
+
}
|
|
10
13
|
|
|
11
14
|
/**
|
|
12
15
|
* Smooth audio level changes when volume is modified, or if volume limiting has started/ended.
|
|
@@ -18,7 +21,7 @@ export class VolumeManager {
|
|
|
18
21
|
// defaults to player volume
|
|
19
22
|
private _volume = 0.0;
|
|
20
23
|
private _isLimiting = false;
|
|
21
|
-
private _limitLevel = 0.1
|
|
24
|
+
private _limitLevel = 0.1;
|
|
22
25
|
private _limitLevelType: LimitLevelType = LimitLevelType.fixed;
|
|
23
26
|
private _startTime = 0;
|
|
24
27
|
private _startVolume = 0;
|
|
@@ -44,7 +47,9 @@ export class VolumeManager {
|
|
|
44
47
|
|
|
45
48
|
public set volume(value: number) {
|
|
46
49
|
if (value < 0 || value > 1.0) {
|
|
47
|
-
throw new Error(
|
|
50
|
+
throw new Error(
|
|
51
|
+
`VolumeManager: cannot set volume to ${value}. Level must be between 0.0 and 1.0.`
|
|
52
|
+
);
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
this._volume = value;
|
|
@@ -71,7 +76,9 @@ export class VolumeManager {
|
|
|
71
76
|
|
|
72
77
|
public set limitLevel(value: number) {
|
|
73
78
|
if (value < 0 || value > 1.0) {
|
|
74
|
-
throw new Error(
|
|
79
|
+
throw new Error(
|
|
80
|
+
`VolumeManager: cannot set level to ${value}. Level must be between 0.0 and 1.0.`
|
|
81
|
+
);
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
this._limitLevel = value;
|
|
@@ -130,19 +137,22 @@ export class VolumeManager {
|
|
|
130
137
|
private startAdjusting() {
|
|
131
138
|
const adjustVolume = () => {
|
|
132
139
|
// Schedule next animation frame if volume change not finished
|
|
133
|
-
if (
|
|
140
|
+
if (
|
|
141
|
+
this.millisSinceVolumeChangeStart() <=
|
|
142
|
+
this._volumeChangeDuration.milliseconds
|
|
143
|
+
) {
|
|
134
144
|
this._player.volume = this.computeInterpolatedVolume();
|
|
135
145
|
this.scheduleAnimationFrame(adjustVolume);
|
|
136
146
|
} else {
|
|
137
147
|
this._player.volume = this.computeTargetVolume();
|
|
138
148
|
this._running = false;
|
|
139
149
|
}
|
|
140
|
-
}
|
|
150
|
+
};
|
|
141
151
|
|
|
142
152
|
this._startTime = new Date().getTime();
|
|
143
153
|
this._startVolume = this._player.volume;
|
|
144
154
|
if (!this._running) {
|
|
145
|
-
this._running = true
|
|
155
|
+
this._running = true;
|
|
146
156
|
this.scheduleAnimationFrame(adjustVolume);
|
|
147
157
|
}
|
|
148
158
|
}
|
|
@@ -156,9 +166,11 @@ export class VolumeManager {
|
|
|
156
166
|
}
|
|
157
167
|
|
|
158
168
|
private computeInterpolatedVolume(): number {
|
|
159
|
-
const volumeChangeMillis = this._volumeChangeDuration.milliseconds
|
|
160
|
-
const volumeDifference = this.computeTargetVolume() - this._startVolume
|
|
161
|
-
const adjustmentFromStart =
|
|
169
|
+
const volumeChangeMillis = this._volumeChangeDuration.milliseconds;
|
|
170
|
+
const volumeDifference = this.computeTargetVolume() - this._startVolume;
|
|
171
|
+
const adjustmentFromStart =
|
|
172
|
+
(volumeDifference / volumeChangeMillis) *
|
|
173
|
+
this.millisSinceVolumeChangeStart();
|
|
162
174
|
return this._startVolume + adjustmentFromStart;
|
|
163
175
|
}
|
|
164
176
|
|
package/src/index.ts
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
* Licensed under the Microsoft Live Share SDK License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from './VolumeManager';
|
|
6
|
+
export * from "./LiveMediaSession";
|
|
7
|
+
export * from "./LiveMediaSessionCoordinator";
|
|
8
|
+
export * from "./LiveMediaSessionCoordinatorSuspension";
|
|
9
|
+
export * from "./IMediaPlayer";
|
|
10
|
+
export * from "./MediaPlayerSynchronizer";
|
|
11
|
+
export * from "./MediaSessionActionThrottler";
|
|
12
|
+
export * from "./MediaSessionExtensions";
|
|
13
|
+
export * from "./RepeatedActionThrottler";
|
|
14
|
+
export * from "./VolumeManager";
|