@microsoft/live-share-media 0.5.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 (100) hide show
  1. package/.nycrc.json +10 -10
  2. package/.vscode/launch.json +29 -0
  3. package/.vscode/settings.json +2 -0
  4. package/LICENSE +86 -86
  5. package/README.md +138 -137
  6. package/bin/IMediaPlayer.d.ts.map +1 -1
  7. package/bin/{EphemeralMediaSession.d.ts → LiveMediaSession.d.ts} +14 -21
  8. package/bin/LiveMediaSession.d.ts.map +1 -0
  9. package/bin/{EphemeralMediaSession.js → LiveMediaSession.js} +39 -37
  10. package/bin/LiveMediaSession.js.map +1 -0
  11. package/bin/{EphemeralMediaSessionCoordinator.d.ts → LiveMediaSessionCoordinator.d.ts} +5 -5
  12. package/bin/LiveMediaSessionCoordinator.d.ts.map +1 -0
  13. package/bin/{EphemeralMediaSessionCoordinator.js → LiveMediaSessionCoordinator.js} +60 -48
  14. package/bin/LiveMediaSessionCoordinator.js.map +1 -0
  15. package/bin/{EphemeralMediaSessionCoordinatorSuspension.d.ts → LiveMediaSessionCoordinatorSuspension.d.ts} +3 -3
  16. package/bin/LiveMediaSessionCoordinatorSuspension.d.ts.map +1 -0
  17. package/bin/{EphemeralMediaSessionCoordinatorSuspension.js → LiveMediaSessionCoordinatorSuspension.js} +4 -4
  18. package/bin/LiveMediaSessionCoordinatorSuspension.js.map +1 -0
  19. package/bin/MediaPlayerSynchronizer.d.ts +11 -11
  20. package/bin/MediaPlayerSynchronizer.d.ts.map +1 -1
  21. package/bin/MediaPlayerSynchronizer.js +132 -75
  22. package/bin/MediaPlayerSynchronizer.js.map +1 -1
  23. package/bin/MediaSessionActionThrottler.d.ts +1 -1
  24. package/bin/MediaSessionActionThrottler.d.ts.map +1 -1
  25. package/bin/MediaSessionActionThrottler.js.map +1 -1
  26. package/bin/MediaSessionExtensions.d.ts.map +1 -1
  27. package/bin/RepeatedActionThrottler.d.ts +2 -2
  28. package/bin/RepeatedActionThrottler.d.ts.map +1 -1
  29. package/bin/RepeatedActionThrottler.js +9 -3
  30. package/bin/RepeatedActionThrottler.js.map +1 -1
  31. package/bin/VolumeManager.d.ts +84 -0
  32. package/bin/VolumeManager.d.ts.map +1 -0
  33. package/bin/VolumeManager.js +175 -0
  34. package/bin/VolumeManager.js.map +1 -0
  35. package/bin/index.d.ts +9 -9
  36. package/bin/index.d.ts.map +1 -1
  37. package/bin/index.js +4 -4
  38. package/bin/index.js.map +1 -1
  39. package/bin/internals/GroupCoordinatorState.d.ts +12 -12
  40. package/bin/internals/GroupCoordinatorState.d.ts.map +1 -1
  41. package/bin/internals/GroupCoordinatorState.js +94 -56
  42. package/bin/internals/GroupCoordinatorState.js.map +1 -1
  43. package/bin/internals/GroupPlaybackPosition.d.ts +3 -3
  44. package/bin/internals/GroupPlaybackPosition.d.ts.map +1 -1
  45. package/bin/internals/GroupPlaybackPosition.js +24 -15
  46. package/bin/internals/GroupPlaybackPosition.js.map +1 -1
  47. package/bin/internals/GroupPlaybackTrack.d.ts +4 -4
  48. package/bin/internals/GroupPlaybackTrack.d.ts.map +1 -1
  49. package/bin/internals/GroupPlaybackTrack.js +14 -4
  50. package/bin/internals/GroupPlaybackTrack.js.map +1 -1
  51. package/bin/internals/GroupPlaybackTrackData.d.ts +3 -3
  52. package/bin/internals/GroupPlaybackTrackData.d.ts.map +1 -1
  53. package/bin/internals/GroupPlaybackTrackData.js +8 -4
  54. package/bin/internals/GroupPlaybackTrackData.js.map +1 -1
  55. package/bin/internals/GroupTransportState.d.ts +5 -5
  56. package/bin/internals/GroupTransportState.d.ts.map +1 -1
  57. package/bin/internals/GroupTransportState.js +28 -13
  58. package/bin/internals/GroupTransportState.js.map +1 -1
  59. package/bin/internals/consts.d.ts.map +1 -1
  60. package/bin/internals/consts.js +54 -54
  61. package/bin/internals/consts.js.map +1 -1
  62. package/bin/internals/index.d.ts +6 -6
  63. package/package.json +38 -38
  64. package/src/IMediaPlayer.ts +29 -21
  65. package/src/LiveMediaSession.ts +300 -0
  66. package/src/LiveMediaSessionCoordinator.ts +621 -0
  67. package/src/{EphemeralMediaSessionCoordinatorSuspension.ts → LiveMediaSessionCoordinatorSuspension.ts} +39 -31
  68. package/src/MediaPlayerSynchronizer.ts +627 -450
  69. package/src/MediaSessionActionThrottler.ts +16 -14
  70. package/src/MediaSessionExtensions.ts +52 -42
  71. package/src/RepeatedActionThrottler.ts +74 -56
  72. package/src/VolumeManager.ts +197 -0
  73. package/src/index.ts +14 -15
  74. package/src/internals/GroupCoordinatorState.ts +606 -446
  75. package/src/internals/GroupPlaybackPosition.ts +227 -193
  76. package/src/internals/GroupPlaybackTrack.ts +176 -147
  77. package/src/internals/GroupPlaybackTrackData.ts +98 -90
  78. package/src/internals/GroupTransportState.ts +157 -127
  79. package/src/internals/consts.ts +98 -80
  80. package/src/internals/index.ts +11 -11
  81. package/src/test/GroupPlaybackPosition.spec.ts +600 -340
  82. package/src/test/GroupPlaybackTrack.spec.ts +122 -66
  83. package/src/test/SharedMediaSession.spec.ts +149 -113
  84. package/src/test/SharedMediaSessionCoordinator.spec.ts +271 -231
  85. package/src/test/VolumeManager.spec.ts +219 -0
  86. package/tsconfig.build.json +8 -8
  87. package/tsconfig.json +76 -75
  88. package/bin/EphemeralMediaSession.d.ts.map +0 -1
  89. package/bin/EphemeralMediaSession.js.map +0 -1
  90. package/bin/EphemeralMediaSessionCoordinator.d.ts.map +0 -1
  91. package/bin/EphemeralMediaSessionCoordinator.js.map +0 -1
  92. package/bin/EphemeralMediaSessionCoordinatorSuspension.d.ts.map +0 -1
  93. package/bin/EphemeralMediaSessionCoordinatorSuspension.js.map +0 -1
  94. package/bin/VolumeLimiter.d.ts +0 -70
  95. package/bin/VolumeLimiter.d.ts.map +0 -1
  96. package/bin/VolumeLimiter.js +0 -170
  97. package/bin/VolumeLimiter.js.map +0 -1
  98. package/src/EphemeralMediaSession.ts +0 -248
  99. package/src/EphemeralMediaSessionCoordinator.ts +0 -461
  100. package/src/VolumeLimiter.ts +0 -182
@@ -1,66 +1,122 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
-
6
- import 'mocha';
7
- import { strict as assert } from 'assert';
8
- import { IParticipant, ParticipantRole, Deferred } from '@microsoft/teams-collaboration';
9
- import { GroupPlaybackTrack, GroupPlaybackTrackEvents, ITrackChangeEvent } from '../internals/GroupPlaybackTrack';
10
- import { ExtendedMediaMetadata } from '../MediaSessionExtensions';
11
-
12
- describe('GroupPlaybackTrack', () => {
13
- const user1: IParticipant = { participantId: 'user1', role: ParticipantRole.organizer };
14
- const user2: IParticipant = { participantId: 'user2', role: ParticipantRole.participant };
15
-
16
- const track1 = { trackIdentifier: 'track1', title: 'Test Track 1' } as ExtendedMediaMetadata;
17
- const track2 = { trackIdentifier: 'track2', title: 'Test Track 2' } as ExtendedMediaMetadata;
18
-
19
- it('should fire "trackChange" event when no media', async () => {
20
- const done = new Deferred();
21
- const playbackTrack = new GroupPlaybackTrack(() => null);
22
- playbackTrack.addEventListener(GroupPlaybackTrackEvents.trackChange, (event: ITrackChangeEvent) => {
23
- try {
24
- assert(event.metadata, `no metadata`);
25
- assert(event.metadata.trackIdentifier == 'track1', `wrong track`);
26
- done.resolve();
27
- } catch(err) {
28
- done.reject(err);
29
- }
30
-
31
- });
32
-
33
- await playbackTrack.updateTrack({ metadata: track1, waitPoints: [], timestamp: 1, socketId: 'a'});
34
-
35
- await done.promise;
36
- });
37
-
38
- it('should switch tracks', async () => {
39
- let cnt = 0;
40
- let metadata: ExtendedMediaMetadata = null;
41
- const playbackTrack = new GroupPlaybackTrack(() => metadata);
42
- playbackTrack.addEventListener(GroupPlaybackTrackEvents.trackChange, (event: ITrackChangeEvent) => {
43
- cnt++;
44
- metadata = event.metadata;
45
- });
46
-
47
- await playbackTrack.updateTrack({ metadata: track1, waitPoints: [], timestamp: 1, socketId: 'a'});
48
- await playbackTrack.updateTrack({ metadata: track2, waitPoints: [], timestamp: 2, socketId: 'b'});
49
- assert(cnt == 2, `called trackChange event ${cnt} times`);
50
- assert(metadata.trackIdentifier == 'track2', `wrong track set`);
51
- });
52
-
53
- it('should ignore track changes with older timestamps', async () => {
54
- let cnt = 0;
55
- let metadata: ExtendedMediaMetadata = null;
56
- const playbackTrack = new GroupPlaybackTrack(() => metadata);
57
- playbackTrack.addEventListener(GroupPlaybackTrackEvents.trackChange, (event: ITrackChangeEvent) => {
58
- cnt++;
59
- metadata = event.metadata;
60
- });
61
-
62
- await playbackTrack.updateTrack({ metadata: track1, waitPoints: [], timestamp: 3, socketId: 'a'});
63
- await playbackTrack.updateTrack({ metadata: track2, waitPoints: [], timestamp: 2, socketId: 'b'});
64
- assert(cnt == 1, `called trackChange event ${cnt} times`);
65
- });
66
- });
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+
6
+ import "mocha";
7
+ import { strict as assert } from "assert";
8
+ import {
9
+ IParticipant,
10
+ ParticipantRole,
11
+ Deferred,
12
+ } from "@microsoft/teams-collaboration";
13
+ import {
14
+ GroupPlaybackTrack,
15
+ GroupPlaybackTrackEvents,
16
+ ITrackChangeEvent,
17
+ } from "../internals/GroupPlaybackTrack";
18
+ import { ExtendedMediaMetadata } from "../MediaSessionExtensions";
19
+
20
+ describe("GroupPlaybackTrack", () => {
21
+ const user1: IParticipant = {
22
+ participantId: "user1",
23
+ role: ParticipantRole.organizer,
24
+ };
25
+ const user2: IParticipant = {
26
+ participantId: "user2",
27
+ role: ParticipantRole.participant,
28
+ };
29
+
30
+ const track1 = {
31
+ trackIdentifier: "track1",
32
+ title: "Test Track 1",
33
+ } as ExtendedMediaMetadata;
34
+ const track2 = {
35
+ trackIdentifier: "track2",
36
+ title: "Test Track 2",
37
+ } as ExtendedMediaMetadata;
38
+
39
+ it('should fire "trackChange" event when no media', async () => {
40
+ const done = new Deferred();
41
+ const playbackTrack = new GroupPlaybackTrack(() => null);
42
+ playbackTrack.addEventListener(
43
+ GroupPlaybackTrackEvents.trackChange,
44
+ (event: ITrackChangeEvent) => {
45
+ try {
46
+ assert(event.metadata, `no metadata`);
47
+ assert(
48
+ event.metadata.trackIdentifier == "track1",
49
+ `wrong track`
50
+ );
51
+ done.resolve();
52
+ } catch (err) {
53
+ done.reject(err);
54
+ }
55
+ }
56
+ );
57
+
58
+ await playbackTrack.updateTrack({
59
+ metadata: track1,
60
+ waitPoints: [],
61
+ timestamp: 1,
62
+ socketId: "a",
63
+ });
64
+
65
+ await done.promise;
66
+ });
67
+
68
+ it("should switch tracks", async () => {
69
+ let cnt = 0;
70
+ let metadata: ExtendedMediaMetadata = null;
71
+ const playbackTrack = new GroupPlaybackTrack(() => metadata);
72
+ playbackTrack.addEventListener(
73
+ GroupPlaybackTrackEvents.trackChange,
74
+ (event: ITrackChangeEvent) => {
75
+ cnt++;
76
+ metadata = event.metadata;
77
+ }
78
+ );
79
+
80
+ await playbackTrack.updateTrack({
81
+ metadata: track1,
82
+ waitPoints: [],
83
+ timestamp: 1,
84
+ socketId: "a",
85
+ });
86
+ await playbackTrack.updateTrack({
87
+ metadata: track2,
88
+ waitPoints: [],
89
+ timestamp: 2,
90
+ socketId: "b",
91
+ });
92
+ assert(cnt == 2, `called trackChange event ${cnt} times`);
93
+ assert(metadata.trackIdentifier == "track2", `wrong track set`);
94
+ });
95
+
96
+ it("should ignore track changes with older timestamps", async () => {
97
+ let cnt = 0;
98
+ let metadata: ExtendedMediaMetadata = null;
99
+ const playbackTrack = new GroupPlaybackTrack(() => metadata);
100
+ playbackTrack.addEventListener(
101
+ GroupPlaybackTrackEvents.trackChange,
102
+ (event: ITrackChangeEvent) => {
103
+ cnt++;
104
+ metadata = event.metadata;
105
+ }
106
+ );
107
+
108
+ await playbackTrack.updateTrack({
109
+ metadata: track1,
110
+ waitPoints: [],
111
+ timestamp: 3,
112
+ socketId: "a",
113
+ });
114
+ await playbackTrack.updateTrack({
115
+ metadata: track2,
116
+ waitPoints: [],
117
+ timestamp: 2,
118
+ socketId: "b",
119
+ });
120
+ assert(cnt == 1, `called trackChange event ${cnt} times`);
121
+ });
122
+ });
@@ -1,113 +1,149 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation. All rights reserved.
3
- * Licensed under the Microsoft Live Share SDK License.
4
- */
5
-
6
- import 'mocha';
7
- import { strict as assert } from 'assert';
8
- import { CollaborationSpace, CollaborationSpaceEvents, Deferred } from '@microsoft/teams-collaboration';
9
- import { LastMediaPositionState } from '../EphemeralMediaSessionCoordinator';
10
- import { ExtendedMediaMetadata, ExtendedMediaSessionActionDetails } from '../MediaSessionExtensions';
11
- import { SharedMediaSession } from '../EphemeralMediaSession';
12
-
13
- export class TestMediaSession extends SharedMediaSession {
14
- private done = new Deferred<ExtendedMediaSessionActionDetails>();
15
- private space: CollaborationSpace;
16
- private playbackTimer: any;
17
- private playbackStarted: number = 0;
18
- private playbackPosition: number = 0.0;
19
-
20
- constructor(space: CollaborationSpace, metadata?: ExtendedMediaMetadata|null, playbackState?: MediaSessionPlaybackState, positionState?: LastMediaPositionState) {
21
- super(space);
22
- this.space = space;
23
- if (metadata) { this.metadata = metadata; }
24
- if (playbackState) { this.playbackState = playbackState; }
25
- if (positionState) {
26
- this.playbackPosition = positionState.position != undefined ? positionState.position : 0.0;
27
- this.duration = positionState.duration;
28
- this.playbackRate = positionState.playbackRate != undefined ? positionState.playbackRate : 1;
29
- }
30
-
31
- this.setActionHandler('play', details => {
32
- this.play();
33
- this.done.resolve(details);
34
- });
35
- this.setActionHandler('pause', details => {
36
- this.pause();
37
- this.done.resolve(details);
38
- });
39
- this.setActionHandler('seekto', details => {
40
- this.currentTime = details.seekTime;
41
- this.done.resolve(details);
42
- });
43
- this.setActionHandler('settrack', details => {
44
- this.done.resolve(details);
45
- });
46
-
47
- this.space.addEventListener(CollaborationSpaceEvents.leftSpace, () => {
48
- if (this.playbackTimer) {
49
- clearInterval(this.playbackTimer);
50
- this.playbackTimer = undefined;
51
- }
52
- });
53
- }
54
-
55
- public duration?: number;
56
- public playbackRate: number = 1;
57
-
58
- public get playing(): boolean {
59
- return this.playbackState == 'playing';
60
- }
61
-
62
- public get paused(): boolean {
63
- return this.playbackState != 'playing';
64
- }
65
-
66
- public get currentTime(): number {
67
- if (this.playbackState == 'playing') {
68
- const now = this.space.clock.getTime();
69
- return this.playbackPosition + ((now - this.playbackStarted) / 1000);
70
- } else {
71
- return this.playbackPosition;
72
- }
73
- }
74
-
75
- public set currentTime(value: number) {
76
- const startState = this.playbackState;
77
- this.pause();
78
- this.playbackPosition = value;
79
- if (startState == 'playing') {
80
- this.play();
81
- } else {
82
- this.setPositionState({position: this.currentTime, duration: this.duration, playbackRate: this.playbackRate});
83
- }
84
- }
85
-
86
- public play(): void {
87
- if (this.playbackState != 'playing') {
88
- this.playbackStarted = this.space.clock.getTime();
89
- this.playbackState = 'playing';
90
- this.playbackTimer = setInterval(() => {
91
- this.playbackState = 'playing';
92
- this.setPositionState({position: this.currentTime, duration: this.duration, playbackRate: this.playbackRate});
93
- }, 60);
94
- }
95
- }
96
-
97
- public pause(): void {
98
- if (this.playbackTimer) {
99
- clearInterval(this.playbackTimer);
100
- this.playbackTimer = undefined;
101
- }
102
-
103
- this.playbackPosition = this.currentTime;
104
- this.playbackState = 'paused';
105
- this.setPositionState({position: this.currentTime, duration: this.duration, playbackRate: this.playbackRate});
106
- }
107
-
108
- public async waitForAction(handler: (details: ExtendedMediaSessionActionDetails) => Promise<void>): Promise<void> {
109
- const details = await this.done.promise;
110
- this.done = new Deferred<ExtendedMediaSessionActionDetails>();
111
- await handler(details);
112
- }
113
- }
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the Microsoft Live Share SDK License.
4
+ */
5
+
6
+ import "mocha";
7
+ import { strict as assert } from "assert";
8
+ import {
9
+ CollaborationSpace,
10
+ CollaborationSpaceEvents,
11
+ Deferred,
12
+ } from "@microsoft/teams-collaboration";
13
+ import { LastMediaPositionState } from "../LiveMediaSessionCoordinator";
14
+ import {
15
+ ExtendedMediaMetadata,
16
+ ExtendedMediaSessionActionDetails,
17
+ } from "../MediaSessionExtensions";
18
+ import { SharedMediaSession } from "../LiveMediaSession";
19
+
20
+ export class TestMediaSession extends SharedMediaSession {
21
+ private done = new Deferred<ExtendedMediaSessionActionDetails>();
22
+ private space: CollaborationSpace;
23
+ private playbackTimer: any;
24
+ private playbackStarted: number = 0;
25
+ private playbackPosition: number = 0.0;
26
+
27
+ constructor(
28
+ space: CollaborationSpace,
29
+ metadata?: ExtendedMediaMetadata | null,
30
+ playbackState?: MediaSessionPlaybackState,
31
+ positionState?: LastMediaPositionState
32
+ ) {
33
+ super(space);
34
+ this.space = space;
35
+ if (metadata) {
36
+ this.metadata = metadata;
37
+ }
38
+ if (playbackState) {
39
+ this.playbackState = playbackState;
40
+ }
41
+ if (positionState) {
42
+ this.playbackPosition =
43
+ positionState.position != undefined
44
+ ? positionState.position
45
+ : 0.0;
46
+ this.duration = positionState.duration;
47
+ this.playbackRate =
48
+ positionState.playbackRate != undefined
49
+ ? positionState.playbackRate
50
+ : 1;
51
+ }
52
+
53
+ this.setActionHandler("play", (details) => {
54
+ this.play();
55
+ this.done.resolve(details);
56
+ });
57
+ this.setActionHandler("pause", (details) => {
58
+ this.pause();
59
+ this.done.resolve(details);
60
+ });
61
+ this.setActionHandler("seekto", (details) => {
62
+ this.currentTime = details.seekTime;
63
+ this.done.resolve(details);
64
+ });
65
+ this.setActionHandler("settrack", (details) => {
66
+ this.done.resolve(details);
67
+ });
68
+
69
+ this.space.addEventListener(CollaborationSpaceEvents.leftSpace, () => {
70
+ if (this.playbackTimer) {
71
+ clearInterval(this.playbackTimer);
72
+ this.playbackTimer = undefined;
73
+ }
74
+ });
75
+ }
76
+
77
+ public duration?: number;
78
+ public playbackRate: number = 1;
79
+
80
+ public get playing(): boolean {
81
+ return this.playbackState == "playing";
82
+ }
83
+
84
+ public get paused(): boolean {
85
+ return this.playbackState != "playing";
86
+ }
87
+
88
+ public get currentTime(): number {
89
+ if (this.playbackState == "playing") {
90
+ const now = this.space.clock.getTime();
91
+ return this.playbackPosition + (now - this.playbackStarted) / 1000;
92
+ } else {
93
+ return this.playbackPosition;
94
+ }
95
+ }
96
+
97
+ public set currentTime(value: number) {
98
+ const startState = this.playbackState;
99
+ this.pause();
100
+ this.playbackPosition = value;
101
+ if (startState == "playing") {
102
+ this.play();
103
+ } else {
104
+ this.setPositionState({
105
+ position: this.currentTime,
106
+ duration: this.duration,
107
+ playbackRate: this.playbackRate,
108
+ });
109
+ }
110
+ }
111
+
112
+ public play(): void {
113
+ if (this.playbackState != "playing") {
114
+ this.playbackStarted = this.space.clock.getTime();
115
+ this.playbackState = "playing";
116
+ this.playbackTimer = setInterval(() => {
117
+ this.playbackState = "playing";
118
+ this.setPositionState({
119
+ position: this.currentTime,
120
+ duration: this.duration,
121
+ playbackRate: this.playbackRate,
122
+ });
123
+ }, 60);
124
+ }
125
+ }
126
+
127
+ public pause(): void {
128
+ if (this.playbackTimer) {
129
+ clearInterval(this.playbackTimer);
130
+ this.playbackTimer = undefined;
131
+ }
132
+
133
+ this.playbackPosition = this.currentTime;
134
+ this.playbackState = "paused";
135
+ this.setPositionState({
136
+ position: this.currentTime,
137
+ duration: this.duration,
138
+ playbackRate: this.playbackRate,
139
+ });
140
+ }
141
+
142
+ public async waitForAction(
143
+ handler: (details: ExtendedMediaSessionActionDetails) => Promise<void>
144
+ ): Promise<void> {
145
+ const details = await this.done.promise;
146
+ this.done = new Deferred<ExtendedMediaSessionActionDetails>();
147
+ await handler(details);
148
+ }
149
+ }