@pexip/media-control 16.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/LICENSE ADDED
@@ -0,0 +1,188 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of fifty percent
20
+ (50%) or more of the outstanding shares, or (iii) beneficial ownership of
21
+ such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source, and
28
+ configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled
32
+ object code, generated documentation, and conversions to other media types.
33
+
34
+ "Work" shall mean the work of authorship, whether in Source or Object form,
35
+ made available under the License, as indicated by a copyright notice that is
36
+ included in or attached to the work (an example is provided in the Appendix
37
+ below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object form,
40
+ that is based on (or derived from) the Work and for which the editorial
41
+ revisions, annotations, elaborations, or other modifications represent, as a
42
+ whole, an original work of authorship. For the purposes of this License,
43
+ Derivative Works shall not include works that remain separable from, or
44
+ merely link (or bind by name) to the interfaces of, the Work and Derivative
45
+ Works thereof.
46
+
47
+ "Contribution" shall mean any work of authorship, including the original
48
+ version of the Work and any modifications or additions to that Work or
49
+ Derivative Works thereof, that is intentionally submitted to Licensor for
50
+ inclusion in the Work by the copyright owner or by an individual or Legal
51
+ Entity authorized to submit on behalf of the copyright owner. For the
52
+ purposes of this definition, "submitted" means any form of electronic,
53
+ verbal, or written communication sent to the Licensor or its
54
+ representatives, including but not limited to communication on electronic
55
+ mailing lists, source code control systems, and issue tracking systems that
56
+ are managed by, or on behalf of, the Licensor for the purpose of discussing
57
+ and improving the Work, but excluding communication that is conspicuously
58
+ marked or otherwise designated in writing by the copyright owner as "Not a
59
+ Contribution."
60
+
61
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
62
+ behalf of whom a Contribution has been received by Licensor and subsequently
63
+ incorporated within the Work.
64
+
65
+ 2. Grant of Copyright License. Subject to the terms and conditions of this
66
+ License, each Contributor hereby grants to You a perpetual, worldwide,
67
+ non-exclusive, no-charge, royalty-free, irrevocable copyright license to
68
+ reproduce, prepare Derivative Works of, publicly display, publicly perform,
69
+ sublicense, and distribute the Work and such Derivative Works in Source or
70
+ Object form.
71
+
72
+ 3. Grant of Patent License. Subject to the terms and conditions of this License,
73
+ each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
74
+ no-charge, royalty-free, irrevocable (except as stated in this section)
75
+ patent license to make, have made, use, offer to sell, sell, import, and
76
+ otherwise transfer the Work, where such license applies only to those patent
77
+ claims licensable by such Contributor that are necessarily infringed by their
78
+ Contribution(s) alone or by combination of their Contribution(s) with the
79
+ Work to which such Contribution(s) was submitted. If You institute patent
80
+ litigation against any entity (including a cross-claim or counterclaim in a
81
+ lawsuit) alleging that the Work or a Contribution incorporated within the
82
+ Work constitutes direct or contributory patent infringement, then any patent
83
+ licenses granted to You under this License for that Work shall terminate as
84
+ of the date such litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the Work or
87
+ Derivative Works thereof in any medium, with or without modifications, and in
88
+ Source or Object form, provided that You meet the following conditions:
89
+
90
+ (a) You must give any other recipients of the Work or Derivative Works a
91
+ copy of this License; and
92
+
93
+ (b) You must cause any modified files to carry prominent notices stating
94
+ that You changed the files; and
95
+
96
+ (c) You must retain, in the Source form of any Derivative Works that You
97
+ distribute, all copyright, patent, trademark, and attribution notices from
98
+ the Source form of the Work, excluding those notices that do not pertain to
99
+ any part of the Derivative Works; and
100
+
101
+ (d) If the Work includes a "NOTICE" text file as part of its distribution,
102
+ then any Derivative Works that You distribute must include a readable copy
103
+ of the attribution notices contained within such NOTICE file, excluding
104
+ those notices that do not pertain to any part of the Derivative Works, in at
105
+ least one of the following places: within a NOTICE text file distributed as
106
+ part of the Derivative Works; within the Source form or documentation, if
107
+ provided along with the Derivative Works; or, within a display generated by
108
+ the Derivative Works, if and wherever such third-party notices normally
109
+ appear. The contents of the NOTICE file are for informational purposes only
110
+ and do not modify the License. You may add Your own attribution notices
111
+ within Derivative Works that You distribute, alongside or as an addendum to
112
+ the NOTICE text from the Work, provided that such additional attribution
113
+ notices cannot be construed as modifying the License.
114
+
115
+ You may add Your own copyright statement to Your modifications and may
116
+ provide additional or different license terms and conditions for use,
117
+ reproduction, or distribution of Your modifications, or for any such
118
+ Derivative Works as a whole, provided Your use, reproduction, and
119
+ distribution of the Work otherwise complies with the conditions stated in
120
+ this License.
121
+
122
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any
123
+ Contribution intentionally submitted for inclusion in the Work by You to the
124
+ Licensor shall be under the terms and conditions of this License, without any
125
+ additional terms or conditions. Notwithstanding the above, nothing herein
126
+ shall supersede or modify the terms of any separate license agreement you may
127
+ have executed with Licensor regarding such Contributions.
128
+
129
+ 6. Trademarks. This License does not grant permission to use the trade names,
130
+ trademarks, service marks, or product names of the Licensor, except as
131
+ required for reasonable and customary use in describing the origin of the
132
+ Work and reproducing the content of the NOTICE file.
133
+
134
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
135
+ writing, Licensor provides the Work (and each Contributor provides its
136
+ Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
137
+ KIND, either express or implied, including, without limitation, any
138
+ warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or
139
+ FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining
140
+ the appropriateness of using or redistributing the Work and assume any risks
141
+ associated with Your exercise of permissions under this License.
142
+
143
+ 8. Limitation of Liability. In no event and under no legal theory, whether in
144
+ tort (including negligence), contract, or otherwise, unless required by
145
+ applicable law (such as deliberate and grossly negligent acts) or agreed to
146
+ in writing, shall any Contributor be liable to You for damages, including any
147
+ direct, indirect, special, incidental, or consequential damages of any
148
+ character arising as a result of this License or out of the use or inability
149
+ to use the Work (including but not limited to damages for loss of goodwill,
150
+ work stoppage, computer failure or malfunction, or any and all other
151
+ commercial damages or losses), even if such Contributor has been advised of
152
+ the possibility of such damages.
153
+
154
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or
155
+ Derivative Works thereof, You may choose to offer, and charge a fee for,
156
+ acceptance of support, warranty, indemnity, or other liability obligations
157
+ and/or rights consistent with this License. However, in accepting such
158
+ obligations, You may act only on Your own behalf and on Your sole
159
+ responsibility, not on behalf of any other Contributor, and only if You agree
160
+ to indemnify, defend, and hold each Contributor harmless for any liability
161
+ incurred by, or claims asserted against, such Contributor by reason of your
162
+ accepting any such warranty or additional liability.
163
+
164
+ END OF TERMS AND CONDITIONS
165
+
166
+ APPENDIX: How to apply the Apache License to your work.
167
+
168
+ To apply the Apache License to your work, attach the following
169
+ boilerplate notice, with the fields enclosed by brackets "[]"
170
+ replaced with your own identifying information. (Don't include
171
+ the brackets!) The text should be enclosed in the appropriate
172
+ comment syntax for the file format. We also recommend that a
173
+ file or class name and description of purpose be included on the
174
+ same "printed page" as the copyright notice for easier
175
+ identification within third-party archives.
176
+
177
+ Copyright 2023 Pexip AS
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
180
+ this file except in compliance with the License. You may obtain a copy of the
181
+ License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software distributed
186
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
187
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
188
+ specific language governing permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,244 @@
1
+ # media-control
2
+
3
+ Abstract away all the quirks of handling media devices
4
+
5
+ A library that will handle media by wrapping
6
+ [`enumerateDevices`][enumeratedevices] and [`getUserMedia`][getusermedia]
7
+ extending both functions with additional logic.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Introduction](#introduction)
12
+ - [Installation](#installation)
13
+ - [Usage](#usage)
14
+
15
+ ## Introduction
16
+
17
+ This library is meant to extend the [`mediaDevices`][mediadevices] api methods
18
+ such as [`getUserMedia`][getusermedia], [`enumerateDevices`][enumeratedevices]
19
+ and events on media streams and tracks.
20
+
21
+ The final goal is to have a library that gives a stable and robust way to use
22
+ these methods while guaranteeing that the developer has better control over
23
+ which devices are delivered, fail, or exist.
24
+
25
+ ## Installation
26
+
27
+ The package is published to Github registry scoped with @pexip. _Access right to
28
+ @pexip is needed in order to install the package._
29
+
30
+ Here is the steps to setup Github Personal Access Token for `npm`/`yarn` in
31
+ order to add the package.
32
+
33
+ 1. A Github Personal Access Token is needed to be setup in order to get the
34
+ @pexip/media-control package. Follow [Github's doc][github package pat] to
35
+ create a Personal Access Token.
36
+
37
+ 2. When the Personal Access Token is ready, you can set it up for `npm` or
38
+ `yarn` via `.npmrc`. By adding your personal access token to your `~/.npmrc`
39
+ file, edit the `~/.npmrc` file for your project to include the following
40
+ line, replacing TOKEN with your personal access token. Create a new
41
+ `~/.npmrc` file if one doesn't exist.
42
+
43
+ ```config
44
+ //npm.pkg.github.com/:_authToken=TOKEN
45
+ ```
46
+
47
+ 3. Add a local `.npmrc` file to your repository with the following lines to tell
48
+ the package manager, `npm` or `yarn` where the registry is for `@pexip`
49
+ scoped packages.
50
+
51
+ ```config
52
+ @pexip:registry=https://npm.pkg.github.com
53
+ ```
54
+
55
+ 4. Now it is ready to add any `@pexip/PACKAGE_NAME` package to your repository.
56
+
57
+ ```sh
58
+ # Use yarn
59
+ yarn add @pexip/media-control
60
+
61
+ # Or use npm
62
+ npm install @pexip/media-control
63
+ ```
64
+
65
+ **P.S.:** _there is no polyfill added to this package, the user needs to add
66
+ polyfill to the application, i.e. `core-js`. We leverage on
67
+ `@babel/plugin-transform-runtime` and `@babel/runtime` to accomplish this._
68
+
69
+ ## Usage
70
+
71
+ ### Get user media
72
+
73
+ Get stream with audio and video without specifying devices, let the browser
74
+ choose the right devices.
75
+
76
+ ```typescript
77
+ import {getUserMedia} from '@pexip/media-control';
78
+
79
+ const stream = await getUserMedia({audio: true, video: true});
80
+ ```
81
+
82
+ Only get stream with video
83
+
84
+ ```typescript
85
+ import {getUserMedia} from '@pexip/media-control';
86
+
87
+ // neglecting audioInput is the same as setting it explicitly to false
88
+ const stream = await getUserMedia({video: true});
89
+ ```
90
+
91
+ Get stream with the specific device only but any for audio.
92
+
93
+ ```typescript
94
+ import {getUserMedia} from 'media-control';
95
+
96
+ const videoInputWanted = {
97
+ deviceId: '0abbc454-71e5-4f7e-9c8b-9de36f1334c3',
98
+ kind: 'videoinput',
99
+ label: 'Camera',
100
+ };
101
+
102
+ const stream = await getUserMedia({
103
+ audio: true,
104
+ video: {device: {exact: videoInputWanted}},
105
+ });
106
+ ```
107
+
108
+ Get stream with specific video input and fallback if it's not available and the
109
+ specific audio input only, no fallback
110
+
111
+ ```typescript
112
+ import {getUserMedia} from 'media-control';
113
+
114
+ const audioInput = {
115
+ deviceId: 'a373b235-3ebf-40c7-b619-a491e05e35e6',
116
+ label: "Rick's Microphone",
117
+ kind: 'audioinput',
118
+ };
119
+ const videoInput = {
120
+ deviceId: '0abbc454-71e5-4f7e-9c8b-9de36f1334c3',
121
+ label: "Morty's Camera",
122
+ kind: 'videoinput',
123
+ };
124
+
125
+ const stream = await getUserMedia({
126
+ audio: {device: {exact: audioInput}},
127
+ video: videoInput,
128
+ });
129
+ ```
130
+
131
+ Get stream with specific devices and fallback when they are not available
132
+
133
+ ```typescript
134
+ import {getUserMedia} from 'media-control';
135
+
136
+ const audioInput = {
137
+ deviceId: 'a373b235-3ebf-40c7-b619-a491e05e35e6',
138
+ label: "Rick's Microphone",
139
+ kind: 'audioinput',
140
+ };
141
+ const videoInput = {
142
+ deviceId: '0abbc454-71e5-4f7e-9c8b-9de36f1334c3',
143
+ label: "Morty's Camera",
144
+ kind: 'videoinput',
145
+ };
146
+
147
+ const stream = await getUserMedia({
148
+ audio: audioInput,
149
+ video: videoInput,
150
+ });
151
+ ```
152
+
153
+ The following requests both audio and video without any specific requirements:
154
+
155
+ ```typescript
156
+ import {getUserMedia} from 'media-control';
157
+
158
+ const stream = await getUserMedia({audio: true, video: true});
159
+ ```
160
+
161
+ The following expresses a preference for 1280x720 camera resolution:
162
+
163
+ ```typescript
164
+ import {getUserMedia} from 'media-control';
165
+
166
+ const stream = await getUserMedia({
167
+ audio: true,
168
+ video: {
169
+ width: 1280,
170
+ height: 720,
171
+ },
172
+ });
173
+ ```
174
+
175
+ The following expresses a preference for user facing camera:
176
+
177
+ ```typescript
178
+ import {getUserMedia} from 'media-control';
179
+
180
+ const stream = await getUserMedia({
181
+ audio: true,
182
+ video: {facingMode: 'user'},
183
+ });
184
+ ```
185
+
186
+ ### Subscribe media events
187
+
188
+ ```typescript
189
+ import {MediaEventType, subscribe} from 'media-control';
190
+
191
+ subscribe((event: MediaEvent) => {
192
+ switch (event.detail.type) {
193
+ case MediaEventType.Mute: // {id: string}
194
+ // id of the device that was muted
195
+ const id = event.detail.id;
196
+ break;
197
+ case MediaEventType.Unmute: // {id: string}
198
+ // id of the device that was unmuted
199
+ const id = event.detail.id;
200
+ break;
201
+ case MediaEventType.Ended: // {id: string}
202
+ // id of the device that ended
203
+ const id = event.detail.id;
204
+ break;
205
+ case MediaEventType.DevicesChanged: // {devices: MediaDeviceInfo[]}
206
+ // devices currently available through enumerateDevices
207
+ const devices = event.detail.devices;
208
+ break;
209
+ case MediaEventType.DevicesFound: // {devices: MediaDeviceInfo[], authorizedDevices: MediaDeviceInfo[]}
210
+ // new devices connected
211
+ const devices = event.detail.devices;
212
+ break;
213
+ case MediaEventType.DevicesLost: // {devices: MediaDeviceInfo[], authorizedDevices: MediaDeviceInfo[]}
214
+ // devices lost from the enumerateDevices list
215
+ const devices = event.detail.devices;
216
+ break;
217
+ case MediaEventType.DeviceLost: // {device: MediaDeviceInfo}
218
+ // device currently in use that was lost from the enumerateDevices list
219
+ const device = event.detail.device;
220
+ break;
221
+ case MediaEventType.DevicesUnauthorized: // {devices: MediaDeviceInfo[], authorizedDevices: MediaDeviceInfo[]}
222
+ // Unauthorized list of devices
223
+ const device = event.detail.devices;
224
+ break;
225
+ case MediaEventType.NoInputDevices:
226
+ // Indicate that there is no input devices from the machine
227
+ break;
228
+ case MediaEventType.Error: // {error: Error}
229
+ const error = event.detail.error;
230
+ break;
231
+ }
232
+ });
233
+ ```
234
+
235
+ [mediadevices]: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices
236
+ [enumeratedevices]:
237
+ https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices
238
+ [getusermedia]:
239
+ https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
240
+ [mediadeviceinfo]:
241
+ https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo
242
+ [github package pat]:
243
+ https://help.github.com/en/github/managing-packages-with-github-packages/about-github-packages#about-tokens
244
+ [parcel]: https://parceljs.org