@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
@@ -1,13 +1,13 @@
1
1
  import { strict as assert } from "assert";
2
- import { IMediaPlayer } from "../IMediaPlayer"
3
- import { LimitLevelType, VolumeManager } from "../VolumeManager"
4
- import { Deferred } from '@microsoft/live-share/src/test/Deferred';
2
+ import { IMediaPlayer } from "../IMediaPlayer";
3
+ import { LimitLevelType, VolumeManager } from "../VolumeManager";
4
+ import { Deferred } from "@microsoft/live-share/src/test/Deferred";
5
5
 
6
- describe('VolumeManager', () => {
7
- it('should ramp down volume', async () => {
6
+ describe("VolumeManager", () => {
7
+ it("should ramp down volume", async () => {
8
8
  const testAwait = new Deferred();
9
9
  const player = new TestMediaPlayer();
10
- player.volume = 1.0
10
+ player.volume = 1.0;
11
11
  const volumeManager = new VolumeManager(player);
12
12
 
13
13
  assert(player.volume == 1.0);
@@ -16,7 +16,7 @@ describe('VolumeManager', () => {
16
16
  // check volume at halfway point
17
17
  assert(player.volume > 0.4);
18
18
  assert(player.volume < 0.6);
19
- }, volumeManager.volumeChangeDuration * 1000 / 2);
19
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
20
20
 
21
21
  setTimeout(() => {
22
22
  // check volume at end with 20ms of leeway
@@ -27,10 +27,10 @@ describe('VolumeManager', () => {
27
27
  await testAwait.promise;
28
28
  });
29
29
 
30
- it('should ramp up volume', async () => {
30
+ it("should ramp up volume", async () => {
31
31
  const testAwait = new Deferred();
32
32
  const player = new TestMediaPlayer();
33
- player.volume = 1.0
33
+ player.volume = 1.0;
34
34
  const volumeManager = new VolumeManager(player);
35
35
 
36
36
  // limit at start
@@ -45,23 +45,22 @@ describe('VolumeManager', () => {
45
45
  // check volume at halfway point
46
46
  assert(player.volume > 0.4);
47
47
  assert(player.volume < 0.6);
48
- }, volumeManager.volumeChangeDuration * 1000 / 2);
48
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
49
49
 
50
50
  setTimeout(() => {
51
51
  // check volume at end with 20ms of leeway
52
52
  assert(player.volume == volumeManager.volume);
53
53
  testAwait.resolve();
54
54
  }, volumeManager.volumeChangeDuration * 1000 + 20);
55
-
56
55
  }, volumeManager.volumeChangeDuration * 1000 + 20);
57
56
 
58
57
  await testAwait.promise;
59
58
  });
60
59
 
61
- it('should ramp down halfway, then ramp up', async () => {
60
+ it("should ramp down halfway, then ramp up", async () => {
62
61
  const testAwait = new Deferred();
63
62
  const player = new TestMediaPlayer();
64
- player.volume = 1.0
63
+ player.volume = 1.0;
65
64
 
66
65
  const volumeManager = new VolumeManager(player);
67
66
 
@@ -77,16 +76,15 @@ describe('VolumeManager', () => {
77
76
  assert(player.volume == volumeManager.volume);
78
77
  testAwait.resolve();
79
78
  }, volumeManager.volumeChangeDuration * 1000 + 20);
80
-
81
- }, volumeManager.volumeChangeDuration * 1000 / 2);
79
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
82
80
 
83
81
  await testAwait.promise;
84
82
  });
85
83
 
86
- it('ramp using selected volume', async () => {
84
+ it("ramp using selected volume", async () => {
87
85
  const testAwait = new Deferred();
88
86
  const player = new TestMediaPlayer();
89
- player.volume = 1.0
87
+ player.volume = 1.0;
90
88
 
91
89
  const volumeManager = new VolumeManager(player);
92
90
 
@@ -95,7 +93,7 @@ describe('VolumeManager', () => {
95
93
  // check volume at halfway point
96
94
  assert(player.volume > 0.6);
97
95
  assert(player.volume < 0.7);
98
- }, volumeManager.volumeChangeDuration * 1000 / 2);
96
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
99
97
 
100
98
  setTimeout(() => {
101
99
  // check volume at end with 20ms of leeway
@@ -106,10 +104,10 @@ describe('VolumeManager', () => {
106
104
  await testAwait.promise;
107
105
  });
108
106
 
109
- it('enable limit, change selected volume, then disable limit', async () => {
107
+ it("enable limit, change selected volume, then disable limit", async () => {
110
108
  const testAwait = new Deferred();
111
109
  const player = new TestMediaPlayer();
112
- player.volume = 1.0
110
+ player.volume = 1.0;
113
111
  const volumeManager = new VolumeManager(player);
114
112
 
115
113
  volumeManager.startLimiting();
@@ -126,16 +124,15 @@ describe('VolumeManager', () => {
126
124
  assert(player.volume === volumeManager.volume);
127
125
  testAwait.resolve();
128
126
  }, volumeManager.volumeChangeDuration * 1000 + 20);
129
-
130
- }, volumeManager.volumeChangeDuration * 1000 / 2);
127
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
131
128
 
132
129
  await testAwait.promise;
133
130
  });
134
131
 
135
- it('ramp down with selected volume to 0.3, then up to 0.8', async () => {
132
+ it("ramp down with selected volume to 0.3, then up to 0.8", async () => {
136
133
  const testAwait = new Deferred();
137
134
  const player = new TestMediaPlayer();
138
- player.volume = 1.0
135
+ player.volume = 1.0;
139
136
 
140
137
  const volumeManager = new VolumeManager(player);
141
138
  volumeManager.volume = 0.3;
@@ -151,15 +148,15 @@ describe('VolumeManager', () => {
151
148
  assert(player.volume == volumeManager.volume);
152
149
  testAwait.resolve();
153
150
  }, volumeManager.volumeChangeDuration * 1000 + 20);
154
- }, volumeManager.volumeChangeDuration * 1000 / 2);
151
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
155
152
 
156
153
  await testAwait.promise;
157
154
  });
158
155
 
159
- it('test 50% limiting', async () => {
156
+ it("test 50% limiting", async () => {
160
157
  const testAwait = new Deferred();
161
158
  const player = new TestMediaPlayer();
162
- player.volume = 1.0
159
+ player.volume = 1.0;
163
160
 
164
161
  const volumeManager = new VolumeManager(player);
165
162
  volumeManager.limitLevelType = LimitLevelType.percentage;
@@ -171,11 +168,13 @@ describe('VolumeManager', () => {
171
168
  // check volume at halfway point
172
169
  assert(player.volume > 0.7);
173
170
  assert(player.volume < 0.8);
174
- }, volumeManager.volumeChangeDuration * 1000 / 2);
171
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
175
172
 
176
173
  setTimeout(() => {
177
174
  // check volume at end with 20ms of leeway
178
- assert(player.volume == volumeManager.limitLevel * volumeManager.volume);
175
+ assert(
176
+ player.volume == volumeManager.limitLevel * volumeManager.volume
177
+ );
179
178
  testAwait.resolve();
180
179
  }, volumeManager.volumeChangeDuration * 1000 + 20);
181
180
 
@@ -203,10 +202,18 @@ class TestMediaPlayer implements IMediaPlayer {
203
202
  play(): Promise<void> {
204
203
  throw new Error("Method not implemented.");
205
204
  }
206
- addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void {
205
+ addEventListener(
206
+ type: string,
207
+ listener: EventListenerOrEventListenerObject,
208
+ options?: boolean | AddEventListenerOptions | undefined
209
+ ): void {
207
210
  throw new Error("Method not implemented.");
208
211
  }
209
- removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void {
212
+ removeEventListener(
213
+ type: string,
214
+ listener: EventListenerOrEventListenerObject,
215
+ options?: boolean | EventListenerOptions | undefined
216
+ ): void {
210
217
  throw new Error("Method not implemented.");
211
218
  }
212
219
  }
package/tsconfig.json CHANGED
@@ -66,6 +66,7 @@
66
66
  "skipLibCheck": true, /* Skip type checking of declaration files. */
67
67
  "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68
68
  },
69
+ "exclude": ["build", "dist", "node_modules"],
69
70
  "include": [
70
71
  "test/**/*.ts"
71
72
  ],
@@ -1,102 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
- import { DataObject, DataObjectFactory } from '@fluidframework/aqueduct';
6
- import { EphemeralTelemetryLogger, UserMeetingRole } from '@microsoft/live-share';
7
- import { MediaPlayerSynchronizer } from './MediaPlayerSynchronizer';
8
- import { ExtendedMediaSessionAction } from './MediaSessionExtensions';
9
- import { EphemeralMediaSessionCoordinator, IMediaPlayerState } from './EphemeralMediaSessionCoordinator';
10
- import { MediaSessionActionThrottler } from './MediaSessionActionThrottler';
11
- import { IMediaPlayer } from './IMediaPlayer';
12
- /**
13
- * Ephemeral fluid object that synchronizes media playback across multiple clients.
14
- */
15
- export declare class EphemeralMediaSession extends DataObject {
16
- private _actionThrottler;
17
- private _logger?;
18
- private _requestPlayerStateHandler?;
19
- private _coordinator?;
20
- private readonly _actionHandlers;
21
- private _synchronizing?;
22
- private _updateTimer;
23
- private _lastUpdateTime;
24
- /**
25
- * The objects fluid type name.
26
- */
27
- static readonly TypeName = "@microsoft/fluid-media:SharedMediaSession";
28
- /**
29
- * The objects fluid type factory.
30
- */
31
- static readonly factory: DataObjectFactory<EphemeralMediaSession, import("@fluidframework/aqueduct").DataObjectTypes>;
32
- /**
33
- * Extension point that lets applications replace the default logic for throttling the sessions
34
- * local sync behavior.
35
- *
36
- * @remarks
37
- * The `EphemeralMediaCoordinator` is fairly aggressive at wanting to keep the local media player
38
- * in sync with the rest of the group. This aggressiveness can result in the coordinator sending
39
- * new sync actions before the local player has finished responding to the previous sync action.
40
- * The `ActionThrottler` gives apps fine grain control over how aggressive they want sync to be.
41
- *
42
- * By default, a `RepeatedAction` throttler is used which prevents the same sync action from
43
- * being sent within an adjustable time period.
44
- */
45
- get actionThrottler(): MediaSessionActionThrottler;
46
- set actionThrottler(value: MediaSessionActionThrottler);
47
- /**
48
- * Returns true if the object has been initialized.
49
- */
50
- get isInitialized(): boolean;
51
- /**
52
- * @deprecated isInitialized should be used instead
53
- * Returns true if the object has been initialized.
54
- */
55
- get isStarted(): boolean;
56
- /**
57
- * The group coordinator for the session.
58
- */
59
- get coordinator(): EphemeralMediaSessionCoordinator;
60
- /**
61
- * Returns the logger used by the session and coordinator.
62
- *
63
- * @remarks
64
- * This is used by the `MediaPlayerSynchronizer` to log events.
65
- */
66
- get logger(): EphemeralTelemetryLogger;
67
- /**
68
- * initialize the object.
69
- * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
70
- * operations like play/pause/seek/setTrack.
71
- */
72
- initialize(acceptTransportChangesFrom?: UserMeetingRole[]): Promise<void>;
73
- /**
74
- * @deprecated initialize should be used instead
75
- * initialize the object.
76
- * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
77
- * operations like play/pause/seek/setTrack.
78
- */
79
- start(acceptTransportChangesFrom?: UserMeetingRole[]): Promise<void>;
80
- /**
81
- * Registers an action handler with the session.
82
- * @param action Name of the action to register a handler for.
83
- * @param handler Function called when the action is triggered.
84
- */
85
- setActionHandler(action: ExtendedMediaSessionAction, handler: MediaSessionActionHandler | null): void;
86
- /**
87
- * Registers a handler that will be queried anytime the group coordinate needs to know the
88
- * local players transport state and position.
89
- */
90
- setRequestPlayerStateHandler(handler: () => IMediaPlayerState): void;
91
- /**
92
- * Begins synchronizing the playback of a media element.
93
- * @param player Something that "looks like" and HTML Media Element.
94
- * @returns A new synchronizer instance. Call `synchronizer.end()` to stop synchronizing the elements playback.
95
- */
96
- synchronize(player: IMediaPlayer): MediaPlayerSynchronizer;
97
- protected hasInitialized(): Promise<void>;
98
- private checkWaitPointHit;
99
- private getCurrentPlayerState;
100
- private dispatchAction;
101
- }
102
- //# sourceMappingURL=EphemeralMediaSession.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EphemeralMediaSession.d.ts","sourceRoot":"","sources":["../src/EphemeralMediaSession.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAiC,0BAA0B,EAAqC,MAAM,0BAA0B,CAAC;AACxI,OAAO,EAAE,gCAAgC,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACF,qBAAa,qBAAsB,SAAQ,UAAU;IAClD,OAAO,CAAC,gBAAgB,CAA8D;IACtF,OAAO,CAAC,OAAO,CAAC,CAA2B;IAC3C,OAAO,CAAC,0BAA0B,CAAC,CAA0B;IAC7D,OAAO,CAAC,YAAY,CAAC,CAAmC;IACxD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqD;IACrF,OAAO,CAAC,cAAc,CAAC,CAA0B;IAGjD,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,eAAe,CAAa;IAEpC;;OAEG;IACF,gBAAuB,QAAQ,+CAA+C;IAE/E;;OAEG;IACF,gBAAuB,OAAO,+FAK7B;IAEF;;;;;;;;;;;;OAYG;IACH,IAAW,eAAe,IAAI,2BAA2B,CAExD;IAED,IAAW,eAAe,CAAC,KAAK,EAAE,2BAA2B,EAE5D;IAED;;OAEG;IACH,IAAW,aAAa,IAAI,OAAO,CAElC;IAED;;;OAGG;IACH,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED;;OAEG;IACH,IAAW,WAAW,IAAI,gCAAgC,CAEzD;IAED;;;;;OAKG;IACH,IAAW,MAAM,IAAI,wBAAwB,CAE5C;IAED;;;;OAIG;IACK,UAAU,CAAC,0BAA0B,CAAC,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjF;;;;;OAKG;IACI,KAAK,CAAC,0BAA0B,CAAC,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3E;;;;OAIG;IACI,gBAAgB,CAAC,MAAM,EAAE,0BAA0B,EAAE,OAAO,EAAE,yBAAyB,GAAG,IAAI,GAAG,IAAI;IAW5G;;;OAGG;IACI,4BAA4B,CAAC,OAAO,EAAE,MAAM,iBAAiB;IAIpE;;;;OAIG;IACI,WAAW,CAAC,MAAM,EAAE,YAAY,GAAG,uBAAuB;cA+BjD,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAuC/C,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,cAAc;CAMzB"}
@@ -1,226 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation. All rights reserved.
4
- * Licensed under the Microsoft Live Share SDK License.
5
- */
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.EphemeralMediaSession = void 0;
17
- const aqueduct_1 = require("@fluidframework/aqueduct");
18
- const live_share_1 = require("@microsoft/live-share");
19
- const MediaPlayerSynchronizer_1 = require("./MediaPlayerSynchronizer");
20
- const internals_1 = require("./internals");
21
- const MediaSessionExtensions_1 = require("./MediaSessionExtensions");
22
- const EphemeralMediaSessionCoordinator_1 = require("./EphemeralMediaSessionCoordinator");
23
- const RepeatedActionThrottler_1 = require("./RepeatedActionThrottler");
24
- /**
25
- * Ephemeral fluid object that synchronizes media playback across multiple clients.
26
- */
27
- class EphemeralMediaSession extends aqueduct_1.DataObject {
28
- constructor() {
29
- super(...arguments);
30
- this._actionThrottler = new RepeatedActionThrottler_1.RepeatedActionThrottler();
31
- this._actionHandlers = new Map();
32
- this._lastUpdateTime = 0;
33
- }
34
- /**
35
- * Extension point that lets applications replace the default logic for throttling the sessions
36
- * local sync behavior.
37
- *
38
- * @remarks
39
- * The `EphemeralMediaCoordinator` is fairly aggressive at wanting to keep the local media player
40
- * in sync with the rest of the group. This aggressiveness can result in the coordinator sending
41
- * new sync actions before the local player has finished responding to the previous sync action.
42
- * The `ActionThrottler` gives apps fine grain control over how aggressive they want sync to be.
43
- *
44
- * By default, a `RepeatedAction` throttler is used which prevents the same sync action from
45
- * being sent within an adjustable time period.
46
- */
47
- get actionThrottler() {
48
- return this._actionThrottler;
49
- }
50
- set actionThrottler(value) {
51
- this._actionThrottler = value;
52
- }
53
- /**
54
- * Returns true if the object has been initialized.
55
- */
56
- get isInitialized() {
57
- return this.coordinator.isInitialized;
58
- }
59
- /**
60
- * @deprecated isInitialized should be used instead
61
- * Returns true if the object has been initialized.
62
- */
63
- get isStarted() {
64
- return this.isInitialized;
65
- }
66
- /**
67
- * The group coordinator for the session.
68
- */
69
- get coordinator() {
70
- return this._coordinator;
71
- }
72
- /**
73
- * Returns the logger used by the session and coordinator.
74
- *
75
- * @remarks
76
- * This is used by the `MediaPlayerSynchronizer` to log events.
77
- */
78
- get logger() {
79
- return this._logger;
80
- }
81
- /**
82
- * initialize the object.
83
- * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
84
- * operations like play/pause/seek/setTrack.
85
- */
86
- initialize(acceptTransportChangesFrom) {
87
- return this.coordinator.initialize(acceptTransportChangesFrom);
88
- }
89
- /**
90
- * @deprecated initialize should be used instead
91
- * initialize the object.
92
- * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
93
- * operations like play/pause/seek/setTrack.
94
- */
95
- start(acceptTransportChangesFrom) {
96
- return this.initialize(acceptTransportChangesFrom);
97
- }
98
- /**
99
- * Registers an action handler with the session.
100
- * @param action Name of the action to register a handler for.
101
- * @param handler Function called when the action is triggered.
102
- */
103
- setActionHandler(action, handler) {
104
- if (handler) {
105
- // add handler
106
- this._actionHandlers.set(action, handler);
107
- }
108
- else if (this._actionHandlers.has(action)) {
109
- // remove handler
110
- this._actionHandlers.delete(action);
111
- }
112
- }
113
- /**
114
- * Registers a handler that will be queried anytime the group coordinate needs to know the
115
- * local players transport state and position.
116
- */
117
- setRequestPlayerStateHandler(handler) {
118
- this._requestPlayerStateHandler = handler;
119
- }
120
- /**
121
- * Begins synchronizing the playback of a media element.
122
- * @param player Something that "looks like" and HTML Media Element.
123
- * @returns A new synchronizer instance. Call `synchronizer.end()` to stop synchronizing the elements playback.
124
- */
125
- synchronize(player) {
126
- // A session can only synchronize one player at a time
127
- if (this._synchronizing) {
128
- this._synchronizing.end();
129
- }
130
- // Start position update timer
131
- if (!this._updateTimer) {
132
- this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.BeginPositionUpdateTimer);
133
- this._updateTimer = setInterval(() => {
134
- // Get current state
135
- const state = this.getCurrentPlayerState();
136
- // Check for hit wait point
137
- this.checkWaitPointHit(state);
138
- // Send position update if interval hit
139
- const now = new Date().getTime();
140
- const delta = (now - this._lastUpdateTime) / 1000;
141
- if (this.coordinator.isInitialized && delta >= this.coordinator.positionUpdateInterval) {
142
- this._lastUpdateTime = now;
143
- this.coordinator.sendPositionUpdate(state);
144
- }
145
- }, 500);
146
- }
147
- return new MediaPlayerSynchronizer_1.MediaPlayerSynchronizer(player, this, () => {
148
- this._synchronizing = undefined;
149
- });
150
- }
151
- hasInitialized() {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- this._logger = new live_share_1.EphemeralTelemetryLogger(this.runtime);
154
- // Create coordinator and listen for triggered actions
155
- this._coordinator = new EphemeralMediaSessionCoordinator_1.EphemeralMediaSessionCoordinator(this.runtime, () => this.getCurrentPlayerState());
156
- this._coordinator.on(MediaSessionExtensions_1.MediaSessionCoordinatorEvents.triggeraction, (event) => {
157
- // Pre-process actions
158
- const details = event.details;
159
- const seekTime = typeof details.seekTime == 'number' ? details.seekTime : -1;
160
- switch (details.action) {
161
- case 'play':
162
- this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.PlayAction, null, { position: seekTime });
163
- break;
164
- case 'pause':
165
- this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.PauseAction, null, { position: seekTime });
166
- break;
167
- case 'seekto':
168
- this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.SeekToAction, null, { position: seekTime });
169
- break;
170
- case 'settrack':
171
- this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.SetTrackAction);
172
- break;
173
- case 'datachange':
174
- this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.DataChangeAction);
175
- break;
176
- case 'catchup':
177
- // Default to seekto if catchup not implemented
178
- this.logger.sendTelemetryEvent(internals_1.TelemetryEvents.MediaSession.CatchUpAction, null, { position: seekTime });
179
- if (!this._actionHandlers.has('catchup')) {
180
- details.action = 'seekto';
181
- }
182
- break;
183
- }
184
- // Dispatch action
185
- this.dispatchAction(details);
186
- });
187
- });
188
- }
189
- checkWaitPointHit(state) {
190
- // Was a wait point hit?
191
- if (state.positionState && this.coordinator.isInitialized) {
192
- const waitPoint = this.coordinator.findNextWaitPoint();
193
- if (waitPoint && state.positionState.position != undefined && state.positionState.position >= waitPoint.position) {
194
- // Ensure handler registered
195
- if (!this._actionHandlers.has('wait')) {
196
- throw new Error(`SharedMediaSession: wait point hit but no 'wait' action registered.`);
197
- }
198
- // Begin suspension for wait point
199
- const suspension = this.coordinator.beginSuspension(waitPoint);
200
- this.dispatchAction({ action: 'wait', suspension: suspension });
201
- }
202
- }
203
- }
204
- getCurrentPlayerState() {
205
- if (!this._requestPlayerStateHandler) {
206
- throw new Error(`SharedMediaSession: no getPlayerState callback configured.`);
207
- }
208
- return this._requestPlayerStateHandler();
209
- }
210
- dispatchAction(details) {
211
- if (this._actionHandlers.has(details.action)) {
212
- const handler = this._actionHandlers.get(details.action);
213
- this._actionThrottler.throttled(details, handler);
214
- }
215
- }
216
- }
217
- exports.EphemeralMediaSession = EphemeralMediaSession;
218
- /**
219
- * The objects fluid type name.
220
- */
221
- EphemeralMediaSession.TypeName = `@microsoft/fluid-media:SharedMediaSession`;
222
- /**
223
- * The objects fluid type factory.
224
- */
225
- EphemeralMediaSession.factory = new aqueduct_1.DataObjectFactory(EphemeralMediaSession.TypeName, EphemeralMediaSession, [], {});
226
- //# sourceMappingURL=EphemeralMediaSession.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EphemeralMediaSession.js","sourceRoot":"","sources":["../src/EphemeralMediaSession.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH,uDAAyE;AACzE,sDAAkF;AAClF,uEAAoE;AACpE,2CAAmE;AACnE,qEAAwI;AACxI,yFAAyG;AAEzG,uEAAoE;AAGpE;;GAEG;AACF,MAAa,qBAAsB,SAAQ,qBAAU;IAArD;;QACW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