@streaming-cdn/rtc-web 1.3.10

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.
Files changed (2) hide show
  1. package/README.md +175 -0
  2. package/package.json +22 -0
package/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # RTC Web SDK 1.3.9
2
+
3
+ The customer package contains compiled ESM/UMD JavaScript and TypeScript declarations. It intentionally excludes implementation source and source maps. Example source remains available under `examples/`.
4
+
5
+ Install the package from the extracted archive or publish it to your private npm registry. Verify the archive against `SHA256SUMS.txt`; a Server API key must never be placed in browser code.
6
+
7
+ ## Integration modes
8
+
9
+ | Mode | Use | Required APIs |
10
+ | --- | --- | --- |
11
+ | Media only | Your app already owns dialing, push, and UI | `createRtcClient()` |
12
+ | Managed signaling, custom UI | Online presence and call events, rendered by your app | `createRtcIncomingClient()` without `mount` |
13
+ | Custom signaling or push, SDK call UI | Your delivery channel injects calls into the SDK | `autoConnect: false`, `handleIncomingCall()` |
14
+ | Managed signaling and SDK call UI | Fastest complete integration | `signalingUrl` plus `mount` |
15
+
16
+ ## Media only
17
+
18
+ Your backend creates or accepts the call and returns only the participant credential.
19
+
20
+ ```ts
21
+ import { createRtcClient } from "@streaming-cdn/rtc-web";
22
+
23
+ const media = await createRtcClient({
24
+ mode: "video",
25
+ credential: response.credential,
26
+ autoJoin: true,
27
+ quality: "auto",
28
+ preferredVideoCodec: "h264"
29
+ });
30
+
31
+ // Bind tracks from the native client to any DOM/framework renderer.
32
+ const nativeClient = media.getNativeClient();
33
+ ```
34
+
35
+ No iframe, push adapter, incoming UI, or signaling client is created.
36
+
37
+ For a receive-only device, disable local capture without disabling remote
38
+ media negotiation:
39
+
40
+ ```ts
41
+ const media = await createRtcClient({
42
+ mode: "video", credential: response.credential,
43
+ audio: false, video: false,
44
+ receiveAudio: true, receiveVideo: true
45
+ });
46
+ media.addEventListener("remotestream", ({ detail }) => {
47
+ const { participant, stream, track } = detail.detail;
48
+ attachRemoteStream(participant, stream, track);
49
+ });
50
+ await media.join();
51
+ ```
52
+
53
+ `localstream` carries `{ stream }`; `remotestream` carries
54
+ `{ participant, stream, track }`. Register both listeners before `join()`.
55
+
56
+ ## Managed signaling with custom UI
57
+
58
+ ```ts
59
+ const phone = createRtcIncomingClient({
60
+ tokenProvider: async () => {
61
+ const response = await fetch("/api/rtc/client-token", { credentials: "include" });
62
+ if (!response.ok) throw new Error("Unable to refresh RTC identity");
63
+ return response.json(); // { token, expiresAt }
64
+ },
65
+ signalingUrl,
66
+ onEvent(event) {
67
+ if (event.type === "presence") renderOnlineUsers(event.detail.users);
68
+ if (event.type === "incomingcall") showYourIncomingUi(event.detail);
69
+ if (event.type === "callupdated") updateYourCallUi(event.detail);
70
+ }
71
+ });
72
+
73
+ const accepted = await phone.accept(callId);
74
+ const media = await createRtcClient({ mode: "video", credential: accepted.credential!, autoJoin: true });
75
+ phone.attachMediaClient(callId, media);
76
+ ```
77
+
78
+ ## Custom push or signaling with SDK UI
79
+
80
+ ```ts
81
+ const phone = createRtcIncomingClient({
82
+ tokenProvider: async () => {
83
+ const response = await fetch("/api/rtc/client-token", { credentials: "include" });
84
+ if (!response.ok) throw new Error("Unable to refresh RTC identity");
85
+ return response.json();
86
+ },
87
+ apiBaseUrl: "https://streaming-cdn.ewin888.com",
88
+ autoConnect: false,
89
+ mount: document.querySelector("#incoming-call")
90
+ });
91
+
92
+ yourPush.onMessage((payload) => phone.handleIncomingCall({
93
+ id: payload.callId,
94
+ mode: payload.mode,
95
+ status: "ringing",
96
+ caller: { id: payload.callerId, name: payload.callerName }
97
+ }));
98
+ ```
99
+
100
+ Omit `mount` when your application also owns the incoming-call UI. Call `accept`, `reject`, `busy`, `end`, or `cancel` from your own controls.
101
+
102
+ For outgoing UI, show `contacting` while mobile push is being delivered, move to `ringing` on `call.delivery`, and show `connected` only after both `call.updated: accepted` and the media client's `connected` event. Do not call `join()` before acceptance. Cancel unanswered calls at the invitation `expiresAt` timestamp (45 seconds by default).
103
+
104
+ ## Complete managed integration
105
+
106
+ ```ts
107
+ const phone = createRtcIncomingClient({
108
+ tokenProvider: async () => {
109
+ const response = await fetch("/api/rtc/client-token", { credentials: "include" });
110
+ if (!response.ok) throw new Error("Unable to refresh RTC identity");
111
+ return response.json();
112
+ },
113
+ signalingUrl,
114
+ mount: "#incoming-call",
115
+ // Built-in incoming and outgoing tones are enabled by default.
116
+ // These URLs are optional and replace the built-in tones.
117
+ ringtoneUrl: "/audio/incoming.mp3",
118
+ ringbackUrl: "/audio/ringback.mp3",
119
+ terminalStateDurationMs: 1600
120
+ });
121
+
122
+ // Call this synchronously from the first click/tap in your UI so later
123
+ // signaling events can play audio under browser autoplay policies.
124
+ await unlockRtcCallAudio();
125
+ const outgoing = await phone.startCall({ mode: "voice", target: { id: "user-42", name: "Alex" } });
126
+ const media = await createRtcClient({ mode: "voice", credential: outgoing.credential!, autoJoin: true });
127
+ phone.attachMediaClient(String(outgoing.call.id), media);
128
+ ```
129
+
130
+ Set `sounds: false` to disable SDK call audio. If `ringtoneUrl` or `ringbackUrl` is omitted, the SDK synthesizes a default tone and does not require an audio asset. The built-in incoming-call UI keeps terminal states such as declined, busy, missed, failed, and ended visible for 1.6 seconds before closing; change this with `terminalStateDurationMs`.
131
+
132
+ ## Lifecycle
133
+
134
+ 1. Your backend holds the long-lived Server API key and exposes an authenticated application endpoint such as `/api/rtc/client-token`.
135
+ 2. `tokenProvider` calls that endpoint. The SDK refreshes the short-lived identity before expiry, before reconnect, and once after an HTTP `401`.
136
+ 3. The client optionally opens `/v1/rtc/signaling` for presence and call events.
137
+ 4. The caller starts a call. Only the caller receives a media credential at this point.
138
+ 5. The callee accepts. The first accepting device wins atomically and receives its credential.
139
+ 6. Both clients initialize `createRtcClient()`, join media, and render tracks.
140
+ 7. Either side ends the call and destroys media/signaling clients during teardown.
141
+
142
+ The Server API key is long-lived until revoked and must remain on the application backend. Do not place it in JavaScript, an APK, an IPA, desktop binaries, or application configuration. The `rtcc_...` identity is deliberately short-lived and is not a deployment secret that staff should replace manually.
143
+
144
+ `attachMediaClient(callId, media)` is the recommended lifecycle API. It stops
145
+ statistics, leaves media, and releases camera/microphone tracks when either
146
+ side receives a terminal call state. Manual integrations must call
147
+ `await media.leave(); media.destroy()` for `ended`, `cancelled`, `rejected`,
148
+ `busy`, `failed`, and `missed`. Calling the same terminal action twice is safe.
149
+
150
+ ## Quality and codecs
151
+
152
+ Use `setQuality("low" | "medium" | "high" | "audio" | "auto")` at runtime.
153
+ `auto` is the default for video and uses interval packet loss, RTT, and the
154
+ available outgoing bitrate plus encoder CPU/bandwidth limits to step down
155
+ quickly and recover conservatively. It starts at `medium`; severe latency or
156
+ loss falls directly to `low`, while promotion requires six healthy samples.
157
+ Use `setPreferredVideoCodec("vp8" | "h264" | "auto")`; compatible fallback
158
+ codecs remain in the offer. `packetLossPct` is the loss measured since the
159
+ previous sample. `packetLossCumulativePct` is the value since the call began.
160
+
161
+ Use `iceTransportPolicy: "relay"` to compare a poor direct carrier route with a
162
+ relay-only route. The default `all` policy allows both direct and relay
163
+ candidates. Relay-only mode requires valid relay credentials and should be
164
+ chosen from measured RTT/loss data rather than enabled blindly.
165
+
166
+ See `docs/RTC_SDK_INTEGRATION.md` in the source repository for sequence diagrams and server examples.
167
+
168
+ Managed signaling uses a 20-second heartbeat and reconnects with jittered
169
+ exponential backoff. WebSocket close code `1006` is recoverable but not a
170
+ normal healthy close. A still-ringing invitation created during an outage is
171
+ replayed after reconnection until its 45-second expiry; terminal calls are not.
172
+ Abnormal close, reconnect, and recovery duration are also sent as bounded
173
+ operational diagnostics. Tokens, SDP, media, and chat content are never part of
174
+ that report. Set `reportSignalingDiagnostics: false` only when replacing this
175
+ with an application-owned diagnostics pipeline.
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@streaming-cdn/rtc-web",
3
+ "version": "1.3.10",
4
+ "type": "module",
5
+ "main": "dist/rtc-web.umd.js",
6
+ "module": "dist/rtc-web.es.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/rtc-web.es.js",
12
+ "require": "./dist/rtc-web.umd.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE.txt",
19
+ "NOTICE.md"
20
+ ],
21
+ "license": "SEE LICENSE IN LICENSE.txt"
22
+ }