ovenlivekit 1.3.0 → 1.5.0

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/README.md CHANGED
@@ -1,381 +1,389 @@
1
- # OvenLiveKit for Web
2
-
3
- ## What is OvenLiveKit for Web?
4
- OvenLiveKit for Web is a JavaScript-based Live Streaming Encoder that supports WebRTC optimized for [OvenMediaEngine](https://github.com/AirenSoft/OvenMediaEngine), Sub-Second Latency Streaming Server. OvenLiveKit for Web relies on the browser's WebRTC API and wraps it to make it easy for you to broadcast WebRTC streams to OvenMediaEngine.
5
-
6
- ## Demo
7
- <img src="./assets/05_OvenSpace_230214.png" style="max-width: 100%; height: auto;">
8
-
9
- OvenSpace is a sub-second latency streaming demo service using [OvenMediaEngine](https://github.com/AirenSoft/OvenMediaEngine), [OvenPlayer](https://github.com/AirenSoft/OvenPlayer) and [OvenLiveKit](https://github.com/AirenSoft/OvenLiveKit-Web). You can experience OvenLiveKit in the **[OvenSpace Demo](https://space.ovenplayer.com/)** and see examples of how it can be applied in the [OvenSpace Repository](https://github.com/AirenSoft/OvenSpace).
10
-
11
- ## Features
12
- * Support WebRTC-HTTP ingestion protocol (WHIP) -Since 1.3.0
13
- * Streaming to OvenMediaEngine's WebRTC Provider.
14
- * Implement [OvenMediaEngine's signaling protocol](https://airensoft.gitbook.io/ovenmediaengine/live-source/webrtc-beta#custom-webrtc-producer)
15
- * Built-in Device, Screen Capture.
16
- * Set the Quality of the Input Stream.
17
-
18
- ## Quick Start
19
-
20
- ### OvenLiveKit Demo
21
- * https://demo.ovenplayer.com/demo_input.html
22
-
23
- ### Installation
24
- #### OveliveKit CDN
25
- ```html
26
- <script src="https://cdn.jsdelivr.net/npm/ovenlivekit@latest/dist/OvenLiveKit.min.js"></script>
27
- ```
28
- #### Install via npm
29
- ```
30
- $ npm install ovenlivekit
31
- ```
32
-
33
- ```JavaScript
34
- import OvenLiveKit from 'ovenlivekit'
35
- ```
36
- ### Getting started
37
- This is the simplest example of sending a device media stream such as a webcam to OvenMediaEngine's WebRTC Provider.
38
- ```JavaScript
39
- // Initialize OvenLiveKit
40
- const ovenLivekit = OvenLiveKit.create();
41
-
42
- // Get media stream from user device
43
- ovenLivekit.getUserMedia().then(function () {
44
-
45
- // Got device stream and start streaming to OvenMediaEngine
46
- ovenLivekit.startStreaming('https://your_oven_media_engine:3334/app/stream?direction=whip');
47
- });
48
-
49
- // Or you can get media stream of your display. Choose either user device or display.
50
- ovenLivekit.getDisplayMedia().then(function () {
51
-
52
- // Got device stream and start streaming to OvenMediaEngine
53
- ovenLivekit.startStreaming('https://your_oven_media_engine:3334/app/stream?direction=whip');
54
- });
55
- ```
56
- ### Quick demo
57
- You can see a quick demo in action by cloning the repository.
58
- 1. Clone repository
59
- ```
60
- $ git clone https://github.com/AirenSoft/OvenLiveKit-Web.git
61
- ```
62
- ```
63
- $ cd OvenLiveKit-Web
64
- ```
65
- 2. Install development dependencies.
66
- ```
67
- $ npm install
68
- ```
69
- 3. Open the demo page using the WebPack's built-in web server.
70
- ```
71
- $ npm run start
72
- ```
73
- ## Configurations & APIs
74
-
75
- - [`Initialization and destroying instance`](#)
76
- - `OvenLiveKit.create()`
77
- - `Configuration`
78
- - `instance.remove()`
79
- - [`Input device listing`](#)
80
- - `OvenLiveKit.getDevices()`
81
- - [`Media APIs`](#)
82
- - `instance.attachMedia(videoElement)`
83
- - `instance.getUserMedia()`
84
- - `instance.getDisplayMedia()`
85
- - `instance.setMediaStream(mediaStream)`
86
- - [`Streaming APIs`](#)
87
- - `instance.startStreaming()`
88
- - `instance.stopStreaming()`
89
-
90
- ### Initialization and destroying instance
91
- Configuration parameters could be provided to OvenLiveKit.js upon instantiation of the OvenLiveKit object.
92
-
93
- ```JavaScript
94
- // Configuration
95
- var config = {
96
- callbacks: {
97
- error: function (error) {
98
-
99
- },
100
- connected: function (event) {
101
-
102
- },
103
- connectionClosed: function (type, event) {
104
-
105
- },
106
- iceStateChange: function (state) {
107
-
108
- }
109
- }
110
- }
111
-
112
- // Initialize ovenLivekit instance
113
- const ovenLivekit = OvenLiveKit.create(config);
114
-
115
- // Release all resources and destroy the instance
116
- ovenLivekit.remove();
117
- ```
118
- #### `OvenLiveKit.create(config)`
119
- - parameters
120
- - config: [Initialization configurations](#).
121
- - Initialize OvenLiveKit instance. Please see the [configuration details](#) next.
122
-
123
- #### `Configurations`
124
- To make the library lightweight and easy to use, only callback options are implemented now.
125
- ##### `callbacks.error`
126
- - type
127
- - Function
128
- - parameters
129
- - error: Various Type of Error
130
- - A callback that receives any errors that occur in an instance of OvenLiveKit.
131
- - Errors are could occur from `getUserMedia`, `getDisplayMedia`, `webSocket`, or `peerConnection`.
132
-
133
- ##### `callbacks.connected`
134
- - type
135
- - Function
136
- - parameters
137
- - event: event object of iceconnectionstatechange
138
- - This is a callback that occurs when the `RTCPeerConnection.iceConnectionState` becomes `connected`.
139
- - It means that the media stream is being transmitted normally to OvenMediaEngine's WebRTC Provider.
140
-
141
- ##### `callbacks.connectionClosed`
142
- - type
143
- - Function
144
- - parameters
145
- - type: (`ice` | `websocket`) Notes which connection is closed.
146
- - event: event object of iceconnectionstatechange or websocket
147
- - A callback that is fired when the websocket's `onclose` event occurs, or when `RTCPeerConnection.iceConnectionState` changes to `failed`, `disconnected`, or `closed`.
148
- - It may be that the media stream is not being sent normally to OvenMediaEngine.
149
- ##### `callbacks.iceStateChange`
150
- - type
151
- - Function
152
- - parameters
153
- - event: event object of iceconnectionstatechange
154
- - A callback that fires whenever [`RTCPeerConnection.iceConnectionState`](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState) changes.
155
- - This is useful when checking the current streaming status.
156
-
157
- #### `instance.remove()`
158
- - Release all resources(websocket, peerconnection, mediastream) and destroy the instance.
159
-
160
- ### Input device listing
161
- OvenLiveKit provides an API to get a list of user devices for convenience.
162
- ```JavaScript
163
- // Lists the available media input and output devices
164
- OvenLiveKit.getDevices().then(function (devices) {
165
-
166
- // Got a list of user devices
167
- console.log(devices);
168
-
169
- /*
170
- console output is
171
-
172
- {
173
- "videoinput": [
174
- {
175
- "deviceId": "b1ab3a7041b1c9a91037b51d9c380f599f3914297b5c0ce2eb8d385dab3b8812",
176
- "label": "c922 Pro Stream Webcam (046d:085c)"
177
- }
178
- ],
179
- "audioinput": [
180
- {
181
- "deviceId": "default",
182
- "label": "default - Microphone(C922 Pro Stream Webcam) (046d:085c)"
183
- },
184
- {
185
- "deviceId": "communications",
186
- "label": "Communication - Microphone(C922 Pro Stream Webcam) (046d:085c)"
187
- },
188
- {
189
- "deviceId": "2feb7f29a130802404f47d8ad9adc9418b1a01e0a4d37e60335771aba21f328d",
190
- "label": "Microphone(C922 Pro Stream Webcam) (046d:085c)"
191
- }
192
- ],
193
- "audiooutput": [
194
- {
195
- "deviceId": "default",
196
- "label": "default - Headphone(2- Xbox Controller) (045e:02f6)"
197
- },
198
- {
199
- "deviceId": "communications",
200
- "label": "Communication - Headphone(2- Xbox Controller) (045e:02f6)"
201
- },
202
- {
203
- "deviceId": "c3d04828621712f9cc006c49486218aca0d89619ac9993809d5f082a2d13a6b0",
204
- "label": "Headphone(2- Xbox Controller) (045e:02f6)"
205
- },
206
- ],
207
- "other": []
208
- }
209
- */
210
-
211
- }).catch(function (error) {
212
-
213
- // Failed to get a list of user devices
214
- console.log(error);
215
- });
216
- ```
217
- #### `OvenLiveKit.getDevices()`
218
- - This static method lists the available media input and output devices, such as microphones, cameras, headsets, and so forth.
219
- - `videoinput`, `audioinput`, `audiooutput`, `other` is available input/output devices. You can use `deviceId` to specify a device to streaming or `label` to make device selection UI.
220
-
221
- ### Media APIs
222
- OvenLiveKit also provides APIs to control a media stream from a user device.
223
- ```HTML
224
- <video id="myVideo"></video>
225
- ```
226
- ```JavaScript
227
- // Create instance
228
- const ovenLivekit = OvenLiveKit.create();
229
-
230
- // Attaching video element for playing device stream
231
- ovenLivekit.attachMedia(document.getElementById('myVideo'));
232
-
233
- const constraint = {
234
- audio: true,
235
- video: true
236
- };
237
-
238
- // Gets a device stream with a constraint that specifies the type of media to request.
239
- ovenLivekit.getUserMedia(constraints).then(function (stream) {
240
-
241
- // Got device stream. Ready for streaming.
242
- ovenLivekit.startStreaming('https://your_oven_media_engine:3334/app/stream?direction=whip');
243
- }).catch(function (error) {
244
-
245
- // Failed to get device stream.
246
- console.error("Error", error);
247
- });
248
-
249
- // Display media also works in the same way.
250
- ovenLivekit.getDisplayMedia(constraints).then(function (stream) {
251
-
252
- // Got device stream. Ready for streaming.
253
- ovenLivekit.startStreaming('https://your_oven_media_engine:3334/app/stream?direction=whip');
254
- }).catch(function (error) {
255
-
256
- // Failed to get device stream.
257
- console.error("Error", error);
258
- });
259
- ```
260
- #### `instance.attachMedia(videoElement)`
261
- - parameters
262
- - videoElement: HTML `<video>` element
263
- - If the video element is attached, when the media stream is received from the user device, it starts playing in the automatically set video element.
264
- - This can be useful when previewing the media stream you want to stream.
265
-
266
- #### `instance.getUserMedia(constraints)`
267
- - parameters
268
- - constraints: [MediaStreamConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints) dictionary. If not set the optimal input that the browser thinks is selected.
269
- - returns Promise
270
- - resolved
271
- - stream: [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream). You can use this stream for whatever you need.
272
- - rejected
273
- - error: Throws error while getting the stream from the user device.
274
- - This API is the most important API in OvenLiveKit. Make the OvenLiveKit streamable by getting the media stream from the user input device. You can get the media stream from any user input device you want using the `constraints` parameter. The device ID to be used in the `constraints` parameter can also be obtained from `OvenLiveKit.getDevices()`.
275
- - For natural behavior, you can have the browser automatically select the device stream without passing a `constraints` parameter. However, if you want to control the device stream strictly (e.g., specify input devices, video resolution, video frame rates), you can control it by passing the constraints parameter.
276
-
277
- #### `instance.getDisplayMedia(constraints)`
278
- - parameters
279
- - constraints: [MediaStreamConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia#parameters)
280
- - returns Promise
281
- - resolved
282
- - stream: [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream). You can use this stream for whatever you need.
283
- - rejected
284
- - error: Throws error while getting the stream from the display.
285
- - Captures the entire screen, application window, or browser tab.
286
-
287
- #### `instance.setMediaStream(stream)`
288
- - parameters
289
- - stream: [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) - The valid MediaStream you want OvenLiveKit to utilize.
290
- - returns Promise
291
- - resolved
292
- - stream: [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) - Returns the same stream provided as an input, confirming its successful attachment.
293
- - rejected
294
- - error: Throws an error if an invalid MediaStream is provided.
295
- - The `setMediaStream` function is designed to let developers directly attach an external or pre-existing MediaStream. This can be particularly useful when you're sourcing the stream not directly from user input devices, but other origins.
296
-
297
-
298
- ### Streaming APIs
299
- Congrats on getting the media stream from the user device and then ready to stream into OvenMediaEngine.
300
- ```JavaScript
301
- // Create instance
302
- const ovenLivekit = OvenLiveKit.create();
303
-
304
- ovenLivekit.getUserMedia().then(function () {
305
-
306
- const connectionConfig = {
307
- iceServers : null ,
308
- iceTransportPolicy: null,
309
- maxBitrate: null
310
- }
311
-
312
- // Got media stream from user device and start to stream to OvenMedieEngeine
313
- ovenLivekit.startStreaming(connectionUrl, connectionConfig);
314
- });
315
- ```
316
- #### `instance.startStreaming(connectionUrl, connectionConfig)`
317
- - parameters
318
- - connectionUrl: The connection URL to OvenMediaEngine is explained [here](https://airensoft.gitbook.io/ovenmediaengine/live-source/webrtc-beta#url-pattern).
319
- - connectionConfig: See [ConnectionConfig](#) details next.
320
- - When this API is called, the media stream starts to be streamed according to OvenMediaEngine's signaling protocol.
321
-
322
- #### `ConnectionConfig`
323
-
324
- ##### `httpHeaders` - Since 1.3.0
325
- - type
326
- - `{ [key: string]: string}`
327
- - If set adds http headers to http request.
328
- - example
329
- - `{'Authorization': 'Bearer token'}`
330
-
331
- ##### `preferredVideoFormat`
332
- - type
333
- - String: Video codec name (eq. H256, VP8)
334
- - If set the specified codec will be preferred if available.
335
- ##### `iceServers`
336
- - type
337
- - [`RTCConfiguration.iceServers`](https://developer.mozilla.org/en-US/docs/Web/API/RTCConfiguration/iceServers)
338
- - If set use the set STUN and TURN servers.
339
- ##### `iceTransportPolicy`
340
- - type
341
- - [`RTCConfiguration.iceTransportPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/RTCConfiguration/iceTransportPolicy)
342
- - If set use the set ice policy.
343
- ##### `maxVideoBitrate`
344
- - type
345
- - Number: Unit is Kbps.
346
- - If set limits max bitrates of streaming to OvenMediaEngine.
347
-
348
- ##### `sdp.appendFmtp`
349
- - type
350
- - String: String you want to append to a=fmtp of SDP.
351
- - If set video format is appended to the a=fmtp sections of SDP.
352
-
353
-
354
- #### `instance.stopStreaming()`
355
- - Close peer connection and websocket associated with OvenMediaEngine.
356
-
357
- ## For more information
358
- * [AirenSoft Website](https://airensoft.com)
359
- * About OvenMediaEngine, OvenMediaEngine Enterprise, OvenVideo, AirenBlog and more
360
- * [OvenMediaEngine GitHub](https://github.com/AirenSoft/OvenMediaEngine)
361
- * Sub-Second Latency Streaming Server with LLHLS and WebRTC
362
- * [OvenMediaEngine Getting Started](https://airensoft.gitbook.io/ovenmediaengine/)
363
- * User guide for OvenMediaEngine Configuration, ABR, Clustering, and more
364
- * [OvenPlayer GitHub](https://github.com/AirenSoft/OvenPlayer)
365
- * JavaScript-based Player with LLHLS and WebRTC
366
- * [OvenPlayer Getting Started](https://airensoft.gitbook.io/ovenplayer)
367
- * User guide for OvenPlayer UI Customize, API Reference, Examples, and more
368
- * [OvenSpace Demo](https://space.ovenplayer.com/)
369
- * Sub-Second Latency Streaming Demo Service
370
-
371
- ## License
372
- OvenLiveKit for Web is licensed under the [MIT](./LICENSE) license.
373
-
374
- ## About AirenSoft
375
- AirenSoft aims to make it easier for you to build a stable broadcasting/streaming service with Sub-Second Latency.
376
- Therefore, we will continue developing and providing the most optimized tools for smooth Sub-Second Latency Streaming.
377
-
378
- Would you please click on each link below for details:
379
- * ["JavaScript-based Live Streaming Encoder" **OvenLiveKit**](https://github.com/AirenSoft/OvenLiveKit-Web)
380
- * ["Sub-Second Latency Streaming Server with LLHLS and WebRTC" **OvenMediaEngine**](https://github.com/AirenSoft/OvenMediaEngine)
381
- * ["JavaScript-based Player with LLHLS and WebRTC" **OvenPlayer**](https://github.com/AirenSoft/OvenPlayer)
1
+ # OvenLiveKit for Web
2
+
3
+ ## What is OvenLiveKit for Web?
4
+ OvenLiveKit for Web is a JavaScript-based Live Streaming Encoder that supports WebRTC optimized for [OvenMediaEngine](https://github.com/AirenSoft/OvenMediaEngine), Sub-Second Latency Streaming Server. OvenLiveKit for Web relies on the browser's WebRTC API and wraps it to make it easy for you to broadcast WebRTC streams to OvenMediaEngine.
5
+
6
+ ## Demo
7
+ <img src="./assets/05_OvenSpace_230214.png" style="max-width: 100%; height: auto;">
8
+
9
+ OvenSpace is a sub-second latency streaming demo service using [OvenMediaEngine](https://github.com/AirenSoft/OvenMediaEngine), [OvenPlayer](https://github.com/AirenSoft/OvenPlayer) and [OvenLiveKit](https://github.com/AirenSoft/OvenLiveKit-Web). You can experience OvenLiveKit in the **[OvenSpace Demo](https://space.ovenplayer.com/)** and see examples of how it can be applied in the [OvenSpace Repository](https://github.com/AirenSoft/OvenSpace).
10
+
11
+ ## Features
12
+ * Support WebRTC-HTTP ingestion protocol (WHIP) -Since 1.3.0
13
+ * Streaming to OvenMediaEngine's WebRTC Provider.
14
+ * Implement [OvenMediaEngine's signaling protocol](https://airensoft.gitbook.io/ovenmediaengine/live-source/webrtc-beta#custom-webrtc-producer)
15
+ * Built-in Device, Screen Capture.
16
+ * Set the Quality of the Input Stream.
17
+
18
+ ## Quick Start
19
+
20
+ ### OvenLiveKit Demo
21
+ * https://demo.ovenplayer.com/demo_input.html
22
+
23
+ ### Installation
24
+ #### OvenLiveKit CDN
25
+ ```html
26
+ <script src="https://cdn.jsdelivr.net/npm/ovenlivekit@latest/dist/OvenLiveKit.min.js"></script>
27
+ ```
28
+ #### Install via npm
29
+ ```
30
+ $ npm install ovenlivekit
31
+ ```
32
+
33
+ ```JavaScript
34
+ import OvenLiveKit from 'ovenlivekit'
35
+ ```
36
+ ### Getting started
37
+ This is the simplest example of sending a device media stream such as a webcam to OvenMediaEngine's WebRTC Provider.
38
+ ```JavaScript
39
+ // Initialize OvenLiveKit
40
+ const ovenLivekit = OvenLiveKit.create();
41
+
42
+ // Get media stream from user device
43
+ ovenLivekit.getUserMedia().then(function () {
44
+
45
+ // Got device stream and start streaming to OvenMediaEngine
46
+ ovenLivekit.startStreaming('https://your_oven_media_engine:3334/app/stream?direction=whip');
47
+ });
48
+
49
+ // Or you can get media stream of your display. Choose either user device or display.
50
+ ovenLivekit.getDisplayMedia().then(function () {
51
+
52
+ // Got device stream and start streaming to OvenMediaEngine
53
+ ovenLivekit.startStreaming('https://your_oven_media_engine:3334/app/stream?direction=whip');
54
+ });
55
+ ```
56
+ ### Quick demo
57
+ You can see a quick demo in action by cloning the repository.
58
+ 1. Clone repository
59
+ ```
60
+ $ git clone https://github.com/AirenSoft/OvenLiveKit-Web.git
61
+ ```
62
+ ```
63
+ $ cd OvenLiveKit-Web
64
+ ```
65
+ 2. Install development dependencies.
66
+ ```
67
+ $ npm install
68
+ ```
69
+ 3. Open the demo page using the WebPack's built-in web server.
70
+ ```
71
+ $ npm run start
72
+ ```
73
+ ## Configurations & APIs
74
+
75
+ - [`Initialization and destroying instance`](#)
76
+ - `OvenLiveKit.create()`
77
+ - `Configuration`
78
+ - `instance.remove()`
79
+ - [`Input device listing`](#)
80
+ - `OvenLiveKit.getDevices()`
81
+ - [`Media APIs`](#)
82
+ - `instance.attachMedia(videoElement)`
83
+ - `instance.getUserMedia()`
84
+ - `instance.getDisplayMedia()`
85
+ - `instance.setMediaStream(mediaStream)`
86
+ - [`Streaming APIs`](#)
87
+ - `instance.startStreaming()`
88
+ - `instance.stopStreaming()`
89
+
90
+ ### Initialization and destroying instance
91
+ Configuration parameters could be provided to OvenLiveKit.js upon instantiation of the OvenLiveKit object.
92
+
93
+ ```JavaScript
94
+ // Configuration
95
+ var config = {
96
+ callbacks: {
97
+ error: function (error) {
98
+
99
+ },
100
+ connected: function (event) {
101
+
102
+ },
103
+ connectionClosed: function (type, event) {
104
+
105
+ },
106
+ iceStateChange: function (state) {
107
+
108
+ }
109
+ }
110
+ }
111
+
112
+ // Initialize ovenLivekit instance
113
+ const ovenLivekit = OvenLiveKit.create(config);
114
+
115
+ // Release all resources and destroy the instance
116
+ ovenLivekit.remove();
117
+ ```
118
+ #### `OvenLiveKit.create(config)`
119
+ - parameters
120
+ - config: [Initialization configurations](#).
121
+ - Initialize OvenLiveKit instance. Please see the [configuration details](#) next.
122
+
123
+ #### `Configurations`
124
+ To make the library lightweight and easy to use, only callback options are implemented now.
125
+ ##### `callbacks.error`
126
+ - type
127
+ - Function
128
+ - parameters
129
+ - error: Various Type of Error
130
+ - A callback that receives any errors that occur in an instance of OvenLiveKit.
131
+ - Errors are could occur from `getUserMedia`, `getDisplayMedia`, `webSocket`, or `peerConnection`.
132
+
133
+ ##### `callbacks.connected`
134
+ - type
135
+ - Function
136
+ - parameters
137
+ - event: event object of iceconnectionstatechange
138
+ - This is a callback that occurs when the `RTCPeerConnection.iceConnectionState` becomes `connected`.
139
+ - It means that the media stream is being transmitted normally to OvenMediaEngine's WebRTC Provider.
140
+
141
+ ##### `callbacks.connectionClosed`
142
+ - type
143
+ - Function
144
+ - parameters
145
+ - type: (`ice` | `websocket`) Notes which connection is closed.
146
+ - event: event object of iceconnectionstatechange or websocket
147
+ - A callback that is fired when the websocket's `onclose` event occurs, or when `RTCPeerConnection.iceConnectionState` changes to `failed`, `disconnected`, or `closed`.
148
+ - It may be that the media stream is not being sent normally to OvenMediaEngine.
149
+ ##### `callbacks.iceStateChange`
150
+ - type
151
+ - Function
152
+ - parameters
153
+ - event: event object of iceconnectionstatechange
154
+ - A callback that fires whenever [`RTCPeerConnection.iceConnectionState`](https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState) changes.
155
+ - This is useful when checking the current streaming status.
156
+
157
+ #### `instance.remove()`
158
+ - Release all resources(websocket, peerconnection, mediastream) and destroy the instance.
159
+
160
+ ### Input device listing
161
+ OvenLiveKit provides an API to get a list of user devices for convenience.
162
+ ```JavaScript
163
+ // Lists the available media input and output devices
164
+ OvenLiveKit.getDevices().then(function (devices) {
165
+
166
+ // Got a list of user devices
167
+ console.log(devices);
168
+
169
+ /*
170
+ console output is
171
+
172
+ {
173
+ "videoinput": [
174
+ {
175
+ "deviceId": "b1ab3a7041b1c9a91037b51d9c380f599f3914297b5c0ce2eb8d385dab3b8812",
176
+ "label": "c922 Pro Stream Webcam (046d:085c)"
177
+ }
178
+ ],
179
+ "audioinput": [
180
+ {
181
+ "deviceId": "default",
182
+ "label": "default - Microphone(C922 Pro Stream Webcam) (046d:085c)"
183
+ },
184
+ {
185
+ "deviceId": "communications",
186
+ "label": "Communication - Microphone(C922 Pro Stream Webcam) (046d:085c)"
187
+ },
188
+ {
189
+ "deviceId": "2feb7f29a130802404f47d8ad9adc9418b1a01e0a4d37e60335771aba21f328d",
190
+ "label": "Microphone(C922 Pro Stream Webcam) (046d:085c)"
191
+ }
192
+ ],
193
+ "audiooutput": [
194
+ {
195
+ "deviceId": "default",
196
+ "label": "default - Headphone(2- Xbox Controller) (045e:02f6)"
197
+ },
198
+ {
199
+ "deviceId": "communications",
200
+ "label": "Communication - Headphone(2- Xbox Controller) (045e:02f6)"
201
+ },
202
+ {
203
+ "deviceId": "c3d04828621712f9cc006c49486218aca0d89619ac9993809d5f082a2d13a6b0",
204
+ "label": "Headphone(2- Xbox Controller) (045e:02f6)"
205
+ },
206
+ ],
207
+ "other": []
208
+ }
209
+ */
210
+
211
+ }).catch(function (error) {
212
+
213
+ // Failed to get a list of user devices
214
+ console.log(error);
215
+ });
216
+ ```
217
+ #### `OvenLiveKit.getDevices(type)`
218
+ - This method lists the available media input and output devices, such as microphones, cameras, headsets, and so forth.
219
+ - Specify a type 'audio' to list just audio devices, 'video' for video devices, or 'both' for all devices. The default is 'both' if no type is provided.
220
+ - `videoinput`, `audioinput`, `audiooutput`, `other` is available input/output devices. You can use `deviceId` to specify a device to streaming or `label` to make device selection UI.
221
+
222
+ ### Media APIs
223
+ OvenLiveKit also provides APIs to control a media stream from a user device.
224
+ ```HTML
225
+ <video id="myVideo"></video>
226
+ ```
227
+ ```JavaScript
228
+ // Create instance
229
+ const ovenLivekit = OvenLiveKit.create();
230
+
231
+ // Attaching video element for playing device stream
232
+ ovenLivekit.attachMedia(document.getElementById('myVideo'));
233
+
234
+ const constraint = {
235
+ audio: true,
236
+ video: true
237
+ };
238
+
239
+ // Gets a device stream with a constraint that specifies the type of media to request.
240
+ ovenLivekit.getUserMedia(constraints).then(function (stream) {
241
+
242
+ // Got device stream. Ready for streaming.
243
+ ovenLivekit.startStreaming('https://your_oven_media_engine:3334/app/stream?direction=whip');
244
+ }).catch(function (error) {
245
+
246
+ // Failed to get device stream.
247
+ console.error("Error", error);
248
+ });
249
+
250
+ // Display media also works in the same way.
251
+ ovenLivekit.getDisplayMedia(constraints).then(function (stream) {
252
+
253
+ // Got device stream. Ready for streaming.
254
+ ovenLivekit.startStreaming('https://your_oven_media_engine:3334/app/stream?direction=whip');
255
+ }).catch(function (error) {
256
+
257
+ // Failed to get device stream.
258
+ console.error("Error", error);
259
+ });
260
+ ```
261
+ #### `instance.attachMedia(videoElement)`
262
+ - parameters
263
+ - videoElement: HTML `<video>` element
264
+ - If the video element is attached, when the media stream is received from the user device, it starts playing in the automatically set video element.
265
+ - This can be useful when previewing the media stream you want to stream.
266
+
267
+ #### `instance.getUserMedia(constraints)`
268
+ - parameters
269
+ - constraints: [MediaStreamConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints) dictionary. If not set the optimal input that the browser thinks is selected.
270
+ - returns Promise
271
+ - resolved
272
+ - stream: [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream). You can use this stream for whatever you need.
273
+ - rejected
274
+ - error: Throws error while getting the stream from the user device.
275
+ - This API is the most important API in OvenLiveKit. Make the OvenLiveKit streamable by getting the media stream from the user input device. You can get the media stream from any user input device you want using the `constraints` parameter. The device ID to be used in the `constraints` parameter can also be obtained from `OvenLiveKit.getDevices()`.
276
+ - For natural behavior, you can have the browser automatically select the device stream without passing a `constraints` parameter. However, if you want to control the device stream strictly (e.g., specify input devices, video resolution, video frame rates), you can control it by passing the constraints parameter.
277
+
278
+ #### `instance.getDisplayMedia(constraints)`
279
+ - parameters
280
+ - constraints: [MediaStreamConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia#parameters)
281
+ - returns Promise
282
+ - resolved
283
+ - stream: [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream). You can use this stream for whatever you need.
284
+ - rejected
285
+ - error: Throws error while getting the stream from the display.
286
+ - Captures the entire screen, application window, or browser tab.
287
+
288
+ #### `instance.setMediaStream(stream)`
289
+ - parameters
290
+ - stream: [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) - The valid MediaStream you want OvenLiveKit to utilize.
291
+ - returns Promise
292
+ - resolved
293
+ - stream: [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) - Returns the same stream provided as an input, confirming its successful attachment.
294
+ - rejected
295
+ - error: Throws an error if an invalid MediaStream is provided.
296
+ - The `setMediaStream` function is designed to let developers directly attach an external or pre-existing MediaStream. This can be particularly useful when you're sourcing the stream not directly from user input devices, but other origins.
297
+
298
+
299
+ ### Streaming APIs
300
+ Congrats on getting the media stream from the user device and then ready to stream into OvenMediaEngine.
301
+ ```JavaScript
302
+ // Create instance
303
+ const ovenLivekit = OvenLiveKit.create();
304
+
305
+ ovenLivekit.getUserMedia().then(function () {
306
+
307
+ const connectionConfig = {
308
+ iceServers : null ,
309
+ iceTransportPolicy: null,
310
+ maxBitrate: null
311
+ }
312
+
313
+ // Got media stream from user device and start to stream to OvenMedieEngeine
314
+ ovenLivekit.startStreaming(connectionUrl, connectionConfig);
315
+ });
316
+ ```
317
+ #### `instance.startStreaming(connectionUrl, connectionConfig)`
318
+ - parameters
319
+ - connectionUrl: The connection URL to OvenMediaEngine is explained [here](https://airensoft.gitbook.io/ovenmediaengine/live-source/webrtc-beta#url-pattern).
320
+ - connectionConfig: See [ConnectionConfig](#) details next.
321
+ - When this API is called, the media stream starts to be streamed according to OvenMediaEngine's signaling protocol.
322
+
323
+ #### `ConnectionConfig`
324
+
325
+ ##### `simulcast` - Since 1.4.0
326
+ - type
327
+ - `RTCRtpEncodingParameters[]` [RTCRtpEncodingParameters](https://w3c.github.io/webrtc-pc/#rtcrtpencodingparameters)
328
+ - Defines layers for simulcast transmission.
329
+ - example
330
+ - `[{ rid: '1', active: true}, { rid: '2', active: true}, { rid: '3', active: true}]`
331
+
332
+ ##### `httpHeaders` - Since 1.3.0
333
+ - type
334
+ - `{ [key: string]: string}[]`
335
+ - If set adds http headers to http request.
336
+ - example
337
+ - `{'Authorization': 'Bearer token'}`
338
+
339
+ ##### `preferredVideoFormat`
340
+ - type
341
+ - String: Video codec name (eq. H256, VP8)
342
+ - If set the specified codec will be preferred if available.
343
+ ##### `iceServers`
344
+ - type
345
+ - [`RTCConfiguration.iceServers`](https://developer.mozilla.org/en-US/docs/Web/API/RTCConfiguration/iceServers)
346
+ - If set use the set STUN and TURN servers.
347
+ ##### `iceTransportPolicy`
348
+ - type
349
+ - [`RTCConfiguration.iceTransportPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/RTCConfiguration/iceTransportPolicy)
350
+ - If set use the set ice policy.
351
+ ##### `maxVideoBitrate`
352
+ - type
353
+ - Number: Unit is Kbps.
354
+ - If set limits max bitrates of streaming to OvenMediaEngine.
355
+
356
+ ##### `sdp.appendFmtp`
357
+ - type
358
+ - String: String you want to append to a=fmtp of SDP.
359
+ - If set video format is appended to the a=fmtp sections of SDP.
360
+
361
+
362
+ #### `instance.stopStreaming()`
363
+ - Close peer connection and websocket associated with OvenMediaEngine.
364
+
365
+ ## For more information
366
+ * [AirenSoft Website](https://airensoft.com)
367
+ * About OvenMediaEngine, OvenMediaEngine Enterprise, OvenVideo, AirenBlog and more
368
+ * [OvenMediaEngine GitHub](https://github.com/AirenSoft/OvenMediaEngine)
369
+ * Sub-Second Latency Streaming Server with LLHLS and WebRTC
370
+ * [OvenMediaEngine Getting Started](https://airensoft.gitbook.io/ovenmediaengine/)
371
+ * User guide for OvenMediaEngine Configuration, ABR, Clustering, and more
372
+ * [OvenPlayer GitHub](https://github.com/AirenSoft/OvenPlayer)
373
+ * JavaScript-based Player with LLHLS and WebRTC
374
+ * [OvenPlayer Getting Started](https://airensoft.gitbook.io/ovenplayer)
375
+ * User guide for OvenPlayer UI Customize, API Reference, Examples, and more
376
+ * [OvenSpace Demo](https://space.ovenplayer.com/)
377
+ * Sub-Second Latency Streaming Demo Service
378
+
379
+ ## License
380
+ OvenLiveKit for Web is licensed under the [MIT](./LICENSE) license.
381
+
382
+ ## About AirenSoft
383
+ AirenSoft aims to make it easier for you to build a stable broadcasting/streaming service with Sub-Second Latency.
384
+ Therefore, we will continue developing and providing the most optimized tools for smooth Sub-Second Latency Streaming.
385
+
386
+ Would you please click on each link below for details:
387
+ * ["JavaScript-based Live Streaming Encoder" **OvenLiveKit**](https://github.com/AirenSoft/OvenLiveKit-Web)
388
+ * ["Sub-Second Latency Streaming Server with LLHLS and WebRTC" **OvenMediaEngine**](https://github.com/AirenSoft/OvenMediaEngine)
389
+ * ["JavaScript-based Player with LLHLS and WebRTC" **OvenPlayer**](https://github.com/AirenSoft/OvenPlayer)