@microsoft/live-share-media 0.5.1 → 1.0.0-preview.1
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/.nycrc.json +10 -10
- package/.vscode/launch.json +29 -0
- package/.vscode/settings.json +2 -0
- package/LICENSE +86 -86
- package/README.md +138 -137
- package/bin/LiveMediaSession.d.ts +95 -0
- package/bin/LiveMediaSession.d.ts.map +1 -0
- package/bin/LiveMediaSession.js +217 -0
- package/bin/LiveMediaSession.js.map +1 -0
- package/bin/LiveMediaSessionCoordinator.d.ts +228 -0
- package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -0
- package/bin/LiveMediaSessionCoordinator.js +396 -0
- package/bin/LiveMediaSessionCoordinator.js.map +1 -0
- package/bin/LiveMediaSessionCoordinatorSuspension.d.ts +20 -0
- package/bin/LiveMediaSessionCoordinatorSuspension.d.ts.map +1 -0
- package/bin/LiveMediaSessionCoordinatorSuspension.js +28 -0
- package/bin/LiveMediaSessionCoordinatorSuspension.js.map +1 -0
- package/bin/MediaPlayerSynchronizer.d.ts +6 -6
- package/bin/MediaPlayerSynchronizer.d.ts.map +1 -1
- package/bin/MediaPlayerSynchronizer.js +12 -7
- package/bin/MediaPlayerSynchronizer.js.map +1 -1
- package/bin/VolumeManager.d.ts +84 -0
- package/bin/VolumeManager.d.ts.map +1 -0
- package/bin/VolumeManager.js +173 -0
- package/bin/VolumeManager.js.map +1 -0
- package/bin/index.d.ts +4 -4
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +4 -4
- package/bin/index.js.map +1 -1
- package/bin/internals/GroupCoordinatorState.d.ts +6 -6
- package/bin/internals/GroupCoordinatorState.d.ts.map +1 -1
- package/bin/internals/GroupCoordinatorState.js +6 -6
- package/bin/internals/GroupCoordinatorState.js.map +1 -1
- package/bin/internals/GroupPlaybackPosition.d.ts.map +1 -1
- package/bin/internals/GroupPlaybackPosition.js +2 -2
- package/bin/internals/GroupPlaybackPosition.js.map +1 -1
- package/bin/internals/GroupPlaybackTrack.d.ts +1 -1
- package/bin/internals/GroupPlaybackTrack.d.ts.map +1 -1
- package/bin/internals/GroupTransportState.d.ts +1 -1
- package/bin/internals/GroupTransportState.d.ts.map +1 -1
- package/bin/internals/GroupTransportState.js +1 -1
- package/bin/internals/GroupTransportState.js.map +1 -1
- package/package.json +38 -38
- package/src/IMediaPlayer.ts +21 -21
- package/src/{EphemeralMediaSession.ts → LiveMediaSession.ts} +238 -248
- package/src/{EphemeralMediaSessionCoordinator.ts → LiveMediaSessionCoordinator.ts} +461 -461
- package/src/{EphemeralMediaSessionCoordinatorSuspension.ts → LiveMediaSessionCoordinatorSuspension.ts} +30 -30
- package/src/MediaPlayerSynchronizer.ts +455 -449
- package/src/MediaSessionActionThrottler.ts +14 -14
- package/src/MediaSessionExtensions.ts +42 -42
- package/src/RepeatedActionThrottler.ts +55 -55
- package/src/VolumeManager.ts +185 -0
- package/src/index.ts +15 -15
- package/src/internals/GroupCoordinatorState.ts +445 -445
- package/src/internals/GroupPlaybackPosition.ts +193 -193
- package/src/internals/GroupPlaybackTrack.ts +147 -147
- package/src/internals/GroupPlaybackTrackData.ts +90 -90
- package/src/internals/GroupTransportState.ts +127 -127
- package/src/internals/consts.ts +80 -80
- package/src/internals/index.ts +10 -10
- package/src/test/GroupPlaybackPosition.spec.ts +339 -339
- package/src/test/GroupPlaybackTrack.spec.ts +65 -65
- package/src/test/SharedMediaSession.spec.ts +113 -113
- package/src/test/SharedMediaSessionCoordinator.spec.ts +230 -230
- package/src/test/VolumeManager.spec.ts +212 -0
- package/tsconfig.build.json +8 -8
- package/tsconfig.json +75 -75
- package/src/VolumeLimiter.ts +0 -182
package/tsconfig.build.json
CHANGED
|
@@ -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,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
|
-
"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
|
+
"include": [
|
|
70
|
+
"test/**/*.ts"
|
|
71
|
+
],
|
|
72
|
+
"files": [
|
|
73
|
+
"src/index.ts"
|
|
74
|
+
]
|
|
75
|
+
}
|
package/src/VolumeLimiter.ts
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
-
* Licensed under the Microsoft Live Share SDK License.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { TimeInterval } from '@microsoft/live-share';
|
|
7
|
-
import { IMediaPlayer } from './IMediaPlayer';
|
|
8
|
-
|
|
9
|
-
export enum LevelType { fixed, percentage }
|
|
10
|
-
|
|
11
|
-
export class VolumeLimiter {
|
|
12
|
-
private readonly _player: IMediaPlayer;
|
|
13
|
-
|
|
14
|
-
// Settings
|
|
15
|
-
private readonly _duration = new TimeInterval(2000);
|
|
16
|
-
private readonly _rampDownDuration = new TimeInterval(500);
|
|
17
|
-
private readonly _rampUpDuration = new TimeInterval(500);
|
|
18
|
-
private _level: number = 0.1
|
|
19
|
-
private _levelType: LevelType = LevelType.fixed;
|
|
20
|
-
|
|
21
|
-
// Running state
|
|
22
|
-
private _running = false;
|
|
23
|
-
private _endTime = 0;
|
|
24
|
-
private _startTime = 0;
|
|
25
|
-
private _startVolume = 0;
|
|
26
|
-
private _inRamp = false;
|
|
27
|
-
|
|
28
|
-
constructor(player: IMediaPlayer) {
|
|
29
|
-
this._player = player;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Time, in seconds, that the volume should be lowered.
|
|
34
|
-
*
|
|
35
|
-
* @remarks
|
|
36
|
-
* Applications should periodically call `lowerVolume()` to keep the volume lowered.
|
|
37
|
-
*/
|
|
38
|
-
public get duration(): number {
|
|
39
|
-
return this._duration.seconds;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public set duration(value: number) {
|
|
43
|
-
this._duration.seconds = Math.abs(value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Target level to lower volume to.
|
|
48
|
-
*
|
|
49
|
-
* @remarks
|
|
50
|
-
* Expressed as a value between 0.0 and 1.0. The value is applied based upon the configured
|
|
51
|
-
* `levelType`. The default value is 0.2.
|
|
52
|
-
*
|
|
53
|
-
* For a level type of `LevelType.fixed` the value is the exact level the volume will be
|
|
54
|
-
* lowered to. The default value of 0.2 would cause the volume to be lowered to 0.2.
|
|
55
|
-
*
|
|
56
|
-
* For a level type of `LevelType.percentage` the value is the percentage by which the volume
|
|
57
|
-
* level should be lowered to. The default value of 0.2 would cause the volume to be lowered
|
|
58
|
-
* to 20% of its starting value.
|
|
59
|
-
*/
|
|
60
|
-
public get level(): number {
|
|
61
|
-
return this._level;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public set level(value: number) {
|
|
65
|
-
if (value < 0 || value > 1.0) {
|
|
66
|
-
throw new Error(`VolumeLimiter: cannot set level to ${value}. Level must be between 0.0 and 1.0.`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this._level = value;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The type of level represented by the `level` property.
|
|
74
|
-
*/
|
|
75
|
-
public get levelType(): LevelType {
|
|
76
|
-
return this._levelType;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public set levelType(value: LevelType) {
|
|
80
|
-
this._levelType = value;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Amount of time, in seconds, it should take to ramp the volume down to the desired level.
|
|
85
|
-
*/
|
|
86
|
-
public get rampDownDuration(): number {
|
|
87
|
-
return this._rampDownDuration.seconds;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public set rampDownDuration(value: number) {
|
|
91
|
-
this._rampDownDuration.seconds = Math.abs(value);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Amount of time, in seconds, it should take to ramp the volume back up to the original level.
|
|
96
|
-
*/
|
|
97
|
-
public get rampUpDuration(): number {
|
|
98
|
-
return this._rampUpDuration.seconds;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public set rampUpDuration(value: number) {
|
|
102
|
-
this._rampUpDuration.seconds = Math.abs(value);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Temporarily lowers an audio sources volume.
|
|
107
|
-
*/
|
|
108
|
-
public lowerVolume(): void {
|
|
109
|
-
this._endTime = new Date().getTime() + this._duration.milliseconds;
|
|
110
|
-
if (!this._running) {
|
|
111
|
-
this.startLimiter();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
private startLimiter(): void {
|
|
116
|
-
const adjustVolume = () => {
|
|
117
|
-
const now = new Date().getTime();
|
|
118
|
-
if (now < this._endTime) {
|
|
119
|
-
// Make no adjustment if muted
|
|
120
|
-
if (!this._player.muted) {
|
|
121
|
-
// Compute adjusted volume level
|
|
122
|
-
let volume: number;
|
|
123
|
-
const targetVolume = this.computeTargetVolume();
|
|
124
|
-
const rampRange = this._startVolume - targetVolume;
|
|
125
|
-
const rampUpStart = this._endTime - this._rampUpDuration.milliseconds;
|
|
126
|
-
const rampDownEnd = this._startTime + this._rampDownDuration.milliseconds;
|
|
127
|
-
if (now > rampUpStart) {
|
|
128
|
-
// We're about to end so ramping up
|
|
129
|
-
const progress = (now - rampUpStart) / this._rampUpDuration.milliseconds;
|
|
130
|
-
volume = targetVolume + (rampRange * progress);
|
|
131
|
-
this._player.volume = volume;
|
|
132
|
-
this._inRamp = true;
|
|
133
|
-
} else if (now < rampDownEnd) {
|
|
134
|
-
// We just begun so ramping down
|
|
135
|
-
const remaining = (rampDownEnd - now) / this._rampUpDuration.milliseconds;
|
|
136
|
-
volume = targetVolume + (rampRange * remaining);
|
|
137
|
-
this._player.volume = volume;
|
|
138
|
-
this._inRamp = true;
|
|
139
|
-
} else if (this._inRamp) {
|
|
140
|
-
// We're at the end of a ramp
|
|
141
|
-
volume = targetVolume;
|
|
142
|
-
this._player.volume = volume;
|
|
143
|
-
this._inRamp = false;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Schedule next animation frame
|
|
148
|
-
this.scheduleAnimationFrame(adjustVolume);
|
|
149
|
-
} else {
|
|
150
|
-
// Reset volume to original level
|
|
151
|
-
this._player.volume = this._startVolume;
|
|
152
|
-
this._running = false;
|
|
153
|
-
this._endTime = 0;
|
|
154
|
-
this._startTime = 0;
|
|
155
|
-
this._startVolume = 0;
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
this._running = true;
|
|
160
|
-
this._startTime = new Date().getTime();
|
|
161
|
-
this._startVolume = this._player.volume;
|
|
162
|
-
this.scheduleAnimationFrame(adjustVolume)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private scheduleAnimationFrame(callback: FrameRequestCallback): void {
|
|
166
|
-
if (requestAnimationFrame) {
|
|
167
|
-
requestAnimationFrame(callback);
|
|
168
|
-
} else {
|
|
169
|
-
setTimeout(callback, 20);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private computeTargetVolume(): number {
|
|
174
|
-
switch (this._levelType) {
|
|
175
|
-
case LevelType.percentage:
|
|
176
|
-
return this._startVolume * this._level;
|
|
177
|
-
case LevelType.fixed:
|
|
178
|
-
default:
|
|
179
|
-
return this._level;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|