@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.
Files changed (96) hide show
  1. package/README.md +1 -1
  2. package/bin/IMediaPlayer.d.ts.map +1 -1
  3. package/bin/LiveMediaSession.d.ts +7 -7
  4. package/bin/LiveMediaSession.d.ts.map +1 -1
  5. package/bin/LiveMediaSession.js +28 -17
  6. package/bin/LiveMediaSession.js.map +1 -1
  7. package/bin/LiveMediaSessionCoordinator.d.ts +2 -2
  8. package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -1
  9. package/bin/LiveMediaSessionCoordinator.js +34 -22
  10. package/bin/LiveMediaSessionCoordinator.js.map +1 -1
  11. package/bin/LiveMediaSessionCoordinatorSuspension.d.ts +1 -1
  12. package/bin/LiveMediaSessionCoordinatorSuspension.d.ts.map +1 -1
  13. package/bin/LiveMediaSessionCoordinatorSuspension.js.map +1 -1
  14. package/bin/MediaPlayerSynchronizer.d.ts +7 -7
  15. package/bin/MediaPlayerSynchronizer.d.ts.map +1 -1
  16. package/bin/MediaPlayerSynchronizer.js +121 -69
  17. package/bin/MediaPlayerSynchronizer.js.map +1 -1
  18. package/bin/MediaSessionActionThrottler.d.ts +1 -1
  19. package/bin/MediaSessionActionThrottler.d.ts.map +1 -1
  20. package/bin/MediaSessionActionThrottler.js.map +1 -1
  21. package/bin/MediaSessionExtensions.d.ts.map +1 -1
  22. package/bin/RepeatedActionThrottler.d.ts +2 -2
  23. package/bin/RepeatedActionThrottler.d.ts.map +1 -1
  24. package/bin/RepeatedActionThrottler.js +9 -3
  25. package/bin/RepeatedActionThrottler.js.map +1 -1
  26. package/bin/VolumeManager.d.ts +1 -1
  27. package/bin/VolumeManager.d.ts.map +1 -1
  28. package/bin/VolumeManager.js +4 -2
  29. package/bin/VolumeManager.js.map +1 -1
  30. package/bin/index.d.ts +9 -9
  31. package/bin/index.d.ts.map +1 -1
  32. package/bin/index.js.map +1 -1
  33. package/bin/internals/GroupCoordinatorState.d.ts +8 -8
  34. package/bin/internals/GroupCoordinatorState.d.ts.map +1 -1
  35. package/bin/internals/GroupCoordinatorState.js +91 -53
  36. package/bin/internals/GroupCoordinatorState.js.map +1 -1
  37. package/bin/internals/GroupPlaybackPosition.d.ts +3 -3
  38. package/bin/internals/GroupPlaybackPosition.d.ts.map +1 -1
  39. package/bin/internals/GroupPlaybackPosition.js +22 -13
  40. package/bin/internals/GroupPlaybackPosition.js.map +1 -1
  41. package/bin/internals/GroupPlaybackTrack.d.ts +4 -4
  42. package/bin/internals/GroupPlaybackTrack.d.ts.map +1 -1
  43. package/bin/internals/GroupPlaybackTrack.js +14 -4
  44. package/bin/internals/GroupPlaybackTrack.js.map +1 -1
  45. package/bin/internals/GroupPlaybackTrackData.d.ts +3 -3
  46. package/bin/internals/GroupPlaybackTrackData.d.ts.map +1 -1
  47. package/bin/internals/GroupPlaybackTrackData.js +8 -4
  48. package/bin/internals/GroupPlaybackTrackData.js.map +1 -1
  49. package/bin/internals/GroupTransportState.d.ts +5 -5
  50. package/bin/internals/GroupTransportState.d.ts.map +1 -1
  51. package/bin/internals/GroupTransportState.js +27 -12
  52. package/bin/internals/GroupTransportState.js.map +1 -1
  53. package/bin/internals/consts.d.ts.map +1 -1
  54. package/bin/internals/consts.js +54 -54
  55. package/bin/internals/consts.js.map +1 -1
  56. package/bin/internals/index.d.ts +6 -6
  57. package/package.json +3 -3
  58. package/src/IMediaPlayer.ts +10 -2
  59. package/src/LiveMediaSession.ts +133 -71
  60. package/src/LiveMediaSessionCoordinator.ts +302 -142
  61. package/src/LiveMediaSessionCoordinatorSuspension.ts +13 -5
  62. package/src/MediaPlayerSynchronizer.ts +317 -146
  63. package/src/MediaSessionActionThrottler.ts +5 -3
  64. package/src/MediaSessionExtensions.ts +15 -5
  65. package/src/RepeatedActionThrottler.ts +27 -9
  66. package/src/VolumeManager.ts +24 -12
  67. package/src/index.ts +9 -10
  68. package/src/internals/GroupCoordinatorState.ts +274 -114
  69. package/src/internals/GroupPlaybackPosition.ts +61 -27
  70. package/src/internals/GroupPlaybackTrack.ts +51 -22
  71. package/src/internals/GroupPlaybackTrackData.ts +24 -16
  72. package/src/internals/GroupTransportState.ts +53 -23
  73. package/src/internals/consts.ts +73 -55
  74. package/src/internals/index.ts +6 -6
  75. package/src/test/GroupPlaybackPosition.spec.ts +371 -111
  76. package/src/test/GroupPlaybackTrack.spec.ts +91 -35
  77. package/src/test/SharedMediaSession.spec.ts +64 -28
  78. package/src/test/SharedMediaSessionCoordinator.spec.ts +86 -46
  79. package/src/test/VolumeManager.spec.ts +38 -31
  80. package/tsconfig.json +1 -0
  81. package/bin/EphemeralMediaSession.d.ts +0 -102
  82. package/bin/EphemeralMediaSession.d.ts.map +0 -1
  83. package/bin/EphemeralMediaSession.js +0 -226
  84. package/bin/EphemeralMediaSession.js.map +0 -1
  85. package/bin/EphemeralMediaSessionCoordinator.d.ts +0 -228
  86. package/bin/EphemeralMediaSessionCoordinator.d.ts.map +0 -1
  87. package/bin/EphemeralMediaSessionCoordinator.js +0 -396
  88. package/bin/EphemeralMediaSessionCoordinator.js.map +0 -1
  89. package/bin/EphemeralMediaSessionCoordinatorSuspension.d.ts +0 -20
  90. package/bin/EphemeralMediaSessionCoordinatorSuspension.d.ts.map +0 -1
  91. package/bin/EphemeralMediaSessionCoordinatorSuspension.js +0 -28
  92. package/bin/EphemeralMediaSessionCoordinatorSuspension.js.map +0 -1
  93. package/bin/VolumeLimiter.d.ts +0 -70
  94. package/bin/VolumeLimiter.d.ts.map +0 -1
  95. package/bin/VolumeLimiter.js +0 -170
  96. 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 './MediaSessionExtensions';
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(details: ExtendedMediaSessionActionDetails, handler?: MediaSessionActionHandler): void;
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 = 'coordinatorstatechange',
15
- triggeraction = 'triggeraction'
14
+ coordinatorstatechange = "coordinatorstatechange",
15
+ triggeraction = "triggeraction",
16
16
  }
17
17
 
18
- export type ExtendedMediaSessionAction = MediaSessionAction | "settrack" | "wait" | "catchup" | "datachange" | "blocked";
18
+ export type ExtendedMediaSessionAction =
19
+ | MediaSessionAction
20
+ | "settrack"
21
+ | "wait"
22
+ | "catchup"
23
+ | "datachange"
24
+ | "blocked";
19
25
 
20
- export type ExtendedMediaSessionPlaybackState = MediaSessionPlaybackState | "suspended" | "waiting" | "ended";
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 '@microsoft/live-share';
7
- import { MediaSessionActionThrottler } from './MediaSessionActionThrottler';
8
- import { ExtendedMediaSessionActionDetails, ExtendedMediaSessionAction } from './MediaSessionExtensions';
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[] = ['play', 'pause', 'seekto', 'catchup'];
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(details: ExtendedMediaSessionActionDetails, handler?: MediaSessionActionHandler): void {
35
+ public throttled(
36
+ details: ExtendedMediaSessionActionDetails,
37
+ handler?: MediaSessionActionHandler
38
+ ): void {
28
39
  if (handler) {
29
- if (RepeatedActionThrottler.FILTERED_ACTIONS.indexOf(details.action) >= 0) {
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 (now - this._lastActionSentTime! >= this._repeatInterval.milliseconds) {
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 'seekto':
68
+ case "seekto":
51
69
  return `seekto:${details.seekTime}`;
52
70
  default:
53
71
  return details.action;
54
72
  }
55
73
  }
56
- }
74
+ }
@@ -3,10 +3,13 @@
3
3
  * Licensed under the Microsoft Live Share SDK License.
4
4
  */
5
5
 
6
- import { TimeInterval } from '@microsoft/live-share';
7
- import { IMediaPlayer } from './IMediaPlayer';
6
+ import { TimeInterval } from "@microsoft/live-share";
7
+ import { IMediaPlayer } from "./IMediaPlayer";
8
8
 
9
- export enum LimitLevelType { fixed, percentage }
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(`VolumeManager: cannot set volume to ${value}. Level must be between 0.0 and 1.0.`);
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(`VolumeManager: cannot set level to ${value}. Level must be between 0.0 and 1.0.`);
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 (this.millisSinceVolumeChangeStart() <= this._volumeChangeDuration.milliseconds) {
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 = volumeDifference / volumeChangeMillis * this.millisSinceVolumeChangeStart()
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 './LiveMediaSession';
8
- export * from './LiveMediaSessionCoordinator';
9
- export * from './LiveMediaSessionCoordinatorSuspension';
10
- export * from './IMediaPlayer';
11
- export * from './MediaPlayerSynchronizer';
12
- export * from './MediaSessionActionThrottler';
13
- export * from './MediaSessionExtensions';
14
- export * from './RepeatedActionThrottler';
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";