@simplito/privmx-webendpoint 2.6.4 → 2.7.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/CONTRIBUTING.md +86 -0
- package/README.md +97 -7
- package/assets/driver-web-context.js +1 -1
- package/assets/e2ee-worker.js +1 -1
- package/assets/endpoint-wasm-module.js +3 -3
- package/assets/endpoint-wasm-module.wasm +0 -0
- package/assets/rms-processor.js +1 -0
- package/build-manifest.sh +6 -0
- package/{FinalizationHelper.js → dist/FinalizationHelper.js} +1 -1
- package/dist/ServerTypes.d.ts +7 -0
- package/{Types.d.ts → dist/Types.d.ts} +97 -10
- package/{Types.js → dist/Types.js} +17 -32
- package/{api → dist/api}/Api.d.ts +2 -0
- package/{api → dist/api}/Api.js +18 -1
- package/{api → dist/api}/ConnectionNative.js +1 -1
- package/{api → dist/api}/CryptoApiNative.js +1 -2
- package/{api → dist/api}/InboxApiNative.d.ts +21 -2
- package/{api → dist/api}/KvdbApiNative.d.ts +19 -2
- package/dist/api/NativeError.d.ts +13 -0
- package/dist/api/NativeError.js +20 -0
- package/{api → dist/api}/StoreApiNative.d.ts +19 -2
- package/dist/api/StreamApiNative.d.ts +72 -0
- package/dist/api/StreamApiNative.js +142 -0
- package/{api → dist/api}/ThreadApiNative.d.ts +19 -2
- package/dist/assets/e2ee-worker.js +1 -0
- package/dist/bundle/privmx-endpoint-web.js +2 -0
- package/dist/bundle/privmx-endpoint-web.js.LICENSE.txt +30 -0
- package/dist/bundle/rms-processor.js +1 -0
- package/{extra → dist/extra}/PrivmxClient.d.ts +9 -9
- package/{extra → dist/extra}/PrivmxClient.js +12 -12
- package/{extra → dist/extra}/PublicConnection.d.ts +2 -2
- package/{extra → dist/extra}/PublicConnection.js +2 -2
- package/{extra → dist/extra}/__tests__/connectionEventManager.test.js +1 -3
- package/{extra → dist/extra}/__tests__/customEventManager.test.js +1 -3
- package/{extra → dist/extra}/__tests__/userEventManager.test.js +2 -6
- package/{extra → dist/extra}/__tests__/utils.test.js +18 -18
- package/{extra → dist/extra}/events.js +32 -12
- package/{extra → dist/extra}/files.d.ts +5 -5
- package/{extra → dist/extra}/files.js +11 -11
- package/{extra → dist/extra}/generics.d.ts +1 -1
- package/{extra → dist/extra}/inbox.d.ts +1 -1
- package/{extra → dist/extra}/inbox.js +2 -2
- package/{extra → dist/extra}/index.d.ts +7 -7
- package/{extra → dist/extra}/managers.js +1 -1
- package/{extra → dist/extra}/utils.js +9 -9
- package/{index.d.ts → dist/index.d.ts} +3 -2
- package/{index.js → dist/index.js} +4 -1
- package/{service → dist/service}/Connection.js +13 -6
- package/{service → dist/service}/CryptoApi.js +2 -8
- package/{service → dist/service}/EndpointFactory.d.ts +11 -0
- package/{service → dist/service}/EndpointFactory.js +45 -10
- package/{service → dist/service}/EventApi.js +9 -5
- package/dist/service/EventDispatcher.d.ts +15 -0
- package/dist/service/EventDispatcher.js +25 -0
- package/{service → dist/service}/EventQueue.d.ts +4 -4
- package/{service → dist/service}/EventQueue.js +5 -9
- package/{service → dist/service}/ExtKey.d.ts +10 -10
- package/{service → dist/service}/ExtKey.js +10 -10
- package/{service → dist/service}/InboxApi.js +7 -11
- package/{service → dist/service}/KvdbApi.js +12 -7
- package/{service → dist/service}/StoreApi.js +10 -15
- package/dist/service/StreamApi.d.ts +237 -0
- package/dist/service/StreamApi.js +442 -0
- package/{service → dist/service}/ThreadApi.js +6 -7
- package/{service → dist/service}/UserVerifierInterface.d.ts +2 -2
- package/dist/service/UserVerifierInterface.js +2 -0
- package/dist/service/WebRtcInterface.d.ts +58 -0
- package/dist/service/WebRtcInterface.js +8 -0
- package/{service → dist/service}/index.d.ts +3 -2
- package/{service → dist/service}/index.js +5 -3
- package/dist/webStreams/CryptoUtils.d.ts +24 -0
- package/dist/webStreams/CryptoUtils.js +58 -0
- package/dist/webStreams/KeyStore.d.ts +9 -0
- package/dist/webStreams/KeyStore.js +29 -0
- package/dist/webStreams/Logger.d.ts +7 -0
- package/dist/webStreams/Logger.js +25 -0
- package/dist/webStreams/PeerConnectionsManager.d.ts +20 -0
- package/dist/webStreams/PeerConnectionsManager.js +92 -0
- package/dist/webStreams/Queue.d.ts +19 -0
- package/dist/webStreams/Queue.js +70 -0
- package/dist/webStreams/Utils.d.ts +20 -0
- package/dist/webStreams/Utils.js +211 -0
- package/dist/webStreams/WebRtcClient.d.ts +85 -0
- package/dist/webStreams/WebRtcClient.js +437 -0
- package/dist/webStreams/WebRtcClientTypes.d.ts +64 -0
- package/dist/webStreams/WebRtcClientTypes.js +2 -0
- package/dist/webStreams/WebRtcConfig.d.ts +20 -0
- package/dist/webStreams/WebRtcConfig.js +53 -0
- package/dist/webStreams/WebRtcInterfaceImpl.d.ts +28 -0
- package/dist/webStreams/WebRtcInterfaceImpl.js +85 -0
- package/dist/webStreams/WebWorkerHelper copy.d.ts +0 -0
- package/dist/webStreams/WebWorkerHelper copy.js +17 -0
- package/dist/webStreams/WebWorkerHelper.d.ts +18 -0
- package/dist/webStreams/WebWorkerHelper.js +69 -0
- package/dist/webStreams/audio/ActiveSpeakerDetector.d.ts +38 -0
- package/dist/webStreams/audio/ActiveSpeakerDetector.js +64 -0
- package/dist/webStreams/audio/LocalAudioLevelMeter.d.ts +12 -0
- package/dist/webStreams/audio/LocalAudioLevelMeter.js +101 -0
- package/dist/webStreams/types/ApiTypes.d.ts +74 -0
- package/dist/webStreams/types/ApiTypes.js +2 -0
- package/dist/webStreams/types/BaseServerTypes.d.ts +10 -0
- package/dist/webStreams/types/BaseServerTypes.js +2 -0
- package/dist/webStreams/types/MediaServerWebSocketApiTypes.d.ts +255 -0
- package/dist/webStreams/types/MediaServerWebSocketApiTypes.js +2 -0
- package/dist/webStreams/types/SignalingReceiverTypes.d.ts +13 -0
- package/dist/webStreams/types/SignalingReceiverTypes.js +2 -0
- package/dist/webStreams/types/SignalingSenderTypes.d.ts +24 -0
- package/dist/webStreams/types/SignalingSenderTypes.js +2 -0
- package/dist/webStreams/types/StreamsApiTypes.d.ts +144 -0
- package/dist/webStreams/types/StreamsApiTypes.js +2 -0
- package/dist/webStreams/worker/WorkerEvents.d.ts +11 -0
- package/dist/webStreams/worker/WorkerEvents.js +2 -0
- package/dist/webStreams/worker/worker.d.ts +13 -0
- package/dist/webStreams/worker/worker.js +202 -0
- package/package.json +46 -15
- package/assets/endpoint-wasm-module.worker.js +0 -1
- package/assets/privmx-endpoint-web.js +0 -2
- package/bundle/privmx-endpoint-web.js +0 -2
- package/bundle/privmx-endpoint-web.js.LICENSE.txt +0 -10
- /package/{FinalizationHelper.d.ts → dist/FinalizationHelper.d.ts} +0 -0
- /package/{extra/generics.js → dist/ServerTypes.js} +0 -0
- /package/{api → dist/api}/ApiStatic.d.ts +0 -0
- /package/{api → dist/api}/ApiStatic.js +0 -0
- /package/{api → dist/api}/BaseNative.d.ts +0 -0
- /package/{api → dist/api}/BaseNative.js +0 -0
- /package/{api → dist/api}/ConnectionNative.d.ts +0 -0
- /package/{api → dist/api}/CryptoApiNative.d.ts +0 -0
- /package/{api → dist/api}/EventApiNative.d.ts +0 -0
- /package/{api → dist/api}/EventApiNative.js +0 -0
- /package/{api → dist/api}/EventQueueNative.d.ts +0 -0
- /package/{api → dist/api}/EventQueueNative.js +0 -0
- /package/{api → dist/api}/ExtKeyNative.d.ts +0 -0
- /package/{api → dist/api}/ExtKeyNative.js +0 -0
- /package/{api → dist/api}/IdGenerator.d.ts +0 -0
- /package/{api → dist/api}/IdGenerator.js +0 -0
- /package/{api → dist/api}/InboxApiNative.js +0 -0
- /package/{api → dist/api}/KvdbApiNative.js +0 -0
- /package/{api → dist/api}/StoreApiNative.js +0 -0
- /package/{api → dist/api}/ThreadApiNative.js +0 -0
- /package/{bundle.d.ts → dist/bundle.d.ts} +0 -0
- /package/{bundle.js → dist/bundle.js} +0 -0
- /package/{extra → dist/extra}/__mocks__/constants.d.ts +0 -0
- /package/{extra → dist/extra}/__mocks__/constants.js +0 -0
- /package/{extra → dist/extra}/__mocks__/mockContainerSubscriber.d.ts +0 -0
- /package/{extra → dist/extra}/__mocks__/mockContainerSubscriber.js +0 -0
- /package/{extra → dist/extra}/__mocks__/mockEventQueue.d.ts +0 -0
- /package/{extra → dist/extra}/__mocks__/mockEventQueue.js +0 -0
- /package/{extra → dist/extra}/__mocks__/utils.d.ts +0 -0
- /package/{extra → dist/extra}/__mocks__/utils.js +0 -0
- /package/{extra → dist/extra}/__tests__/connectionEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/customEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/eventsManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/eventsManager.test.js +0 -0
- /package/{extra → dist/extra}/__tests__/inboxEventManager.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/inboxEventManager.js +0 -0
- /package/{extra → dist/extra}/__tests__/storeEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/storeEventManager.test.js +0 -0
- /package/{extra → dist/extra}/__tests__/threadEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/threadEventManager.test.js +0 -0
- /package/{extra → dist/extra}/__tests__/userEventManager.test.d.ts +0 -0
- /package/{extra → dist/extra}/__tests__/utils.test.d.ts +0 -0
- /package/{extra → dist/extra}/events.d.ts +0 -0
- /package/{service/UserVerifierInterface.js → dist/extra/generics.js} +0 -0
- /package/{extra → dist/extra}/index.js +0 -0
- /package/{extra → dist/extra}/managers.d.ts +0 -0
- /package/{extra → dist/extra}/subscriptions.d.ts +0 -0
- /package/{extra → dist/extra}/subscriptions.js +0 -0
- /package/{extra → dist/extra}/utils.d.ts +0 -0
- /package/{service → dist/service}/BaseApi.d.ts +0 -0
- /package/{service → dist/service}/BaseApi.js +0 -0
- /package/{service → dist/service}/Connection.d.ts +0 -0
- /package/{service → dist/service}/CryptoApi.d.ts +0 -0
- /package/{service → dist/service}/EventApi.d.ts +0 -0
- /package/{service → dist/service}/InboxApi.d.ts +0 -0
- /package/{service → dist/service}/KvdbApi.d.ts +0 -0
- /package/{service → dist/service}/StoreApi.d.ts +0 -0
- /package/{service → dist/service}/ThreadApi.d.ts +0 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { Types } from "../ServerTypes";
|
|
2
|
+
import * as EndpointTypes from "../Types";
|
|
3
|
+
import { AudioLevelsStats, WebRtcClient } from "../webStreams/WebRtcClient";
|
|
4
|
+
import { DataChannelMeta } from "../webStreams/types/ApiTypes";
|
|
5
|
+
import { BaseApi } from "./BaseApi";
|
|
6
|
+
import { ContainerPolicy, PagingList, PagingQuery, StreamInfo, StreamEventSelectorType, StreamEventType, StreamRoom, UserWithPubKey, StreamHandle, StreamSubscription, StreamPublishResult, RemoteStreamListener } from "../Types";
|
|
7
|
+
import { StreamApiNative } from "../api/StreamApiNative";
|
|
8
|
+
import { Buffer } from "buffer";
|
|
9
|
+
export interface StreamTrack {
|
|
10
|
+
id: Types.StreamTrackId;
|
|
11
|
+
streamId?: Types.StreamId;
|
|
12
|
+
streamHandle: StreamHandle;
|
|
13
|
+
track?: MediaStreamTrack;
|
|
14
|
+
dataChannelMeta?: DataChannelMeta;
|
|
15
|
+
published: Boolean;
|
|
16
|
+
markedToRemove?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* `StreamApi` is a class representing Endpoint's API for Stream Rooms.
|
|
20
|
+
*/
|
|
21
|
+
export declare class StreamApi extends BaseApi {
|
|
22
|
+
private native;
|
|
23
|
+
private client;
|
|
24
|
+
constructor(native: StreamApiNative, ptr: number, client: WebRtcClient);
|
|
25
|
+
private streams;
|
|
26
|
+
private streamTracks;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new Stream Room in given Context.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} contextId ID of the Context to create the Stream Room in
|
|
31
|
+
* @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Stream Room
|
|
32
|
+
* @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the created Stream Room
|
|
33
|
+
* @param {Uint8Array} publicMeta public (unencrypted) metadata
|
|
34
|
+
* @param {Uint8Array} privateMeta private (encrypted) metadata
|
|
35
|
+
* @param {ContainerPolicy} policies Stream Room's policies (pass `undefined` to use defaults)
|
|
36
|
+
* @returns {string} ID of the created Stream Room
|
|
37
|
+
*/
|
|
38
|
+
createStreamRoom(contextId: string, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, policies?: ContainerPolicy): Promise<Types.StreamRoomId>;
|
|
39
|
+
/**
|
|
40
|
+
* Updates an existing Stream Room.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} streamRoomId ID of the Stream Room to update
|
|
43
|
+
* @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the Stream Room
|
|
44
|
+
* @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the Stream Room
|
|
45
|
+
* @param {Uint8Array} publicMeta public (unencrypted) metadata
|
|
46
|
+
* @param {Uint8Array} privateMeta private (encrypted) metadata
|
|
47
|
+
* @param {number} version current version of the updated Stream Room
|
|
48
|
+
* @param {boolean} force force update (without checking version)
|
|
49
|
+
* @param {boolean} forceGenerateNewKey force to regenerate a key for the Stream Room
|
|
50
|
+
* @param {ContainerPolicy} policies Stream Room's policies (pass `undefined` to keep current/defaults)
|
|
51
|
+
*/
|
|
52
|
+
updateStreamRoom(streamRoomId: Types.StreamRoomId, users: UserWithPubKey[], managers: UserWithPubKey[], publicMeta: Uint8Array, privateMeta: Uint8Array, version: number, force: boolean, forceGenerateNewKey: boolean, policies?: ContainerPolicy): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Gets a list of Stream Rooms in given Context.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} contextId ID of the Context to get the Stream Rooms from
|
|
57
|
+
* @param {PagingQuery} query struct with list query parameters
|
|
58
|
+
* @returns {PagingList<StreamRoom>} list of Stream Rooms
|
|
59
|
+
*/
|
|
60
|
+
listStreamRooms(contextId: string, query: PagingQuery): Promise<PagingList<StreamRoom>>;
|
|
61
|
+
/**
|
|
62
|
+
* Joins a Stream Room.
|
|
63
|
+
*
|
|
64
|
+
* This is required before calling `createStream`/`publishStream` and before subscribing to remote streams
|
|
65
|
+
* in the room.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} streamRoomId ID of the Stream Room to join
|
|
68
|
+
*/
|
|
69
|
+
joinStreamRoom(streamRoomId: Types.StreamRoomId): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Leaves a Stream Room.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} streamRoomId ID of the Stream Room to leave
|
|
74
|
+
*/
|
|
75
|
+
leaveStreamRoom(streamRoomId: Types.StreamRoomId): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Enables server-side recording for the Stream Room.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
80
|
+
*/
|
|
81
|
+
enableStreamRoomRecording(streamRoomId: Types.StreamRoomId): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Gets encryption keys used for Stream Room recordings.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
86
|
+
* @returns {EndpointTypes.RecordingEncKey[]} list of recording encryption keys
|
|
87
|
+
*/
|
|
88
|
+
getStreamRoomRecordingKeys(streamRoomId: Types.StreamRoomId): Promise<EndpointTypes.RecordingEncKey[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Gets a single Stream Room by given Stream Room ID.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} streamRoomId ID of the Stream Room to get
|
|
93
|
+
* @returns {StreamRoom} information about the Stream Room
|
|
94
|
+
*/
|
|
95
|
+
getStreamRoom(streamRoomId: Types.StreamRoomId): Promise<StreamRoom>;
|
|
96
|
+
/**
|
|
97
|
+
* Deletes a Stream Room by given Stream Room ID.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} streamRoomId ID of the Stream Room to delete
|
|
100
|
+
*/
|
|
101
|
+
deleteStreamRoom(streamRoomId: Types.StreamRoomId): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Creates a local Stream handle for publishing media in given Stream Room.
|
|
104
|
+
*
|
|
105
|
+
* Call `addStreamTrack`/`removeStreamTrack` to stage tracks and `publishStream`/`updateStream` to send
|
|
106
|
+
* changes to the server.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} streamRoomId ID of the Stream Room to create the stream in
|
|
109
|
+
* @returns {StreamHandle} handle to a local Stream instance
|
|
110
|
+
*/
|
|
111
|
+
createStream(streamRoomId: Types.StreamRoomId): Promise<StreamHandle>;
|
|
112
|
+
/**
|
|
113
|
+
* Gets a list of currently published streams in given Stream Room.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} streamRoomId ID of the Stream Room to list streams from
|
|
116
|
+
* @returns {StreamInfo[]} list of StreamInfo structs describing currently published streams
|
|
117
|
+
*/
|
|
118
|
+
listStreams(streamRoomId: Types.StreamRoomId): Promise<StreamInfo[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Adds a local media track or a data channel definition to a Stream handle.
|
|
121
|
+
*
|
|
122
|
+
* The track is staged locally and becomes visible to others after `publishStream`/`updateStream`.
|
|
123
|
+
*
|
|
124
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
125
|
+
* @param {Types.StreamTrackMeta} meta track/data channel metadata (track: `MediaStreamTrack`, dataChannel: `DataChannelMeta`)
|
|
126
|
+
* @returns {string} StreamTrackId assigned locally for this track
|
|
127
|
+
* @throws {Error} when the given `streamHandle` does not exist or the same browser track is already staged
|
|
128
|
+
*/
|
|
129
|
+
addStreamTrack(streamHandle: StreamHandle, meta: Types.StreamTrackMeta): Promise<Types.StreamTrackId>;
|
|
130
|
+
/**
|
|
131
|
+
* Removes a previously added media track from a Stream handle.
|
|
132
|
+
*
|
|
133
|
+
* For already published streams the removal is applied on `updateStream`.
|
|
134
|
+
*
|
|
135
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
136
|
+
* @param {Types.StreamTrackMeta} meta media track metadata previously passed to `addStreamTrack`
|
|
137
|
+
* @throws {Error} when the given `streamHandle` does not exist
|
|
138
|
+
*/
|
|
139
|
+
removeStreamTrack(streamHandle: StreamHandle, meta: Types.StreamTrackMeta): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Sends a data message over a stream data track.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} _streamTrackId StreamTrackId returned by `addStreamTrack`
|
|
144
|
+
* @param {Buffer} _data data to send
|
|
145
|
+
* @throws {Error} not implemented
|
|
146
|
+
*/
|
|
147
|
+
streamTrackSendData(_streamTrackId: Types.StreamTrackId, _data: Buffer): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Registers a data receive callback for a stream data track.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} _streamTrackId StreamTrackId returned by `addStreamTrack`
|
|
152
|
+
* @param {(data: Buffer) => void} _onData callback invoked when data is received
|
|
153
|
+
* @throws {Error} not implemented
|
|
154
|
+
*/
|
|
155
|
+
streamTrackRecvData(_streamTrackId: Types.StreamTrackId, _onData: (data: Buffer) => void): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Publishes the Stream (with currently staged tracks) to the server.
|
|
158
|
+
*
|
|
159
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
160
|
+
* @param {(state: RTCPeerConnectionState) => void} onStreamState optional callback invoked on RTCPeerConnection state changes
|
|
161
|
+
* @returns {StreamPublishResult} result of the publish operation
|
|
162
|
+
* @throws {Error} when the given `streamHandle` does not exist
|
|
163
|
+
*/
|
|
164
|
+
publishStream(streamHandle: StreamHandle, onStreamState?: (state: RTCPeerConnectionState) => void): Promise<StreamPublishResult>;
|
|
165
|
+
/**
|
|
166
|
+
* Updates a published Stream after adding/removing tracks.
|
|
167
|
+
*
|
|
168
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
169
|
+
* @returns {StreamPublishResult} result of the update operation
|
|
170
|
+
* @throws {Error} when the given `streamHandle` does not exist
|
|
171
|
+
*/
|
|
172
|
+
updateStream(streamHandle: StreamHandle): Promise<StreamPublishResult>;
|
|
173
|
+
private filterMapByValue;
|
|
174
|
+
/**
|
|
175
|
+
* Stops publishing the Stream.
|
|
176
|
+
*
|
|
177
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
178
|
+
* @throws {Error} when the given `streamHandle` does not exist
|
|
179
|
+
*/
|
|
180
|
+
unpublishStream(streamHandle: StreamHandle): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Subscribes to selected remote streams (and optionally specific tracks) in the Stream Room.
|
|
183
|
+
*
|
|
184
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
185
|
+
* @param {EndpointTypes.StreamSubscription[]} subscriptions list of remote streams/tracks to subscribe to
|
|
186
|
+
*/
|
|
187
|
+
subscribeToRemoteStreams(streamRoomId: Types.StreamRoomId, subscriptions: EndpointTypes.StreamSubscription[]): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Modifies current remote streams subscriptions.
|
|
190
|
+
*
|
|
191
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
192
|
+
* @param {EndpointTypes.StreamSubscription[]} subscriptionsToAdd list of subscriptions to add
|
|
193
|
+
* @param {StreamSubscription[]} subscriptionsToRemove list of subscriptions to remove
|
|
194
|
+
*/
|
|
195
|
+
modifyRemoteStreamsSubscriptions(streamRoomId: Types.StreamRoomId, subscriptionsToAdd: EndpointTypes.StreamSubscription[], subscriptionsToRemove: StreamSubscription[]): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Unsubscribes from selected remote streams (and optionally specific tracks) in the Stream Room.
|
|
198
|
+
*
|
|
199
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
200
|
+
* @param {StreamSubscription[]} subscriptions list of subscriptions to remove
|
|
201
|
+
*/
|
|
202
|
+
unsubscribeFromRemoteStreams(streamRoomId: Types.StreamRoomId, subscriptions: StreamSubscription[]): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Registers a listener for remote tracks in the Stream Room.
|
|
205
|
+
*
|
|
206
|
+
* @param {RemoteStreamListener} listener listener configuration
|
|
207
|
+
* @param {string} listener.streamRoomId ID of the Stream Room
|
|
208
|
+
* @param {number} [listener.streamId] optional remote Stream ID to filter events (omit for all streams)
|
|
209
|
+
* @param {(event: RTCTrackEvent) => void} listener.onRemoteStreamTrack callback invoked for incoming remote tracks
|
|
210
|
+
*/
|
|
211
|
+
addRemoteStreamListener(listener: RemoteStreamListener): void;
|
|
212
|
+
/**
|
|
213
|
+
* Subscribe for the Stream Room events on the given subscription query.
|
|
214
|
+
*
|
|
215
|
+
* @param {string[]} subscriptionQueries list of queries
|
|
216
|
+
* @return list of subscriptionIds in maching order to subscriptionQueries
|
|
217
|
+
*/
|
|
218
|
+
subscribeFor(subscriptionQueries: string[]): Promise<string[]>;
|
|
219
|
+
/**
|
|
220
|
+
* Unsubscribe from events for the given subscriptionId.
|
|
221
|
+
* @param {string[]} subscriptionIds list of subscriptionId
|
|
222
|
+
*/
|
|
223
|
+
unsubscribeFrom(subscriptionIds: string[]): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Generate subscription Query for the Stream Room events.
|
|
226
|
+
* @param {EventType} eventType type of event which you listen for
|
|
227
|
+
* @param {EventSelectorType} selectorType scope on which you listen for events
|
|
228
|
+
* @param {string} selectorId ID of the selector
|
|
229
|
+
*/
|
|
230
|
+
buildSubscriptionQuery(eventType: StreamEventType, selectorType: StreamEventSelectorType, selectorId: string): Promise<string>;
|
|
231
|
+
/**
|
|
232
|
+
* Registers a callback for audio level statistics produced by the WebRTC client.
|
|
233
|
+
*
|
|
234
|
+
* @param {(stats: AudioLevelsStats) => void} onStats callback invoked with current audio levels stats
|
|
235
|
+
*/
|
|
236
|
+
addAudioLevelStatsListener(onStats: (stats: AudioLevelsStats) => void): Promise<void>;
|
|
237
|
+
}
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StreamApi = void 0;
|
|
4
|
+
const Utils_1 = require("../webStreams/Utils");
|
|
5
|
+
const BaseApi_1 = require("./BaseApi");
|
|
6
|
+
/**
|
|
7
|
+
* `StreamApi` is a class representing Endpoint's API for Stream Rooms.
|
|
8
|
+
*/
|
|
9
|
+
class StreamApi extends BaseApi_1.BaseApi {
|
|
10
|
+
native;
|
|
11
|
+
client;
|
|
12
|
+
constructor(native, ptr, client) {
|
|
13
|
+
super(ptr);
|
|
14
|
+
this.native = native;
|
|
15
|
+
this.client = client;
|
|
16
|
+
}
|
|
17
|
+
// local data
|
|
18
|
+
streams = new Map();
|
|
19
|
+
streamTracks = new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new Stream Room in given Context.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} contextId ID of the Context to create the Stream Room in
|
|
24
|
+
* @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the created Stream Room
|
|
25
|
+
* @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the created Stream Room
|
|
26
|
+
* @param {Uint8Array} publicMeta public (unencrypted) metadata
|
|
27
|
+
* @param {Uint8Array} privateMeta private (encrypted) metadata
|
|
28
|
+
* @param {ContainerPolicy} policies Stream Room's policies (pass `undefined` to use defaults)
|
|
29
|
+
* @returns {string} ID of the created Stream Room
|
|
30
|
+
*/
|
|
31
|
+
async createStreamRoom(contextId, users, managers, publicMeta, privateMeta, policies) {
|
|
32
|
+
const res = await this.native.createStreamRoom(this.servicePtr, [
|
|
33
|
+
contextId,
|
|
34
|
+
users,
|
|
35
|
+
managers,
|
|
36
|
+
publicMeta,
|
|
37
|
+
privateMeta,
|
|
38
|
+
policies,
|
|
39
|
+
]);
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Updates an existing Stream Room.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} streamRoomId ID of the Stream Room to update
|
|
46
|
+
* @param {UserWithPubKey[]} users array of UserWithPubKey structs which indicates who will have access to the Stream Room
|
|
47
|
+
* @param {UserWithPubKey[]} managers array of UserWithPubKey structs which indicates who will have access (and management rights) to the Stream Room
|
|
48
|
+
* @param {Uint8Array} publicMeta public (unencrypted) metadata
|
|
49
|
+
* @param {Uint8Array} privateMeta private (encrypted) metadata
|
|
50
|
+
* @param {number} version current version of the updated Stream Room
|
|
51
|
+
* @param {boolean} force force update (without checking version)
|
|
52
|
+
* @param {boolean} forceGenerateNewKey force to regenerate a key for the Stream Room
|
|
53
|
+
* @param {ContainerPolicy} policies Stream Room's policies (pass `undefined` to keep current/defaults)
|
|
54
|
+
*/
|
|
55
|
+
async updateStreamRoom(streamRoomId, users, managers, publicMeta, privateMeta, version, force, forceGenerateNewKey, policies) {
|
|
56
|
+
return this.native.updateStreamRoom(this.servicePtr, [
|
|
57
|
+
streamRoomId,
|
|
58
|
+
users,
|
|
59
|
+
managers,
|
|
60
|
+
publicMeta,
|
|
61
|
+
privateMeta,
|
|
62
|
+
version,
|
|
63
|
+
force,
|
|
64
|
+
forceGenerateNewKey,
|
|
65
|
+
policies,
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets a list of Stream Rooms in given Context.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} contextId ID of the Context to get the Stream Rooms from
|
|
72
|
+
* @param {PagingQuery} query struct with list query parameters
|
|
73
|
+
* @returns {PagingList<StreamRoom>} list of Stream Rooms
|
|
74
|
+
*/
|
|
75
|
+
async listStreamRooms(contextId, query) {
|
|
76
|
+
return this.native.listStreamRooms(this.servicePtr, [contextId, query]);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Joins a Stream Room.
|
|
80
|
+
*
|
|
81
|
+
* This is required before calling `createStream`/`publishStream` and before subscribing to remote streams
|
|
82
|
+
* in the room.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} streamRoomId ID of the Stream Room to join
|
|
85
|
+
*/
|
|
86
|
+
async joinStreamRoom(streamRoomId) {
|
|
87
|
+
return this.native.joinStreamRoom(this.servicePtr, [streamRoomId]);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Leaves a Stream Room.
|
|
91
|
+
*
|
|
92
|
+
* @param {string} streamRoomId ID of the Stream Room to leave
|
|
93
|
+
*/
|
|
94
|
+
async leaveStreamRoom(streamRoomId) {
|
|
95
|
+
return this.native.leaveStreamRoom(this.servicePtr, [streamRoomId]);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Enables server-side recording for the Stream Room.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
101
|
+
*/
|
|
102
|
+
async enableStreamRoomRecording(streamRoomId) {
|
|
103
|
+
return this.native.enableStreamRoomRecording(this.servicePtr, [streamRoomId]);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Gets encryption keys used for Stream Room recordings.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
109
|
+
* @returns {EndpointTypes.RecordingEncKey[]} list of recording encryption keys
|
|
110
|
+
*/
|
|
111
|
+
async getStreamRoomRecordingKeys(streamRoomId) {
|
|
112
|
+
return this.native.getStreamRoomRecordingKeys(this.servicePtr, [streamRoomId]);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Gets a single Stream Room by given Stream Room ID.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} streamRoomId ID of the Stream Room to get
|
|
118
|
+
* @returns {StreamRoom} information about the Stream Room
|
|
119
|
+
*/
|
|
120
|
+
async getStreamRoom(streamRoomId) {
|
|
121
|
+
return this.native.getStreamRoom(this.servicePtr, [streamRoomId]);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Deletes a Stream Room by given Stream Room ID.
|
|
125
|
+
*
|
|
126
|
+
* @param {string} streamRoomId ID of the Stream Room to delete
|
|
127
|
+
*/
|
|
128
|
+
async deleteStreamRoom(streamRoomId) {
|
|
129
|
+
return this.native.deleteStreamRoom(this.servicePtr, [streamRoomId]);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Creates a local Stream handle for publishing media in given Stream Room.
|
|
133
|
+
*
|
|
134
|
+
* Call `addStreamTrack`/`removeStreamTrack` to stage tracks and `publishStream`/`updateStream` to send
|
|
135
|
+
* changes to the server.
|
|
136
|
+
*
|
|
137
|
+
* @param {string} streamRoomId ID of the Stream Room to create the stream in
|
|
138
|
+
* @returns {StreamHandle} handle to a local Stream instance
|
|
139
|
+
*/
|
|
140
|
+
async createStream(streamRoomId) {
|
|
141
|
+
const meta = {};
|
|
142
|
+
// tutaj uzupelniajac opcjonalne pola obiektu meta mozemy ustawiac w Janusie dodatkowe rzeczy
|
|
143
|
+
const handle = await this.native.createStream(this.servicePtr, [streamRoomId]);
|
|
144
|
+
this.streams.set(handle, { handle, streamRoomId, createStreamMeta: meta, remote: false });
|
|
145
|
+
return handle;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Gets a list of currently published streams in given Stream Room.
|
|
149
|
+
*
|
|
150
|
+
* @param {string} streamRoomId ID of the Stream Room to list streams from
|
|
151
|
+
* @returns {StreamInfo[]} list of StreamInfo structs describing currently published streams
|
|
152
|
+
*/
|
|
153
|
+
async listStreams(streamRoomId) {
|
|
154
|
+
const remoteStreams = await this.native.listStreams(this.servicePtr, [streamRoomId]);
|
|
155
|
+
return remoteStreams;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Adds a local media track or a data channel definition to a Stream handle.
|
|
159
|
+
*
|
|
160
|
+
* The track is staged locally and becomes visible to others after `publishStream`/`updateStream`.
|
|
161
|
+
*
|
|
162
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
163
|
+
* @param {Types.StreamTrackMeta} meta track/data channel metadata (track: `MediaStreamTrack`, dataChannel: `DataChannelMeta`)
|
|
164
|
+
* @returns {string} StreamTrackId assigned locally for this track
|
|
165
|
+
* @throws {Error} when the given `streamHandle` does not exist or the same browser track is already staged
|
|
166
|
+
*/
|
|
167
|
+
async addStreamTrack(streamHandle, meta) {
|
|
168
|
+
// if (streamTrack.dataChannelMeta) {
|
|
169
|
+
// await this.client.provideSession();
|
|
170
|
+
// const request: StreamDataTrackAddRequest = {
|
|
171
|
+
// kind: "streams.streamDataTrackAdd",
|
|
172
|
+
// data: {
|
|
173
|
+
// streamRoomId: stream.streamRoomId,
|
|
174
|
+
// streamId: streamTrack.streamId,
|
|
175
|
+
// streamTrackId: streamTrack.id,
|
|
176
|
+
// meta: streamTrack.dataChannelMeta
|
|
177
|
+
// }
|
|
178
|
+
// };
|
|
179
|
+
// await this.serverChannel.call<StreamsApi.StreamDataTrackAddRequest, void>(request);
|
|
180
|
+
// }
|
|
181
|
+
if (!this.streams.has(streamHandle)) {
|
|
182
|
+
throw new Error("[addStreamTrack]: there is no Stream with given Id: " + streamHandle);
|
|
183
|
+
}
|
|
184
|
+
let alreadyAddedId = "";
|
|
185
|
+
const tracksByHandle = Array.from(this.streamTracks.values()).filter((x) => x.streamHandle === streamHandle);
|
|
186
|
+
for (const streamTrack of tracksByHandle) {
|
|
187
|
+
if (streamTrack.track && streamTrack.track?.id === meta.track?.id) {
|
|
188
|
+
if (streamTrack.markedToRemove === true) {
|
|
189
|
+
streamTrack.markedToRemove === undefined;
|
|
190
|
+
alreadyAddedId = streamTrack.id;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
throw new Error("[addStreamTrack] StreamTrack with given browser's track already added.");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (alreadyAddedId.length > 0) {
|
|
199
|
+
return alreadyAddedId;
|
|
200
|
+
}
|
|
201
|
+
const stream = this.streams.get(streamHandle);
|
|
202
|
+
if (!stream) {
|
|
203
|
+
throw new Error("Cannot find stream by id");
|
|
204
|
+
}
|
|
205
|
+
const streamTrackId = Utils_1.Utils.getRandomString(16);
|
|
206
|
+
const streamTrack = {
|
|
207
|
+
id: streamTrackId,
|
|
208
|
+
streamHandle: streamHandle,
|
|
209
|
+
track: meta.track,
|
|
210
|
+
dataChannelMeta: meta.dataChannel,
|
|
211
|
+
published: false,
|
|
212
|
+
};
|
|
213
|
+
this.streamTracks.set(streamTrackId, streamTrack);
|
|
214
|
+
return streamTrackId;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Removes a previously added media track from a Stream handle.
|
|
218
|
+
*
|
|
219
|
+
* For already published streams the removal is applied on `updateStream`.
|
|
220
|
+
*
|
|
221
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
222
|
+
* @param {Types.StreamTrackMeta} meta media track metadata previously passed to `addStreamTrack`
|
|
223
|
+
* @throws {Error} when the given `streamHandle` does not exist
|
|
224
|
+
*/
|
|
225
|
+
async removeStreamTrack(streamHandle, meta) {
|
|
226
|
+
if (!this.streams.has(streamHandle)) {
|
|
227
|
+
throw new Error("[removeStreamTrack]: there is no Stream with given Id: " + streamHandle);
|
|
228
|
+
}
|
|
229
|
+
for (const [key, streamTrack] of this.streamTracks.entries()) {
|
|
230
|
+
if (streamTrack.track &&
|
|
231
|
+
streamTrack.track?.id === meta.track?.id &&
|
|
232
|
+
streamTrack.streamHandle === streamHandle) {
|
|
233
|
+
streamTrack.markedToRemove = true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Sends a data message over a stream data track.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} _streamTrackId StreamTrackId returned by `addStreamTrack`
|
|
241
|
+
* @param {Buffer} _data data to send
|
|
242
|
+
* @throws {Error} not implemented
|
|
243
|
+
*/
|
|
244
|
+
async streamTrackSendData(_streamTrackId, _data) {
|
|
245
|
+
throw new Error("not implemented");
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Registers a data receive callback for a stream data track.
|
|
249
|
+
*
|
|
250
|
+
* @param {string} _streamTrackId StreamTrackId returned by `addStreamTrack`
|
|
251
|
+
* @param {(data: Buffer) => void} _onData callback invoked when data is received
|
|
252
|
+
* @throws {Error} not implemented
|
|
253
|
+
*/
|
|
254
|
+
async streamTrackRecvData(_streamTrackId, _onData) {
|
|
255
|
+
throw new Error("not implemented");
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Publishes the Stream (with currently staged tracks) to the server.
|
|
259
|
+
*
|
|
260
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
261
|
+
* @param {(state: RTCPeerConnectionState) => void} onStreamState optional callback invoked on RTCPeerConnection state changes
|
|
262
|
+
* @returns {StreamPublishResult} result of the publish operation
|
|
263
|
+
* @throws {Error} when the given `streamHandle` does not exist
|
|
264
|
+
*/
|
|
265
|
+
async publishStream(streamHandle, onStreamState) {
|
|
266
|
+
const mediaTracks = [];
|
|
267
|
+
for (const value of this.streamTracks.values()) {
|
|
268
|
+
if (value.streamHandle === streamHandle &&
|
|
269
|
+
value.track &&
|
|
270
|
+
!value.markedToRemove &&
|
|
271
|
+
value.published === false) {
|
|
272
|
+
mediaTracks.push(value.track);
|
|
273
|
+
value.published = true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const _stream = this.streams.get(streamHandle);
|
|
277
|
+
if (!_stream) {
|
|
278
|
+
throw new Error("No stream defined to publish");
|
|
279
|
+
}
|
|
280
|
+
const mediaStream = new MediaStream(mediaTracks);
|
|
281
|
+
_stream.localMediaStream = mediaStream;
|
|
282
|
+
const turnCredentials = await this.native.getTurnCredentials(this.servicePtr, []);
|
|
283
|
+
await this.client.setTurnCredentials(turnCredentials);
|
|
284
|
+
await this.client.createPeerConnectionWithLocalStream(streamHandle, _stream.streamRoomId, mediaStream);
|
|
285
|
+
if (onStreamState && typeof onStreamState === "function") {
|
|
286
|
+
this.client
|
|
287
|
+
.getStreamStateChangeDispatcher()
|
|
288
|
+
.addOnStateChangeListener({ streamHandle: streamHandle }, (event) => onStreamState(event.state));
|
|
289
|
+
}
|
|
290
|
+
const res = await this.native.publishStream(this.servicePtr, [streamHandle]);
|
|
291
|
+
return res;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Updates a published Stream after adding/removing tracks.
|
|
295
|
+
*
|
|
296
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
297
|
+
* @returns {StreamPublishResult} result of the update operation
|
|
298
|
+
* @throws {Error} when the given `streamHandle` does not exist
|
|
299
|
+
*/
|
|
300
|
+
async updateStream(streamHandle) {
|
|
301
|
+
// configure client
|
|
302
|
+
const tracksToAdd = [];
|
|
303
|
+
const tracksToRemove = [];
|
|
304
|
+
for (const value of this.streamTracks.values()) {
|
|
305
|
+
if (value.streamHandle === streamHandle && value.track) {
|
|
306
|
+
if (!value.published && !value.markedToRemove) {
|
|
307
|
+
tracksToAdd.push(value.track);
|
|
308
|
+
}
|
|
309
|
+
if (value.markedToRemove) {
|
|
310
|
+
tracksToRemove.push(value.track);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const _stream = this.streams.get(streamHandle);
|
|
315
|
+
if (!_stream) {
|
|
316
|
+
throw new Error("No stream defined to publish");
|
|
317
|
+
}
|
|
318
|
+
const turnCredentials = await this.native.getTurnCredentials(this.servicePtr, []);
|
|
319
|
+
await this.client.setTurnCredentials(turnCredentials);
|
|
320
|
+
await this.client.updatePeerConnectionWithLocalStream(_stream.streamRoomId, _stream.localMediaStream, tracksToAdd, tracksToRemove);
|
|
321
|
+
const res = await this.native.updateStream(this.servicePtr, [streamHandle]);
|
|
322
|
+
return res;
|
|
323
|
+
}
|
|
324
|
+
filterMapByValue(map, predicate) {
|
|
325
|
+
const result = new Map();
|
|
326
|
+
for (const [key, value] of map) {
|
|
327
|
+
if (predicate(value, key)) {
|
|
328
|
+
result.set(key, value);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Stops publishing the Stream.
|
|
335
|
+
*
|
|
336
|
+
* @param {StreamHandle} streamHandle handle returned by `createStream`
|
|
337
|
+
* @throws {Error} when the given `streamHandle` does not exist
|
|
338
|
+
*/
|
|
339
|
+
async unpublishStream(streamHandle) {
|
|
340
|
+
if (!this.streams.has(streamHandle)) {
|
|
341
|
+
throw new Error("No local stream with given id to unpublish");
|
|
342
|
+
}
|
|
343
|
+
const _stream = this.streams.get(streamHandle);
|
|
344
|
+
const filteredTracks = this.filterMapByValue(this.streamTracks, (x) => x.streamHandle !== streamHandle);
|
|
345
|
+
this.streamTracks = filteredTracks;
|
|
346
|
+
await this.native.unpublishStream(this.servicePtr, [streamHandle]);
|
|
347
|
+
this.client.removeSenderPeerConnectionOnUnpublish(_stream.streamRoomId, _stream.localMediaStream);
|
|
348
|
+
this.streams.delete(streamHandle);
|
|
349
|
+
this.client.getStreamStateChangeDispatcher().removeOnStateChangeListener({ streamHandle });
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Subscribes to selected remote streams (and optionally specific tracks) in the Stream Room.
|
|
353
|
+
*
|
|
354
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
355
|
+
* @param {EndpointTypes.StreamSubscription[]} subscriptions list of remote streams/tracks to subscribe to
|
|
356
|
+
*/
|
|
357
|
+
async subscribeToRemoteStreams(streamRoomId, subscriptions) {
|
|
358
|
+
// native part
|
|
359
|
+
const peerCredentials = await this.native.getTurnCredentials(this.servicePtr, []);
|
|
360
|
+
await this.client.setTurnCredentials(peerCredentials);
|
|
361
|
+
// server / core part
|
|
362
|
+
await this.native.subscribeToRemoteStreams(this.servicePtr, [streamRoomId, subscriptions]);
|
|
363
|
+
this.client.getConnectionManager().initialize(streamRoomId, "subscriber");
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Modifies current remote streams subscriptions.
|
|
367
|
+
*
|
|
368
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
369
|
+
* @param {EndpointTypes.StreamSubscription[]} subscriptionsToAdd list of subscriptions to add
|
|
370
|
+
* @param {StreamSubscription[]} subscriptionsToRemove list of subscriptions to remove
|
|
371
|
+
*/
|
|
372
|
+
async modifyRemoteStreamsSubscriptions(streamRoomId, subscriptionsToAdd, subscriptionsToRemove) {
|
|
373
|
+
await this.native.modifyRemoteStreamsSubscriptions(this.servicePtr, [
|
|
374
|
+
streamRoomId,
|
|
375
|
+
subscriptionsToAdd,
|
|
376
|
+
subscriptionsToRemove,
|
|
377
|
+
]);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Unsubscribes from selected remote streams (and optionally specific tracks) in the Stream Room.
|
|
381
|
+
*
|
|
382
|
+
* @param {string} streamRoomId ID of the Stream Room
|
|
383
|
+
* @param {StreamSubscription[]} subscriptions list of subscriptions to remove
|
|
384
|
+
*/
|
|
385
|
+
async unsubscribeFromRemoteStreams(streamRoomId, subscriptions) {
|
|
386
|
+
await this.native.unsubscribeFromRemoteStreams(this.servicePtr, [
|
|
387
|
+
streamRoomId,
|
|
388
|
+
subscriptions,
|
|
389
|
+
]);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Registers a listener for remote tracks in the Stream Room.
|
|
393
|
+
*
|
|
394
|
+
* @param {RemoteStreamListener} listener listener configuration
|
|
395
|
+
* @param {string} listener.streamRoomId ID of the Stream Room
|
|
396
|
+
* @param {number} [listener.streamId] optional remote Stream ID to filter events (omit for all streams)
|
|
397
|
+
* @param {(event: RTCTrackEvent) => void} listener.onRemoteStreamTrack callback invoked for incoming remote tracks
|
|
398
|
+
*/
|
|
399
|
+
addRemoteStreamListener(listener) {
|
|
400
|
+
this.client.addRemoteStreamListener(listener);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Subscribe for the Stream Room events on the given subscription query.
|
|
404
|
+
*
|
|
405
|
+
* @param {string[]} subscriptionQueries list of queries
|
|
406
|
+
* @return list of subscriptionIds in maching order to subscriptionQueries
|
|
407
|
+
*/
|
|
408
|
+
async subscribeFor(subscriptionQueries) {
|
|
409
|
+
return this.native.subscribeFor(this.servicePtr, [subscriptionQueries]);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Unsubscribe from events for the given subscriptionId.
|
|
413
|
+
* @param {string[]} subscriptionIds list of subscriptionId
|
|
414
|
+
*/
|
|
415
|
+
async unsubscribeFrom(subscriptionIds) {
|
|
416
|
+
return this.native.unsubscribeFrom(this.servicePtr, [subscriptionIds]);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Generate subscription Query for the Stream Room events.
|
|
420
|
+
* @param {EventType} eventType type of event which you listen for
|
|
421
|
+
* @param {EventSelectorType} selectorType scope on which you listen for events
|
|
422
|
+
* @param {string} selectorId ID of the selector
|
|
423
|
+
*/
|
|
424
|
+
async buildSubscriptionQuery(eventType, selectorType, selectorId) {
|
|
425
|
+
return this.native.buildSubscriptionQuery(this.servicePtr, [
|
|
426
|
+
eventType,
|
|
427
|
+
selectorType,
|
|
428
|
+
selectorId,
|
|
429
|
+
]);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Registers a callback for audio level statistics produced by the WebRTC client.
|
|
433
|
+
*
|
|
434
|
+
* @param {(stats: AudioLevelsStats) => void} onStats callback invoked with current audio levels stats
|
|
435
|
+
*/
|
|
436
|
+
async addAudioLevelStatsListener(onStats) {
|
|
437
|
+
if (onStats && typeof onStats === "function") {
|
|
438
|
+
this.client.setAudioLevelCallback(onStats);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
exports.StreamApi = StreamApi;
|