@microsoft/live-share-media 0.5.1 → 1.0.0-preview.10

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 (88) hide show
  1. package/.nycrc.json +10 -10
  2. package/LICENSE +86 -86
  3. package/README.md +141 -137
  4. package/bin/IMediaPlayer.d.ts.map +1 -1
  5. package/bin/LiveMediaSession.d.ts +95 -0
  6. package/bin/LiveMediaSession.d.ts.map +1 -0
  7. package/bin/LiveMediaSession.js +232 -0
  8. package/bin/LiveMediaSession.js.map +1 -0
  9. package/bin/LiveMediaSessionCoordinator.d.ts +228 -0
  10. package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -0
  11. package/bin/LiveMediaSessionCoordinator.js +408 -0
  12. package/bin/LiveMediaSessionCoordinator.js.map +1 -0
  13. package/bin/LiveMediaSessionCoordinatorSuspension.d.ts +20 -0
  14. package/bin/LiveMediaSessionCoordinatorSuspension.d.ts.map +1 -0
  15. package/bin/LiveMediaSessionCoordinatorSuspension.js +28 -0
  16. package/bin/LiveMediaSessionCoordinatorSuspension.js.map +1 -0
  17. package/bin/MediaPlayerSynchronizer.d.ts +11 -11
  18. package/bin/MediaPlayerSynchronizer.d.ts.map +1 -1
  19. package/bin/MediaPlayerSynchronizer.js +136 -76
  20. package/bin/MediaPlayerSynchronizer.js.map +1 -1
  21. package/bin/MediaSessionActionThrottler.d.ts +1 -1
  22. package/bin/MediaSessionActionThrottler.d.ts.map +1 -1
  23. package/bin/MediaSessionActionThrottler.js.map +1 -1
  24. package/bin/MediaSessionExtensions.d.ts.map +1 -1
  25. package/bin/RepeatedActionThrottler.d.ts +2 -2
  26. package/bin/RepeatedActionThrottler.d.ts.map +1 -1
  27. package/bin/RepeatedActionThrottler.js +9 -3
  28. package/bin/RepeatedActionThrottler.js.map +1 -1
  29. package/bin/VolumeManager.d.ts +84 -0
  30. package/bin/VolumeManager.d.ts.map +1 -0
  31. package/bin/VolumeManager.js +175 -0
  32. package/bin/VolumeManager.js.map +1 -0
  33. package/bin/index.d.ts +9 -9
  34. package/bin/index.d.ts.map +1 -1
  35. package/bin/index.js +4 -4
  36. package/bin/index.js.map +1 -1
  37. package/bin/internals/GroupCoordinatorState.d.ts +12 -12
  38. package/bin/internals/GroupCoordinatorState.d.ts.map +1 -1
  39. package/bin/internals/GroupCoordinatorState.js +94 -56
  40. package/bin/internals/GroupCoordinatorState.js.map +1 -1
  41. package/bin/internals/GroupPlaybackPosition.d.ts +3 -3
  42. package/bin/internals/GroupPlaybackPosition.d.ts.map +1 -1
  43. package/bin/internals/GroupPlaybackPosition.js +24 -15
  44. package/bin/internals/GroupPlaybackPosition.js.map +1 -1
  45. package/bin/internals/GroupPlaybackTrack.d.ts +4 -4
  46. package/bin/internals/GroupPlaybackTrack.d.ts.map +1 -1
  47. package/bin/internals/GroupPlaybackTrack.js +14 -4
  48. package/bin/internals/GroupPlaybackTrack.js.map +1 -1
  49. package/bin/internals/GroupPlaybackTrackData.d.ts +3 -3
  50. package/bin/internals/GroupPlaybackTrackData.d.ts.map +1 -1
  51. package/bin/internals/GroupPlaybackTrackData.js +8 -4
  52. package/bin/internals/GroupPlaybackTrackData.js.map +1 -1
  53. package/bin/internals/GroupTransportState.d.ts +5 -5
  54. package/bin/internals/GroupTransportState.d.ts.map +1 -1
  55. package/bin/internals/GroupTransportState.js +28 -13
  56. package/bin/internals/GroupTransportState.js.map +1 -1
  57. package/bin/internals/consts.d.ts.map +1 -1
  58. package/bin/internals/consts.js +54 -54
  59. package/bin/internals/consts.js.map +1 -1
  60. package/bin/internals/index.d.ts +6 -6
  61. package/package.json +38 -38
  62. package/src/IMediaPlayer.ts +29 -21
  63. package/src/LiveMediaSession.ts +305 -0
  64. package/src/LiveMediaSessionCoordinator.ts +621 -0
  65. package/src/{EphemeralMediaSessionCoordinatorSuspension.ts → LiveMediaSessionCoordinatorSuspension.ts} +39 -31
  66. package/src/MediaPlayerSynchronizer.ts +636 -450
  67. package/src/MediaSessionActionThrottler.ts +16 -14
  68. package/src/MediaSessionExtensions.ts +52 -42
  69. package/src/RepeatedActionThrottler.ts +74 -56
  70. package/src/VolumeManager.ts +197 -0
  71. package/src/index.ts +14 -15
  72. package/src/internals/GroupCoordinatorState.ts +606 -446
  73. package/src/internals/GroupPlaybackPosition.ts +227 -193
  74. package/src/internals/GroupPlaybackTrack.ts +176 -147
  75. package/src/internals/GroupPlaybackTrackData.ts +98 -90
  76. package/src/internals/GroupTransportState.ts +157 -127
  77. package/src/internals/consts.ts +98 -80
  78. package/src/internals/index.ts +11 -11
  79. package/src/test/GroupPlaybackPosition.spec.ts +600 -340
  80. package/src/test/GroupPlaybackTrack.spec.ts +122 -66
  81. package/src/test/SharedMediaSession.spec.ts +149 -113
  82. package/src/test/SharedMediaSessionCoordinator.spec.ts +271 -231
  83. package/src/test/VolumeManager.spec.ts +219 -0
  84. package/tsconfig.build.json +8 -8
  85. package/tsconfig.json +76 -75
  86. package/src/EphemeralMediaSession.ts +0 -248
  87. package/src/EphemeralMediaSessionCoordinator.ts +0 -461
  88. package/src/VolumeLimiter.ts +0 -182
@@ -0,0 +1,219 @@
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";
5
+
6
+ describe("VolumeManager", () => {
7
+ it("should ramp down volume", async () => {
8
+ const testAwait = new Deferred();
9
+ const player = new TestMediaPlayer();
10
+ player.volume = 1.0;
11
+ const volumeManager = new VolumeManager(player);
12
+
13
+ assert(player.volume == 1.0);
14
+ volumeManager.startLimiting();
15
+ setTimeout(() => {
16
+ // check volume at halfway point
17
+ assert(player.volume > 0.4);
18
+ assert(player.volume < 0.6);
19
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
20
+
21
+ setTimeout(() => {
22
+ // check volume at end with 20ms of leeway
23
+ assert(player.volume == volumeManager.limitLevel);
24
+ testAwait.resolve();
25
+ }, volumeManager.volumeChangeDuration * 1000 + 20);
26
+
27
+ await testAwait.promise;
28
+ });
29
+
30
+ it("should ramp up volume", async () => {
31
+ const testAwait = new Deferred();
32
+ const player = new TestMediaPlayer();
33
+ player.volume = 1.0;
34
+ const volumeManager = new VolumeManager(player);
35
+
36
+ // limit at start
37
+ volumeManager.startLimiting();
38
+
39
+ // when limited all the way, test ramp up
40
+ setTimeout(() => {
41
+ assert(player.volume == volumeManager.limitLevel);
42
+ volumeManager.stopLimiting();
43
+
44
+ setTimeout(() => {
45
+ // check volume at halfway point
46
+ assert(player.volume > 0.4);
47
+ assert(player.volume < 0.6);
48
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
49
+
50
+ setTimeout(() => {
51
+ // check volume at end with 20ms of leeway
52
+ assert(player.volume == volumeManager.volume);
53
+ testAwait.resolve();
54
+ }, volumeManager.volumeChangeDuration * 1000 + 20);
55
+ }, volumeManager.volumeChangeDuration * 1000 + 20);
56
+
57
+ await testAwait.promise;
58
+ });
59
+
60
+ it("should ramp down halfway, then ramp up", async () => {
61
+ const testAwait = new Deferred();
62
+ const player = new TestMediaPlayer();
63
+ player.volume = 1.0;
64
+
65
+ const volumeManager = new VolumeManager(player);
66
+
67
+ volumeManager.startLimiting();
68
+ setTimeout(() => {
69
+ // check volume at halfway point, begin ramping other direction
70
+ assert(player.volume > 0.4);
71
+ assert(player.volume < 0.6);
72
+ volumeManager.stopLimiting();
73
+
74
+ setTimeout(() => {
75
+ // check volume at end with 20ms of leeway
76
+ assert(player.volume == volumeManager.volume);
77
+ testAwait.resolve();
78
+ }, volumeManager.volumeChangeDuration * 1000 + 20);
79
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
80
+
81
+ await testAwait.promise;
82
+ });
83
+
84
+ it("ramp using selected volume", async () => {
85
+ const testAwait = new Deferred();
86
+ const player = new TestMediaPlayer();
87
+ player.volume = 1.0;
88
+
89
+ const volumeManager = new VolumeManager(player);
90
+
91
+ volumeManager.volume = 0.3;
92
+ setTimeout(() => {
93
+ // check volume at halfway point
94
+ assert(player.volume > 0.6);
95
+ assert(player.volume < 0.7);
96
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
97
+
98
+ setTimeout(() => {
99
+ // check volume at end with 20ms of leeway
100
+ assert(player.volume == volumeManager.volume);
101
+ testAwait.resolve();
102
+ }, volumeManager.volumeChangeDuration * 1000 + 20);
103
+
104
+ await testAwait.promise;
105
+ });
106
+
107
+ it("enable limit, change selected volume, then disable limit", async () => {
108
+ const testAwait = new Deferred();
109
+ const player = new TestMediaPlayer();
110
+ player.volume = 1.0;
111
+ const volumeManager = new VolumeManager(player);
112
+
113
+ volumeManager.startLimiting();
114
+ setTimeout(() => {
115
+ // check volume at halfway point, begin ramping other direction with lower selected volume
116
+ assert(player.volume > 0.4);
117
+ assert(player.volume < 0.6);
118
+
119
+ volumeManager.volume = 0.7;
120
+ volumeManager.stopLimiting();
121
+
122
+ setTimeout(() => {
123
+ // check volume at end with 20ms of leeway
124
+ assert(player.volume === volumeManager.volume);
125
+ testAwait.resolve();
126
+ }, volumeManager.volumeChangeDuration * 1000 + 20);
127
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
128
+
129
+ await testAwait.promise;
130
+ });
131
+
132
+ it("ramp down with selected volume to 0.3, then up to 0.8", async () => {
133
+ const testAwait = new Deferred();
134
+ const player = new TestMediaPlayer();
135
+ player.volume = 1.0;
136
+
137
+ const volumeManager = new VolumeManager(player);
138
+ volumeManager.volume = 0.3;
139
+
140
+ setTimeout(() => {
141
+ // check volume at halfway point
142
+ assert(player.volume > 0.6);
143
+ assert(player.volume < 0.7);
144
+ volumeManager.volume = 0.8;
145
+
146
+ setTimeout(() => {
147
+ // check volume at end with 20ms of leeway
148
+ assert(player.volume == volumeManager.volume);
149
+ testAwait.resolve();
150
+ }, volumeManager.volumeChangeDuration * 1000 + 20);
151
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
152
+
153
+ await testAwait.promise;
154
+ });
155
+
156
+ it("test 50% limiting", async () => {
157
+ const testAwait = new Deferred();
158
+ const player = new TestMediaPlayer();
159
+ player.volume = 1.0;
160
+
161
+ const volumeManager = new VolumeManager(player);
162
+ volumeManager.limitLevelType = LimitLevelType.percentage;
163
+ volumeManager.limitLevel = 0.5;
164
+
165
+ volumeManager.startLimiting();
166
+
167
+ setTimeout(() => {
168
+ // check volume at halfway point
169
+ assert(player.volume > 0.7);
170
+ assert(player.volume < 0.8);
171
+ }, (volumeManager.volumeChangeDuration * 1000) / 2);
172
+
173
+ setTimeout(() => {
174
+ // check volume at end with 20ms of leeway
175
+ assert(
176
+ player.volume == volumeManager.limitLevel * volumeManager.volume
177
+ );
178
+ testAwait.resolve();
179
+ }, volumeManager.volumeChangeDuration * 1000 + 20);
180
+
181
+ await testAwait.promise;
182
+ });
183
+ });
184
+
185
+ // test implementation
186
+ class TestMediaPlayer implements IMediaPlayer {
187
+ currentSrc: string;
188
+ currentTime: number;
189
+ duration: number;
190
+ ended: boolean;
191
+ muted: boolean;
192
+ paused: boolean;
193
+ playbackRate: number;
194
+ src: string;
195
+ volume: number;
196
+ load(): void {
197
+ throw new Error("Method not implemented.");
198
+ }
199
+ pause(): void {
200
+ throw new Error("Method not implemented.");
201
+ }
202
+ play(): Promise<void> {
203
+ throw new Error("Method not implemented.");
204
+ }
205
+ addEventListener(
206
+ type: string,
207
+ listener: EventListenerOrEventListenerObject,
208
+ options?: boolean | AddEventListenerOptions | undefined
209
+ ): void {
210
+ throw new Error("Method not implemented.");
211
+ }
212
+ removeEventListener(
213
+ type: string,
214
+ listener: EventListenerOrEventListenerObject,
215
+ options?: boolean | EventListenerOptions | undefined
216
+ ): void {
217
+ throw new Error("Method not implemented.");
218
+ }
219
+ }
@@ -1,9 +1,9 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
5
- },
6
- "exclude": [
7
- "test/**/*.ts"
8
- ]
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
5
+ },
6
+ "exclude": [
7
+ "test/**/*.ts"
8
+ ]
9
9
  }
package/tsconfig.json CHANGED
@@ -1,75 +1,76 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Basic Options */
6
- // "incremental": true, /* Enable incremental compilation */
7
- "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
- "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
- "lib": ["es2020","DOM"], /* Specify library files to be included in the compilation. */
10
- "allowJs": false, /* Allow javascript files to be compiled. */
11
- // "checkJs": true, /* Report errors in .js files. */
12
- // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
- "declaration": true, /* Generates corresponding '.d.ts' file. */
14
- "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
- "sourceMap": true, /* Generates corresponding '.map' file. */
16
- // "outFile": "./", /* Concatenate and emit output to single file. */
17
- "outDir": "./bin", /* Redirect output structure to the directory. */
18
- // "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19
- // "composite": true, /* Enable project compilation */
20
- // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21
- // "removeComments": true, /* Do not emit comments to output. */
22
- // "noEmit": true, /* Do not emit outputs. */
23
- // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24
- // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25
- // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26
-
27
- /* Strict Type-Checking Options */
28
- "strict": true, /* Enable all strict type-checking options. */
29
- // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30
- // "strictNullChecks": true, /* Enable strict null checks. */
31
- // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32
- // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33
- // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34
- // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35
- // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36
-
37
- /* Additional Checks */
38
- // "noUnusedLocals": true, /* Report errors on unused locals. */
39
- // "noUnusedParameters": true, /* Report errors on unused parameters. */
40
- // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41
- // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42
-
43
- /* Module Resolution Options */
44
- // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45
- // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46
- // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48
- // "typeRoots": [], /* List of folders to include type definitions from. */
49
- // "types": [], /* Type declaration files to be included in compilation. */
50
- // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51
- "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54
-
55
- /* Source Map Options */
56
- // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
- // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59
- // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60
-
61
- /* Experimental Options */
62
- // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
63
- // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64
-
65
- /* Advanced Options */
66
- "skipLibCheck": true, /* Skip type checking of declaration files. */
67
- "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68
- },
69
- "include": [
70
- "test/**/*.ts"
71
- ],
72
- "files": [
73
- "src/index.ts"
74
- ]
75
- }
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
+
5
+ /* Basic Options */
6
+ // "incremental": true, /* Enable incremental compilation */
7
+ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
+ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
+ "lib": ["es2020","DOM"], /* Specify library files to be included in the compilation. */
10
+ "allowJs": false, /* Allow javascript files to be compiled. */
11
+ // "checkJs": true, /* Report errors in .js files. */
12
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
+ "declaration": true, /* Generates corresponding '.d.ts' file. */
14
+ "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
+ "sourceMap": true, /* Generates corresponding '.map' file. */
16
+ // "outFile": "./", /* Concatenate and emit output to single file. */
17
+ "outDir": "./bin", /* Redirect output structure to the directory. */
18
+ // "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19
+ // "composite": true, /* Enable project compilation */
20
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21
+ // "removeComments": true, /* Do not emit comments to output. */
22
+ // "noEmit": true, /* Do not emit outputs. */
23
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26
+
27
+ /* Strict Type-Checking Options */
28
+ "strict": true, /* Enable all strict type-checking options. */
29
+ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30
+ // "strictNullChecks": true, /* Enable strict null checks. */
31
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36
+
37
+ /* Additional Checks */
38
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
39
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
40
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42
+
43
+ /* Module Resolution Options */
44
+ // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48
+ // "typeRoots": [], /* List of folders to include type definitions from. */
49
+ // "types": [], /* Type declaration files to be included in compilation. */
50
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51
+ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54
+
55
+ /* Source Map Options */
56
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60
+
61
+ /* Experimental Options */
62
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
63
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64
+
65
+ /* Advanced Options */
66
+ "skipLibCheck": true, /* Skip type checking of declaration files. */
67
+ "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
68
+ },
69
+ "exclude": ["build", "dist", "node_modules"],
70
+ "include": [
71
+ "test/**/*.ts"
72
+ ],
73
+ "files": [
74
+ "src/index.ts"
75
+ ]
76
+ }
@@ -1,248 +0,0 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
-
6
- import { DataObject, DataObjectFactory } from '@fluidframework/aqueduct';
7
- import { EphemeralTelemetryLogger, UserMeetingRole } from '@microsoft/live-share';
8
- import { MediaPlayerSynchronizer } from './MediaPlayerSynchronizer';
9
- import { ITriggerActionEvent, TelemetryEvents } from './internals';
10
- import { MediaSessionCoordinatorEvents, ExtendedMediaSessionAction, ExtendedMediaSessionActionDetails } from './MediaSessionExtensions';
11
- import { EphemeralMediaSessionCoordinator, IMediaPlayerState } from './EphemeralMediaSessionCoordinator';
12
- import { MediaSessionActionThrottler } from './MediaSessionActionThrottler';
13
- import { RepeatedActionThrottler } from './RepeatedActionThrottler';
14
- import { IMediaPlayer } from './IMediaPlayer';
15
-
16
- /**
17
- * Ephemeral fluid object that synchronizes media playback across multiple clients.
18
- */
19
- export class EphemeralMediaSession extends DataObject {
20
- private _actionThrottler: MediaSessionActionThrottler = new RepeatedActionThrottler();
21
- private _logger?: EphemeralTelemetryLogger;
22
- private _requestPlayerStateHandler?: () => IMediaPlayerState;
23
- private _coordinator?: EphemeralMediaSessionCoordinator;
24
- private readonly _actionHandlers: Map<string, MediaSessionActionHandler> = new Map();
25
- private _synchronizing?: MediaPlayerSynchronizer;
26
-
27
- // Position update timer
28
- private _updateTimer: any;
29
- private _lastUpdateTime: number = 0;
30
-
31
- /**
32
- * The objects fluid type name.
33
- */
34
- public static readonly TypeName = `@microsoft/fluid-media:SharedMediaSession`;
35
-
36
- /**
37
- * The objects fluid type factory.
38
- */
39
- public static readonly factory = new DataObjectFactory(
40
- EphemeralMediaSession.TypeName,
41
- EphemeralMediaSession,
42
- [],
43
- {}
44
- );
45
-
46
- /**
47
- * Extension point that lets applications replace the default logic for throttling the sessions
48
- * local sync behavior.
49
- *
50
- * @remarks
51
- * The `EphemeralMediaCoordinator` is fairly aggressive at wanting to keep the local media player
52
- * in sync with the rest of the group. This aggressiveness can result in the coordinator sending
53
- * new sync actions before the local player has finished responding to the previous sync action.
54
- * The `ActionThrottler` gives apps fine grain control over how aggressive they want sync to be.
55
- *
56
- * By default, a `RepeatedAction` throttler is used which prevents the same sync action from
57
- * being sent within an adjustable time period.
58
- */
59
- public get actionThrottler(): MediaSessionActionThrottler {
60
- return this._actionThrottler;
61
- }
62
-
63
- public set actionThrottler(value: MediaSessionActionThrottler) {
64
- this._actionThrottler = value;
65
- }
66
-
67
- /**
68
- * Returns true if the object has been initialized.
69
- */
70
- public get isInitialized(): boolean {
71
- return this.coordinator.isInitialized;
72
- }
73
-
74
- /**
75
- * @deprecated isInitialized should be used instead
76
- * Returns true if the object has been initialized.
77
- */
78
- public get isStarted(): boolean {
79
- return this.isInitialized
80
- }
81
-
82
- /**
83
- * The group coordinator for the session.
84
- */
85
- public get coordinator(): EphemeralMediaSessionCoordinator {
86
- return this._coordinator!;
87
- }
88
-
89
- /**
90
- * Returns the logger used by the session and coordinator.
91
- *
92
- * @remarks
93
- * This is used by the `MediaPlayerSynchronizer` to log events.
94
- */
95
- public get logger(): EphemeralTelemetryLogger {
96
- return this._logger!;
97
- }
98
-
99
- /**
100
- * initialize the object.
101
- * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
102
- * operations like play/pause/seek/setTrack.
103
- */
104
- public initialize(acceptTransportChangesFrom?: UserMeetingRole[]): Promise<void> {
105
- return this.coordinator.initialize(acceptTransportChangesFrom);
106
- }
107
-
108
- /**
109
- * @deprecated initialize should be used instead
110
- * initialize the object.
111
- * @param acceptTransportChangesFrom Optional. List of roles allowed to group transport
112
- * operations like play/pause/seek/setTrack.
113
- */
114
- public start(acceptTransportChangesFrom?: UserMeetingRole[]): Promise<void> {
115
- return this.initialize(acceptTransportChangesFrom)
116
- }
117
-
118
- /**
119
- * Registers an action handler with the session.
120
- * @param action Name of the action to register a handler for.
121
- * @param handler Function called when the action is triggered.
122
- */
123
- public setActionHandler(action: ExtendedMediaSessionAction, handler: MediaSessionActionHandler | null): void {
124
- if (handler) {
125
- // add handler
126
- this._actionHandlers.set(action, handler);
127
-
128
- } else if (this._actionHandlers.has(action)) {
129
- // remove handler
130
- this._actionHandlers.delete(action);
131
- }
132
- }
133
-
134
- /**
135
- * Registers a handler that will be queried anytime the group coordinate needs to know the
136
- * local players transport state and position.
137
- */
138
- public setRequestPlayerStateHandler(handler: () => IMediaPlayerState) {
139
- this._requestPlayerStateHandler = handler;
140
- }
141
-
142
- /**
143
- * Begins synchronizing the playback of a media element.
144
- * @param player Something that "looks like" and HTML Media Element.
145
- * @returns A new synchronizer instance. Call `synchronizer.end()` to stop synchronizing the elements playback.
146
- */
147
- public synchronize(player: IMediaPlayer): MediaPlayerSynchronizer {
148
- // A session can only synchronize one player at a time
149
- if (this._synchronizing) {
150
- this._synchronizing.end();
151
- }
152
-
153
- // Start position update timer
154
- if (!this._updateTimer) {
155
- this.logger.sendTelemetryEvent(TelemetryEvents.MediaSession.BeginPositionUpdateTimer);
156
- this._updateTimer = setInterval(() => {
157
- // Get current state
158
- const state = this.getCurrentPlayerState();
159
-
160
- // Check for hit wait point
161
- this.checkWaitPointHit(state);
162
-
163
- // Send position update if interval hit
164
- const now = new Date().getTime();
165
- const delta = (now - this._lastUpdateTime) / 1000;
166
- if (this.coordinator.isInitialized && delta >= this.coordinator.positionUpdateInterval) {
167
- this._lastUpdateTime = now;
168
- this.coordinator.sendPositionUpdate(state);
169
- }
170
- }, 500);
171
- }
172
-
173
- return new MediaPlayerSynchronizer(player, this, () => {
174
- this._synchronizing = undefined;
175
- });
176
- }
177
-
178
- protected async hasInitialized(): Promise<void> {
179
- this. _logger = new EphemeralTelemetryLogger(this.runtime);
180
-
181
- // Create coordinator and listen for triggered actions
182
- this._coordinator = new EphemeralMediaSessionCoordinator(this.runtime, () => this.getCurrentPlayerState());
183
- this._coordinator.on(MediaSessionCoordinatorEvents.triggeraction, (event: ITriggerActionEvent) => {
184
- // Pre-process actions
185
- const details = event.details;
186
- const seekTime = typeof details.seekTime == 'number' ? details.seekTime : -1;
187
- switch (details.action) {
188
- case 'play':
189
- this.logger.sendTelemetryEvent(TelemetryEvents.MediaSession.PlayAction, null, {position: seekTime});
190
- break;
191
- case 'pause':
192
- this.logger.sendTelemetryEvent(TelemetryEvents.MediaSession.PauseAction, null, {position: seekTime});
193
- break;
194
- case 'seekto':
195
- this.logger.sendTelemetryEvent(TelemetryEvents.MediaSession.SeekToAction, null, {position: seekTime});
196
- break;
197
- case 'settrack':
198
- this.logger.sendTelemetryEvent(TelemetryEvents.MediaSession.SetTrackAction);
199
- break;
200
- case 'datachange':
201
- this.logger.sendTelemetryEvent(TelemetryEvents.MediaSession.DataChangeAction);
202
- break;
203
- case 'catchup':
204
- // Default to seekto if catchup not implemented
205
- this.logger.sendTelemetryEvent(TelemetryEvents.MediaSession.CatchUpAction, null, {position: seekTime});
206
- if (!this._actionHandlers.has('catchup')) {
207
- details.action = 'seekto';
208
- }
209
- break;
210
- }
211
-
212
- // Dispatch action
213
- this.dispatchAction(details);
214
- });
215
- }
216
-
217
- private checkWaitPointHit(state: IMediaPlayerState): void {
218
- // Was a wait point hit?
219
- if (state.positionState && this.coordinator.isInitialized) {
220
- const waitPoint = this.coordinator.findNextWaitPoint();
221
- if (waitPoint && state.positionState.position != undefined && state.positionState.position >= waitPoint.position) {
222
- // Ensure handler registered
223
- if (!this._actionHandlers.has('wait')) {
224
- throw new Error(`SharedMediaSession: wait point hit but no 'wait' action registered.`);
225
- }
226
-
227
- // Begin suspension for wait point
228
- const suspension = this.coordinator.beginSuspension(waitPoint);
229
- this.dispatchAction({action: 'wait', suspension: suspension});
230
- }
231
- }
232
- }
233
-
234
- private getCurrentPlayerState(): IMediaPlayerState {
235
- if (!this._requestPlayerStateHandler) {
236
- throw new Error(`SharedMediaSession: no getPlayerState callback configured.`);
237
- }
238
-
239
- return this._requestPlayerStateHandler();
240
- }
241
-
242
- private dispatchAction(details: MediaSessionActionDetails|ExtendedMediaSessionActionDetails): void {
243
- if (this._actionHandlers.has(details.action)) {
244
- const handler = this._actionHandlers.get(details.action);
245
- this._actionThrottler.throttled(details, handler);
246
- }
247
- }
248
- }