@unwanted/matrix-sdk-mini 34.12.0-1 → 34.12.0-2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. package/git-revision.txt +1 -1
  2. package/lib/@types/event.d.ts +0 -19
  3. package/lib/@types/event.d.ts.map +1 -1
  4. package/lib/@types/event.js.map +1 -1
  5. package/lib/client.d.ts +2 -50
  6. package/lib/client.d.ts.map +1 -1
  7. package/lib/client.js +391 -501
  8. package/lib/client.js.map +1 -1
  9. package/lib/embedded.d.ts.map +1 -1
  10. package/lib/embedded.js +0 -1
  11. package/lib/embedded.js.map +1 -1
  12. package/lib/matrix.d.ts +0 -6
  13. package/lib/matrix.d.ts.map +1 -1
  14. package/lib/matrix.js +1 -5
  15. package/lib/matrix.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/@types/event.ts +2 -36
  18. package/src/client.ts +1 -150
  19. package/src/embedded.ts +0 -2
  20. package/src/matrix.ts +0 -13
  21. package/lib/matrixrtc/CallMembership.d.ts +0 -66
  22. package/lib/matrixrtc/CallMembership.d.ts.map +0 -1
  23. package/lib/matrixrtc/CallMembership.js +0 -197
  24. package/lib/matrixrtc/CallMembership.js.map +0 -1
  25. package/lib/matrixrtc/LivekitFocus.d.ts +0 -16
  26. package/lib/matrixrtc/LivekitFocus.d.ts.map +0 -1
  27. package/lib/matrixrtc/LivekitFocus.js +0 -20
  28. package/lib/matrixrtc/LivekitFocus.js.map +0 -1
  29. package/lib/matrixrtc/MatrixRTCSession.d.ts +0 -295
  30. package/lib/matrixrtc/MatrixRTCSession.d.ts.map +0 -1
  31. package/lib/matrixrtc/MatrixRTCSession.js +0 -1043
  32. package/lib/matrixrtc/MatrixRTCSession.js.map +0 -1
  33. package/lib/matrixrtc/MatrixRTCSessionManager.d.ts +0 -40
  34. package/lib/matrixrtc/MatrixRTCSessionManager.d.ts.map +0 -1
  35. package/lib/matrixrtc/MatrixRTCSessionManager.js +0 -146
  36. package/lib/matrixrtc/MatrixRTCSessionManager.js.map +0 -1
  37. package/lib/matrixrtc/focus.d.ts +0 -10
  38. package/lib/matrixrtc/focus.d.ts.map +0 -1
  39. package/lib/matrixrtc/focus.js +0 -1
  40. package/lib/matrixrtc/focus.js.map +0 -1
  41. package/lib/matrixrtc/index.d.ts +0 -7
  42. package/lib/matrixrtc/index.d.ts.map +0 -1
  43. package/lib/matrixrtc/index.js +0 -21
  44. package/lib/matrixrtc/index.js.map +0 -1
  45. package/lib/matrixrtc/types.d.ts +0 -19
  46. package/lib/matrixrtc/types.d.ts.map +0 -1
  47. package/lib/matrixrtc/types.js +0 -1
  48. package/lib/matrixrtc/types.js.map +0 -1
  49. package/lib/webrtc/audioContext.d.ts +0 -15
  50. package/lib/webrtc/audioContext.d.ts.map +0 -1
  51. package/lib/webrtc/audioContext.js +0 -46
  52. package/lib/webrtc/audioContext.js.map +0 -1
  53. package/lib/webrtc/call.d.ts +0 -560
  54. package/lib/webrtc/call.d.ts.map +0 -1
  55. package/lib/webrtc/call.js +0 -2541
  56. package/lib/webrtc/call.js.map +0 -1
  57. package/lib/webrtc/callEventHandler.d.ts +0 -37
  58. package/lib/webrtc/callEventHandler.d.ts.map +0 -1
  59. package/lib/webrtc/callEventHandler.js +0 -344
  60. package/lib/webrtc/callEventHandler.js.map +0 -1
  61. package/lib/webrtc/callEventTypes.d.ts +0 -73
  62. package/lib/webrtc/callEventTypes.d.ts.map +0 -1
  63. package/lib/webrtc/callEventTypes.js +0 -13
  64. package/lib/webrtc/callEventTypes.js.map +0 -1
  65. package/lib/webrtc/callFeed.d.ts +0 -128
  66. package/lib/webrtc/callFeed.d.ts.map +0 -1
  67. package/lib/webrtc/callFeed.js +0 -289
  68. package/lib/webrtc/callFeed.js.map +0 -1
  69. package/lib/webrtc/groupCall.d.ts +0 -323
  70. package/lib/webrtc/groupCall.d.ts.map +0 -1
  71. package/lib/webrtc/groupCall.js +0 -1337
  72. package/lib/webrtc/groupCall.js.map +0 -1
  73. package/lib/webrtc/groupCallEventHandler.d.ts +0 -31
  74. package/lib/webrtc/groupCallEventHandler.d.ts.map +0 -1
  75. package/lib/webrtc/groupCallEventHandler.js +0 -178
  76. package/lib/webrtc/groupCallEventHandler.js.map +0 -1
  77. package/lib/webrtc/mediaHandler.d.ts +0 -89
  78. package/lib/webrtc/mediaHandler.d.ts.map +0 -1
  79. package/lib/webrtc/mediaHandler.js +0 -437
  80. package/lib/webrtc/mediaHandler.js.map +0 -1
  81. package/lib/webrtc/stats/callFeedStatsReporter.d.ts +0 -8
  82. package/lib/webrtc/stats/callFeedStatsReporter.d.ts.map +0 -1
  83. package/lib/webrtc/stats/callFeedStatsReporter.js +0 -82
  84. package/lib/webrtc/stats/callFeedStatsReporter.js.map +0 -1
  85. package/lib/webrtc/stats/callStatsReportGatherer.d.ts +0 -25
  86. package/lib/webrtc/stats/callStatsReportGatherer.d.ts.map +0 -1
  87. package/lib/webrtc/stats/callStatsReportGatherer.js +0 -199
  88. package/lib/webrtc/stats/callStatsReportGatherer.js.map +0 -1
  89. package/lib/webrtc/stats/callStatsReportSummary.d.ts +0 -17
  90. package/lib/webrtc/stats/callStatsReportSummary.d.ts.map +0 -1
  91. package/lib/webrtc/stats/callStatsReportSummary.js +0 -1
  92. package/lib/webrtc/stats/callStatsReportSummary.js.map +0 -1
  93. package/lib/webrtc/stats/connectionStats.d.ts +0 -28
  94. package/lib/webrtc/stats/connectionStats.d.ts.map +0 -1
  95. package/lib/webrtc/stats/connectionStats.js +0 -26
  96. package/lib/webrtc/stats/connectionStats.js.map +0 -1
  97. package/lib/webrtc/stats/connectionStatsBuilder.d.ts +0 -5
  98. package/lib/webrtc/stats/connectionStatsBuilder.d.ts.map +0 -1
  99. package/lib/webrtc/stats/connectionStatsBuilder.js +0 -27
  100. package/lib/webrtc/stats/connectionStatsBuilder.js.map +0 -1
  101. package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts +0 -7
  102. package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts.map +0 -1
  103. package/lib/webrtc/stats/connectionStatsReportBuilder.js +0 -121
  104. package/lib/webrtc/stats/connectionStatsReportBuilder.js.map +0 -1
  105. package/lib/webrtc/stats/groupCallStats.d.ts +0 -22
  106. package/lib/webrtc/stats/groupCallStats.d.ts.map +0 -1
  107. package/lib/webrtc/stats/groupCallStats.js +0 -78
  108. package/lib/webrtc/stats/groupCallStats.js.map +0 -1
  109. package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts +0 -10
  110. package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts.map +0 -1
  111. package/lib/webrtc/stats/media/mediaSsrcHandler.js +0 -57
  112. package/lib/webrtc/stats/media/mediaSsrcHandler.js.map +0 -1
  113. package/lib/webrtc/stats/media/mediaTrackHandler.d.ts +0 -12
  114. package/lib/webrtc/stats/media/mediaTrackHandler.d.ts.map +0 -1
  115. package/lib/webrtc/stats/media/mediaTrackHandler.js +0 -62
  116. package/lib/webrtc/stats/media/mediaTrackHandler.js.map +0 -1
  117. package/lib/webrtc/stats/media/mediaTrackStats.d.ts +0 -86
  118. package/lib/webrtc/stats/media/mediaTrackStats.d.ts.map +0 -1
  119. package/lib/webrtc/stats/media/mediaTrackStats.js +0 -142
  120. package/lib/webrtc/stats/media/mediaTrackStats.js.map +0 -1
  121. package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts +0 -22
  122. package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts.map +0 -1
  123. package/lib/webrtc/stats/media/mediaTrackStatsHandler.js +0 -76
  124. package/lib/webrtc/stats/media/mediaTrackStatsHandler.js.map +0 -1
  125. package/lib/webrtc/stats/statsReport.d.ts +0 -99
  126. package/lib/webrtc/stats/statsReport.d.ts.map +0 -1
  127. package/lib/webrtc/stats/statsReport.js +0 -32
  128. package/lib/webrtc/stats/statsReport.js.map +0 -1
  129. package/lib/webrtc/stats/statsReportEmitter.d.ts +0 -15
  130. package/lib/webrtc/stats/statsReportEmitter.d.ts.map +0 -1
  131. package/lib/webrtc/stats/statsReportEmitter.js +0 -33
  132. package/lib/webrtc/stats/statsReportEmitter.js.map +0 -1
  133. package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts +0 -16
  134. package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts.map +0 -1
  135. package/lib/webrtc/stats/summaryStatsReportGatherer.js +0 -116
  136. package/lib/webrtc/stats/summaryStatsReportGatherer.js.map +0 -1
  137. package/lib/webrtc/stats/trackStatsBuilder.d.ts +0 -19
  138. package/lib/webrtc/stats/trackStatsBuilder.d.ts.map +0 -1
  139. package/lib/webrtc/stats/trackStatsBuilder.js +0 -168
  140. package/lib/webrtc/stats/trackStatsBuilder.js.map +0 -1
  141. package/lib/webrtc/stats/transportStats.d.ts +0 -11
  142. package/lib/webrtc/stats/transportStats.d.ts.map +0 -1
  143. package/lib/webrtc/stats/transportStats.js +0 -1
  144. package/lib/webrtc/stats/transportStats.js.map +0 -1
  145. package/lib/webrtc/stats/transportStatsBuilder.d.ts +0 -5
  146. package/lib/webrtc/stats/transportStatsBuilder.d.ts.map +0 -1
  147. package/lib/webrtc/stats/transportStatsBuilder.js +0 -34
  148. package/lib/webrtc/stats/transportStatsBuilder.js.map +0 -1
  149. package/lib/webrtc/stats/valueFormatter.d.ts +0 -4
  150. package/lib/webrtc/stats/valueFormatter.d.ts.map +0 -1
  151. package/lib/webrtc/stats/valueFormatter.js +0 -25
  152. package/lib/webrtc/stats/valueFormatter.js.map +0 -1
  153. package/src/matrixrtc/CallMembership.ts +0 -247
  154. package/src/matrixrtc/LivekitFocus.ts +0 -39
  155. package/src/matrixrtc/MatrixRTCSession.ts +0 -1319
  156. package/src/matrixrtc/MatrixRTCSessionManager.ts +0 -166
  157. package/src/matrixrtc/focus.ts +0 -25
  158. package/src/matrixrtc/index.ts +0 -22
  159. package/src/matrixrtc/types.ts +0 -36
  160. package/src/webrtc/audioContext.ts +0 -44
  161. package/src/webrtc/call.ts +0 -3074
  162. package/src/webrtc/callEventHandler.ts +0 -425
  163. package/src/webrtc/callEventTypes.ts +0 -93
  164. package/src/webrtc/callFeed.ts +0 -364
  165. package/src/webrtc/groupCall.ts +0 -1735
  166. package/src/webrtc/groupCallEventHandler.ts +0 -234
  167. package/src/webrtc/mediaHandler.ts +0 -484
  168. package/src/webrtc/stats/callFeedStatsReporter.ts +0 -94
  169. package/src/webrtc/stats/callStatsReportGatherer.ts +0 -219
  170. package/src/webrtc/stats/callStatsReportSummary.ts +0 -30
  171. package/src/webrtc/stats/connectionStats.ts +0 -47
  172. package/src/webrtc/stats/connectionStatsBuilder.ts +0 -28
  173. package/src/webrtc/stats/connectionStatsReportBuilder.ts +0 -140
  174. package/src/webrtc/stats/groupCallStats.ts +0 -93
  175. package/src/webrtc/stats/media/mediaSsrcHandler.ts +0 -57
  176. package/src/webrtc/stats/media/mediaTrackHandler.ts +0 -76
  177. package/src/webrtc/stats/media/mediaTrackStats.ts +0 -176
  178. package/src/webrtc/stats/media/mediaTrackStatsHandler.ts +0 -90
  179. package/src/webrtc/stats/statsReport.ts +0 -133
  180. package/src/webrtc/stats/statsReportEmitter.ts +0 -49
  181. package/src/webrtc/stats/summaryStatsReportGatherer.ts +0 -148
  182. package/src/webrtc/stats/trackStatsBuilder.ts +0 -207
  183. package/src/webrtc/stats/transportStats.ts +0 -26
  184. package/src/webrtc/stats/transportStatsBuilder.ts +0 -48
  185. package/src/webrtc/stats/valueFormatter.ts +0 -27
@@ -1,166 +0,0 @@
1
- /*
2
- Copyright 2023 The Matrix.org Foundation C.I.C.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- import { logger as rootLogger } from "../logger.ts";
18
- import { MatrixClient, ClientEvent } from "../client.ts";
19
- import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
20
- import { Room, RoomEvent } from "../models/room.ts";
21
- import { RoomState, RoomStateEvent } from "../models/room-state.ts";
22
- import { MatrixEvent } from "../models/event.ts";
23
- import { MatrixRTCSession } from "./MatrixRTCSession.ts";
24
- import { EventType } from "../@types/event.ts";
25
-
26
- const logger = rootLogger.getChild("MatrixRTCSessionManager");
27
-
28
- export enum MatrixRTCSessionManagerEvents {
29
- // A member has joined the MatrixRTC session, creating an active session in a room where there wasn't previously
30
- SessionStarted = "session_started",
31
- // All participants have left a given MatrixRTC session.
32
- SessionEnded = "session_ended",
33
- }
34
-
35
- type EventHandlerMap = {
36
- [MatrixRTCSessionManagerEvents.SessionStarted]: (roomId: string, session: MatrixRTCSession) => void;
37
- [MatrixRTCSessionManagerEvents.SessionEnded]: (roomId: string, session: MatrixRTCSession) => void;
38
- };
39
-
40
- /**
41
- * Holds all active MatrixRTC session objects and creates new ones as events arrive.
42
- * This interface is UNSTABLE and may change without warning.
43
- */
44
- export class MatrixRTCSessionManager extends TypedEventEmitter<MatrixRTCSessionManagerEvents, EventHandlerMap> {
45
- // All the room-scoped sessions we know about. This will include any where the app
46
- // has queried for the MatrixRTC sessions in a room, whether it's ever had any members
47
- // or not). We keep a (lazily created) session object for every room to ensure that there
48
- // is only ever one single room session object for any given room for the lifetime of the
49
- // client: that way there can never be any code holding onto a stale object that is no
50
- // longer the correct session object for the room.
51
- private roomSessions = new Map<string, MatrixRTCSession>();
52
-
53
- public constructor(private client: MatrixClient) {
54
- super();
55
- }
56
-
57
- public start(): void {
58
- // We shouldn't need to null-check here, but matrix-client.spec.ts mocks getRooms
59
- // returning nothing, and breaks tests if you change it to return an empty array :'(
60
- for (const room of this.client.getRooms() ?? []) {
61
- const session = MatrixRTCSession.roomSessionForRoom(this.client, room);
62
- if (session.memberships.length > 0) {
63
- this.roomSessions.set(room.roomId, session);
64
- }
65
- }
66
-
67
- this.client.on(ClientEvent.Room, this.onRoom);
68
- this.client.on(RoomEvent.Timeline, this.onTimeline);
69
- this.client.on(RoomStateEvent.Events, this.onRoomState);
70
- }
71
-
72
- public stop(): void {
73
- for (const sess of this.roomSessions.values()) {
74
- sess.stop();
75
- }
76
- this.roomSessions.clear();
77
-
78
- this.client.off(ClientEvent.Room, this.onRoom);
79
- this.client.off(RoomEvent.Timeline, this.onTimeline);
80
- this.client.off(RoomStateEvent.Events, this.onRoomState);
81
- }
82
-
83
- /**
84
- * Gets the main MatrixRTC session for a room, or undefined if there is
85
- * no current session
86
- */
87
- public getActiveRoomSession(room: Room): MatrixRTCSession | undefined {
88
- return this.roomSessions.get(room.roomId)!;
89
- }
90
-
91
- /**
92
- * Gets the main MatrixRTC session for a room, returning an empty session
93
- * if no members are currently participating
94
- */
95
- public getRoomSession(room: Room): MatrixRTCSession {
96
- if (!this.roomSessions.has(room.roomId)) {
97
- this.roomSessions.set(room.roomId, MatrixRTCSession.roomSessionForRoom(this.client, room));
98
- }
99
-
100
- return this.roomSessions.get(room.roomId)!;
101
- }
102
-
103
- private async consumeCallEncryptionEvent(event: MatrixEvent, isRetry = false): Promise<void> {
104
- await this.client.decryptEventIfNeeded(event);
105
- if (event.isDecryptionFailure()) {
106
- if (!isRetry) {
107
- logger.warn(
108
- `Decryption failed for event ${event.getId()}: ${event.decryptionFailureReason} will retry once only`,
109
- );
110
- // retry after 1 second. After this we give up.
111
- setTimeout(() => this.consumeCallEncryptionEvent(event, true), 1000);
112
- } else {
113
- logger.warn(`Decryption failed for event ${event.getId()}: ${event.decryptionFailureReason}`);
114
- }
115
- return;
116
- } else if (isRetry) {
117
- logger.info(`Decryption succeeded for event ${event.getId()} after retry`);
118
- }
119
-
120
- if (event.getType() !== EventType.CallEncryptionKeysPrefix) return Promise.resolve();
121
-
122
- const room = this.client.getRoom(event.getRoomId());
123
- if (!room) {
124
- logger.error(`Got room state event for unknown room ${event.getRoomId()}!`);
125
- return Promise.resolve();
126
- }
127
-
128
- this.getRoomSession(room).onCallEncryption(event);
129
- }
130
- private onTimeline = (event: MatrixEvent): void => {
131
- this.consumeCallEncryptionEvent(event);
132
- };
133
-
134
- private onRoom = (room: Room): void => {
135
- this.refreshRoom(room);
136
- };
137
-
138
- private onRoomState = (event: MatrixEvent, _state: RoomState): void => {
139
- const room = this.client.getRoom(event.getRoomId());
140
- if (!room) {
141
- logger.error(`Got room state event for unknown room ${event.getRoomId()}!`);
142
- return;
143
- }
144
-
145
- if (event.getType() == EventType.GroupCallMemberPrefix) {
146
- this.refreshRoom(room);
147
- }
148
- };
149
-
150
- private refreshRoom(room: Room): void {
151
- const isNewSession = !this.roomSessions.has(room.roomId);
152
- const sess = this.getRoomSession(room);
153
-
154
- const wasActiveAndKnown = sess.memberships.length > 0 && !isNewSession;
155
-
156
- sess.onMembershipUpdate();
157
-
158
- const nowActive = sess.memberships.length > 0;
159
-
160
- if (wasActiveAndKnown && !nowActive) {
161
- this.emit(MatrixRTCSessionManagerEvents.SessionEnded, room.roomId, this.roomSessions.get(room.roomId)!);
162
- } else if (!wasActiveAndKnown && nowActive) {
163
- this.emit(MatrixRTCSessionManagerEvents.SessionStarted, room.roomId, this.roomSessions.get(room.roomId)!);
164
- }
165
- }
166
- }
@@ -1,25 +0,0 @@
1
- /*
2
- Copyright 2023 The Matrix.org Foundation C.I.C.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- /**
18
- * Information about a MatrixRTC conference focus. The only attribute that
19
- * the js-sdk (currently) knows about is the type: applications can extend
20
- * this class for different types of focus.
21
- */
22
- export interface Focus {
23
- type: string;
24
- [key: string]: unknown;
25
- }
@@ -1,22 +0,0 @@
1
- /*
2
- Copyright 2024 The Matrix.org Foundation C.I.C.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- export * from "./CallMembership.ts";
18
- export type * from "./focus.ts";
19
- export * from "./LivekitFocus.ts";
20
- export * from "./MatrixRTCSession.ts";
21
- export * from "./MatrixRTCSessionManager.ts";
22
- export type * from "./types.ts";
@@ -1,36 +0,0 @@
1
- /*
2
- Copyright 2023 The Matrix.org Foundation C.I.C.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
- import { IMentions } from "../matrix.ts";
17
- export interface EncryptionKeyEntry {
18
- index: number;
19
- key: string;
20
- }
21
-
22
- export interface EncryptionKeysEventContent {
23
- keys: EncryptionKeyEntry[];
24
- device_id: string;
25
- call_id: string;
26
- sent_ts?: number;
27
- }
28
-
29
- export type CallNotifyType = "ring" | "notify";
30
-
31
- export interface ICallNotifyContent {
32
- "application": string;
33
- "m.mentions": IMentions;
34
- "notify_type": CallNotifyType;
35
- "call_id": string;
36
- }
@@ -1,44 +0,0 @@
1
- /*
2
- Copyright 2022 The Matrix.org Foundation C.I.C.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- let audioContext: AudioContext | null = null;
18
- let refCount = 0;
19
-
20
- /**
21
- * Acquires a reference to the shared AudioContext.
22
- * It's highly recommended to reuse this AudioContext rather than creating your
23
- * own, because multiple AudioContexts can be problematic in some browsers.
24
- * Make sure to call releaseContext when you're done using it.
25
- * @returns The shared AudioContext
26
- */
27
- export const acquireContext = (): AudioContext => {
28
- if (audioContext === null) audioContext = new AudioContext();
29
- refCount++;
30
- return audioContext;
31
- };
32
-
33
- /**
34
- * Signals that one of the references to the shared AudioContext has been
35
- * released, allowing the context and associated hardware resources to be
36
- * cleaned up if nothing else is using it.
37
- */
38
- export const releaseContext = (): void => {
39
- refCount--;
40
- if (refCount === 0) {
41
- audioContext?.close();
42
- audioContext = null;
43
- }
44
- };