@qencode/calls 0.2.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/LICENSE +202 -0
- package/README.md +242 -0
- package/dist/call.d.ts +255 -0
- package/dist/credential.d.ts +42 -0
- package/dist/devices.d.ts +40 -0
- package/dist/errors.d.ts +29 -0
- package/dist/events.d.ts +11 -0
- package/dist/index.d.ts +16 -0
- package/dist/latency.d.ts +25 -0
- package/dist/profiles.d.ts +18 -0
- package/dist/qencode-calls.esm.bundle.js +47 -0
- package/dist/qencode-calls.esm.bundle.js.map +7 -0
- package/dist/qencode-calls.esm.js +9 -0
- package/dist/qencode-calls.esm.js.map +7 -0
- package/dist/qencode-calls.umd.js +47 -0
- package/dist/qencode-calls.umd.js.map +7 -0
- package/dist/regions.d.ts +22 -0
- package/dist/render.d.ts +35 -0
- package/dist/stats.d.ts +143 -0
- package/dist/telemetry.d.ts +73 -0
- package/dist/version.d.ts +2 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# @qencode/calls
|
|
2
|
+
|
|
3
|
+
Low-latency 1:1 audio and video calls inside your own UI. The SDK takes a short-lived
|
|
4
|
+
participant credential minted by **your backend**, connects, renders media into views you
|
|
5
|
+
place, and reports call quality. It ships no screens and no theme. Version 0.2.0, pre-release.
|
|
6
|
+
|
|
7
|
+
## Quickstart
|
|
8
|
+
|
|
9
|
+
### 1. Your backend mints a credential
|
|
10
|
+
|
|
11
|
+
Never put a Qencode API key in a browser. Your server calls the Qencode calls API and hands
|
|
12
|
+
the token response to the page unchanged:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
POST /v1/access_token/{api_key} -> { access_token } (project JWT, 24 h)
|
|
16
|
+
POST /v1/calls -> { call: { id, ... } } Authorization: Bearer <access_token>
|
|
17
|
+
POST /v1/calls/{id}/tokens -> { token, url, regions, identity, room_name, expires_at }
|
|
18
|
+
body { "identity": "alice", "name": "Alice", "role": "A", "ttl": 600 }
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Return that last object to the browser (optionally add `call_id` and `api_base`). See
|
|
22
|
+
`examples/backend-node/server.js` for a complete 60-line version.
|
|
23
|
+
|
|
24
|
+
### 2. The page joins
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<script type="module">
|
|
28
|
+
import { Call } from 'https://unpkg.com/@qencode/calls/dist/qencode-calls.esm.bundle.js';
|
|
29
|
+
|
|
30
|
+
const cred = await fetch('/api/calls/join?as=alice').then(r => r.json());
|
|
31
|
+
const call = Call.create(cred, { videoProfile: 'p540_60' });
|
|
32
|
+
|
|
33
|
+
call.on('remoteVideo', track => { document.querySelector('#remote').track = track; });
|
|
34
|
+
call.on('stateChanged', (state, reason) => console.log(state, reason ?? ''));
|
|
35
|
+
call.on('credentialExpiring', async () => {
|
|
36
|
+
call.updateCredential(await fetch('/api/calls/refresh').then(r => r.json()));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
await call.connect();
|
|
40
|
+
document.querySelector('#self').track = call.localVideo;
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<qencode-video id="remote"></qencode-video>
|
|
44
|
+
<qencode-video id="self" mirror></qencode-video>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`npm install @qencode/calls` gives the same API as an ES module with TypeScript types.
|
|
48
|
+
|
|
49
|
+
## Builds and size
|
|
50
|
+
|
|
51
|
+
| File | Use | Size, gzipped |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `dist/qencode-calls.esm.js` | `import` through a bundler; the engine (`livekit-client`) is a dependency your bundler resolves and dedupes | ~11 KB |
|
|
54
|
+
| `dist/qencode-calls.esm.bundle.js` | `<script type="module">` with no bundler; engine included | ~154 KB |
|
|
55
|
+
| `dist/qencode-calls.umd.js` | classic `<script>`; exposes `window.QencodeCalls`; engine included | ~154 KB |
|
|
56
|
+
|
|
57
|
+
The SDK itself is about 11 KB gzipped. The self-contained builds are dominated by the engine,
|
|
58
|
+
which is about 145 KB gzipped on its own.
|
|
59
|
+
|
|
60
|
+
## Call
|
|
61
|
+
|
|
62
|
+
| Member | Meaning |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `Call.create(credential, options)` | Builds a call. No network yet. |
|
|
65
|
+
| `connect()` | Probes regions when the credential lists several, connects, publishes camera and microphone per options. Rejects with a `CallError`. |
|
|
66
|
+
| `leave()` | Unpublishes, disconnects, releases devices. Idempotent. |
|
|
67
|
+
| `state` | `idle`, `connecting`, `connected`, `reconnecting`, `ended`; `endReason` says why it ended. |
|
|
68
|
+
| `localVideo`, `remoteVideo`, `remoteAudio` | Track handles with `attach(element)` and `detach()`. Remote audio is played by the SDK; the handle is for metering or custom output. |
|
|
69
|
+
| `setMicrophoneEnabled(bool)`, `setCameraEnabled(bool)` | Mute keeps the track published, so unmute is instant. |
|
|
70
|
+
| `setVideoProfile(name)` | Switches tier mid-call. Simulcast changes republish; other changes restart capture in place. |
|
|
71
|
+
| `setLatencyMode('lowest' \| 'smooth')` | Jitter buffer target, degradation preference and audio framing in one switch. Clears a `setJitterBufferTarget` pin. |
|
|
72
|
+
| `setJitterBufferTarget(ms)` | Pins the receiver's jitter buffer target regardless of the mode. Returns which property took it: `jitterBufferTarget`, `playoutDelayHint`, or `unsupported` (Firefox). |
|
|
73
|
+
| `setVideoEncoding({ codec, simulcast })` | Switches codec or simulcast mid-call; the video track is republished. |
|
|
74
|
+
| `setVideoSource(source \| null)` | Replaces the published video with a custom track or factory, or returns to the camera. See below. |
|
|
75
|
+
| `devices` | `list()`, `setCamera(id)`, `setMicrophone(id)`, `setSpeaker(id)`, `onChange(handler)`, `canSelectSpeaker`. |
|
|
76
|
+
| `sendMessage(payload, reliable = true)` | Up to 15 KB, 30 per second, to the peer. Strings and JSON objects arrive as sent, `Uint8Array` as bytes. |
|
|
77
|
+
| `stats` | Latest quality snapshot, refreshed every second. |
|
|
78
|
+
| `peer` | Identity, display name and mute state of the other human, or `null`. |
|
|
79
|
+
| `videoCodec`, `simulcast`, `jitterBufferTargetMs`, `jitterBufferSupport`, `regionProbe` | What is in force: codec, simulcast, jitter target in ms, which receiver property took it, and the probe results by region name (`null` when no probe ran). |
|
|
80
|
+
| `updateCredential(credential)` | Fresh token for the same call and identity, used by the next reconnect. |
|
|
81
|
+
| `on(event, handler)` returns an unsubscribe function; `off`, `once`. |
|
|
82
|
+
|
|
83
|
+
### Options
|
|
84
|
+
|
|
85
|
+
`adaptiveStream` (default `true`) lets the engine match what is sent and received to how the
|
|
86
|
+
video is displayed: a phone rendering a desktop's 720p pulls the 540p layer, and a hidden or
|
|
87
|
+
background video element pauses that track on the server until it is visible again. Two tabs
|
|
88
|
+
on one machine therefore show a black remote picture in whichever tab is in the background.
|
|
89
|
+
Set it to `false` to always send and receive the full profile, which is what a measurement
|
|
90
|
+
bench wants and what a customer UI rarely does.
|
|
91
|
+
|
|
92
|
+
| Option | Default | Notes |
|
|
93
|
+
|---|---|---|
|
|
94
|
+
| `audio`, `video` | `true` | Publish on connect. |
|
|
95
|
+
| `videoProfile` | `p540_60` | See profiles. |
|
|
96
|
+
| `latencyMode` | `lowest` | See latency modes. |
|
|
97
|
+
| `region` | auto | Pin a region name from the credential. |
|
|
98
|
+
| `telemetry` | `true` | Post quality stats to Qencode every 5 s. |
|
|
99
|
+
| `autoReconnect` | `true` | Resume for up to 60 s after a network change, then end with reason `network`. |
|
|
100
|
+
| `endOnPeerLeft` | `true` | 1:1 semantics: the call ends when the peer leaves. |
|
|
101
|
+
| `cameraId`, `microphoneId` | system default | Initial devices. |
|
|
102
|
+
| `apiBase` | `https://api.qencode.com` | Telemetry target; `credential.api_base` also works. |
|
|
103
|
+
| `logLevel` | `warn` | Never logs media or credentials. |
|
|
104
|
+
| `videoSource` | camera | A `MediaStreamTrack` or a factory `(profile) => MediaStreamTrack`; see custom video source. |
|
|
105
|
+
| `codec` | `h264` | `h264`, `vp8`, `vp9`, `av1`. The engine falls back to VP8 when a peer cannot decode the choice. |
|
|
106
|
+
| `simulcast` | per profile | Force simulcast layers on or off. |
|
|
107
|
+
| `jitterBufferTargetMs` | per latency mode | Pin the receiver's jitter buffer target; `0` asks for the browser's floor. |
|
|
108
|
+
| `telemetryExtra` | none | `(direction) => fields` appended to every telemetry row; see telemetry. |
|
|
109
|
+
| `forceRelay` | `false` | Connect through TURN only, to measure the relay path. |
|
|
110
|
+
|
|
111
|
+
### Custom video source
|
|
112
|
+
|
|
113
|
+
Pass `videoSource` to publish something other than the raw camera: a canvas with an overlay or a
|
|
114
|
+
timestamp, a processed camera track (virtual background, filters), or a screen.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const call = Call.create(cred, {
|
|
118
|
+
videoSource: (profile) => { // called on every publish and republish
|
|
119
|
+
canvas.width = profile.width; canvas.height = profile.height;
|
|
120
|
+
return canvas.captureStream(profile.fps).getVideoTracks()[0];
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
A factory is called with the profile so it can size its output, and is called again on
|
|
126
|
+
`setVideoProfile`, `setVideoEncoding` and `setVideoSource`; the SDK stops the track it returned
|
|
127
|
+
when it is replaced or the call ends. A `MediaStreamTrack` passed directly is published as is,
|
|
128
|
+
gets new encoding parameters on a profile switch, and is never stopped by the SDK. Encoding
|
|
129
|
+
caps, codec, simulcast and mute work the same either way. `devices.setCamera` is refused while a
|
|
130
|
+
custom source is published: switch cameras in the code that produces the track.
|
|
131
|
+
|
|
132
|
+
### Events
|
|
133
|
+
|
|
134
|
+
| Event | Payload |
|
|
135
|
+
|---|---|
|
|
136
|
+
| `stateChanged` | `(state, endReason \| null)` |
|
|
137
|
+
| `peerJoined`, `peerLeft` | `(peer)` |
|
|
138
|
+
| `remoteVideo`, `remoteAudio` | `(track \| null)`; fires again after a reconnect with the replacement track |
|
|
139
|
+
| `peerMuted` | `('audio' \| 'video', muted)` |
|
|
140
|
+
| `stats` | `(snapshot)` once per second |
|
|
141
|
+
| `qualityChanged` | `('good' \| 'fair' \| 'poor', 'recv' \| 'send')`, with hysteresis |
|
|
142
|
+
| `message` | `(payload, reliable)` |
|
|
143
|
+
| `credentialExpiring` | `(expiresAt)` two minutes before expiry, and on reconnect if already expired |
|
|
144
|
+
| `devicesChanged` | `(list)` |
|
|
145
|
+
| `moderation` | reserved; no-op until the moderation agent ships |
|
|
146
|
+
| `error` | `(CallError)` non-fatal errors; fatal ones end the call |
|
|
147
|
+
|
|
148
|
+
### Errors
|
|
149
|
+
|
|
150
|
+
`CallError` has `code`, `message`, `retryable` and `cause`. Codes: `credentialInvalid`,
|
|
151
|
+
`credentialExpired`, `roomFull`, `roomClosed`, `permissionDenied`, `deviceUnavailable`,
|
|
152
|
+
`network`, `unsupported`, `internal`.
|
|
153
|
+
|
|
154
|
+
A media server refuses a third participant by closing the websocket without a reason a
|
|
155
|
+
browser can read. `connect()` then asks the server's validate endpoint whether the credential
|
|
156
|
+
is still accepted; if it is, the rejection was capacity and the error is `roomFull`, otherwise
|
|
157
|
+
it stays `network`. That is one extra request, on that failure path only.
|
|
158
|
+
|
|
159
|
+
## Profiles
|
|
160
|
+
|
|
161
|
+
| Profile | Resolution | fps | Cap |
|
|
162
|
+
|---|---|---|---|
|
|
163
|
+
| `audioOnly` | none | | 48 kbps |
|
|
164
|
+
| `p360_30` | 640×360 | 30 | 450 kbps |
|
|
165
|
+
| `p540_30` | 960×540 | 30 | 800 kbps |
|
|
166
|
+
| `p540_60` (default) | 960×540 | 60 | 1.2 Mbps |
|
|
167
|
+
| `p720_30` | 1280×720 | 30 | 1.2 Mbps |
|
|
168
|
+
| `p720_60` | 1280×720 | 60 | 1.8 Mbps |
|
|
169
|
+
| `p1080_30` | 1920×1080 | 30 | 2.2 Mbps |
|
|
170
|
+
|
|
171
|
+
Hardware H.264 everywhere it exists, VP8 as the fallback. Simulcast is on at 720p and above.
|
|
172
|
+
The captured frame is cover-fitted to the profile's aspect ratio, never stretched.
|
|
173
|
+
|
|
174
|
+
## Latency modes
|
|
175
|
+
|
|
176
|
+
`lowest` (default) asks the browser for its minimum jitter buffer, drops resolution before
|
|
177
|
+
frame rate under pressure, and uses 10 ms audio frames where the platform allows. `smooth`
|
|
178
|
+
lets the buffer grow to 150 ms and drops frame rate before resolution. Switch mid-call.
|
|
179
|
+
|
|
180
|
+
## Stats
|
|
181
|
+
|
|
182
|
+
Every second, `call.stats` and the `stats` event carry:
|
|
183
|
+
|
|
184
|
+
| Field | Source |
|
|
185
|
+
|---|---|
|
|
186
|
+
| `recv.rttMs`, `send.rttMs` | selected ICE candidate pair, round trip to the media node |
|
|
187
|
+
| `recv.jitterBufferMs` | Δ`jitterBufferDelay` / Δ`jitterBufferEmittedCount` |
|
|
188
|
+
| `recv.decodeMs`, `send.encodeMs` | Δ`totalDecodeTime` / Δ`framesDecoded`, Δ`totalEncodeTime` / Δ`framesEncoded` |
|
|
189
|
+
| `recv.fps`, `width`, `height`, `kbps`, `codec` | inbound-rtp; `send.*` from outbound-rtp |
|
|
190
|
+
| `recv.lossPct`, `jitterMs`, `freezes`, `freezeMs` | inbound-rtp deltas |
|
|
191
|
+
| `recv.processingMs` | Δ`totalProcessingDelay` / Δ`framesDecoded`, receive to render |
|
|
192
|
+
| `recv.absCaptureLatencyMs` | sender capture to now through the abs-capture-time extension; Chromium, and only when the media node forwards it. A cross-check for the estimate. |
|
|
193
|
+
| `send.lossPct` | remote-inbound-rtp `fractionLost` |
|
|
194
|
+
| `send.targetKbps` | the encoder's current bitrate target |
|
|
195
|
+
| `recv.transport`, `candidateType` | `udp`, `tcp`, `relay-udp`, `relay-tcp`; `host`, `srflx`, `prflx`, `relay` |
|
|
196
|
+
| `peerRttMs` | the peer's own RTT, exchanged over the data channel |
|
|
197
|
+
| `estimatedLatencyMs` | `rtt/2 + peerRtt/2 + jitterBuffer + decode + one frame interval`. An estimate; it excludes capture and display. |
|
|
198
|
+
| `quality.recv`, `quality.send` | `good`, `fair`, `poor` |
|
|
199
|
+
| `region`, `nodeId`, `serverVersion`, `joinMs` | where the call landed and how long connect took |
|
|
200
|
+
|
|
201
|
+
## Telemetry and privacy
|
|
202
|
+
|
|
203
|
+
With `telemetry: true` and a credential that carries `call_id`, the SDK posts the last
|
|
204
|
+
snapshots every 5 s to `POST {apiBase}/v1/calls/{call_id}/stats` using the participant token.
|
|
205
|
+
The rows are the fields above plus SDK version, platform and user agent. Nothing identifying the
|
|
206
|
+
user is sent, media never is, and a failed post is dropped silently. Manual credentials without a
|
|
207
|
+
`call_id` post nothing.
|
|
208
|
+
|
|
209
|
+
`telemetryExtra` adds your own fields to every row. It is called once per row with `'recv'` or
|
|
210
|
+
`'send'`. Three keys are stored as columns because the API knows them: `g2g_p50`, `g2g_p95` and
|
|
211
|
+
`g2g_samples`, an app's own measured glass-to-glass latency in ms over its window, as the Qencode
|
|
212
|
+
bench posts. Every other key lands in the row's `extra` object next to the SDK's keys, which win
|
|
213
|
+
on a name clash.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
Call.create(cred, { telemetryExtra: (direction) => ({ session: mySessionId, screen: direction === 'recv' ? 'room' : undefined }) });
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Browser support
|
|
220
|
+
|
|
221
|
+
Chromium 110+, Safari 16.4+, Firefox 115+. A secure context is required. Device labels are
|
|
222
|
+
empty until the first permission grant. Firefox has no `jitterBufferTarget`, so `lowest` mode
|
|
223
|
+
runs with the browser's default buffer there and `stats` still reports the size. Speaker
|
|
224
|
+
selection needs `setSinkId`, which Safari lacks; `devices.canSelectSpeaker` says so.
|
|
225
|
+
|
|
226
|
+
## Running the example
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
cd examples/backend-node && npm install
|
|
230
|
+
QENCODE_API_KEY=<your project API key> npm start # API_BASE defaults to https://api.qencode.com
|
|
231
|
+
# open http://localhost:8787/ in two tabs or on two devices, join as alice and bob
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
The backend creates one call, mints a credential per identity, and serves `examples/vanilla`.
|
|
235
|
+
|
|
236
|
+
## Development
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
npm install
|
|
240
|
+
npm test # vitest, jsdom, engine mocked
|
|
241
|
+
npm run build # typecheck, ESM + UMD bundles, declarations in dist/
|
|
242
|
+
```
|