@dtelecom/livekit-client 1.12.23 → 1.12.25
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 +61 -24
- package/dist/livekit-client.esm.mjs +14 -1
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/room/track/LocalTrack.d.ts +1 -0
- package/dist/src/room/track/LocalTrack.d.ts.map +1 -1
- package/dist/ts4.2/src/room/track/LocalTrack.d.ts +1 -0
- package/package.json +1 -1
- package/src/room/track/LocalTrack.ts +15 -0
package/README.md
CHANGED
|
@@ -1,47 +1,86 @@
|
|
|
1
|
-
# JavaScript/TypeScript client SDK
|
|
1
|
+
# dTelecom JavaScript/TypeScript client SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@dtelecom/livekit-client` connects a browser to dTelecom rooms: join, publish camera, microphone and screen, and receive other participants' tracks and data. It is dTelecom's build of the LiveKit client and works with dTelecom Cloud.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Your backend creates the participant token with the server SDK ([`@dtelecom/server-sdk-js`](https://github.com/dTelecom/server-sdk-js) or [`server-sdk-go`](https://github.com/dTelecom/server-sdk-go)); the browser only gets the token and the node URL. Never put the API key or secret in browser code.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```shell
|
|
10
|
+
npm install @dtelecom/livekit-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or
|
|
10
14
|
|
|
11
15
|
```shell
|
|
12
16
|
yarn add @dtelecom/livekit-client
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
###
|
|
19
|
+
### Without a bundler
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
The browser build registers a global named `LivekitClient` (from 1.12.25):
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<script src="https://unpkg.com/@dtelecom/livekit-client@1.12.25/dist/livekit-client.umd.js"></script>
|
|
25
|
+
<script type="module">
|
|
26
|
+
const { Room, RoomEvent } = LivekitClient;
|
|
27
|
+
const { token, wsUrl } = await (await fetch('/api/token')).json();
|
|
28
|
+
const room = new Room();
|
|
29
|
+
await room.connect(wsUrl, token);
|
|
30
|
+
</script>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Versions up to 1.12.24 register `window['@dtelecom/livekitClient']`; that name still works.
|
|
34
|
+
|
|
35
|
+
## Getting a token
|
|
36
|
+
|
|
37
|
+
On your server, with dTelecom Cloud credentials (`DTELECOM_API_KEY`, `DTELECOM_API_SECRET`, `DTELECOM_CLOUD_URL`):
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { CloudClient } from '@dtelecom/server-sdk-js';
|
|
41
|
+
|
|
42
|
+
const cloud = new CloudClient();
|
|
43
|
+
|
|
44
|
+
// e.g. GET /api/token
|
|
45
|
+
const { token, wsUrl, sessionId, expiresAt } = await cloud.createToken({
|
|
46
|
+
room: 'my-room',
|
|
47
|
+
identity: userId, // unique in the room; a second connection with it replaces the first
|
|
48
|
+
name: userName,
|
|
49
|
+
clientIp: request.ip, // picks the node nearest to the user
|
|
50
|
+
});
|
|
51
|
+
// send { token, wsUrl } to the browser
|
|
19
52
|
```
|
|
20
53
|
|
|
54
|
+
A token lasts 6 hours by default (at most 24). For longer sessions your backend extends it with `cloud.extendToken(sessionId, '1h')` before `expiresAt`; a participant whose token expired without an extension is removed from the room about a minute later.
|
|
55
|
+
|
|
21
56
|
## Usage
|
|
22
57
|
|
|
23
|
-
Examples below are in TypeScript
|
|
58
|
+
Examples below are in TypeScript. With CommonJS:
|
|
24
59
|
|
|
25
60
|
```javascript
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const room = new livekit.Room(...);
|
|
29
|
-
await room.connect(...);
|
|
61
|
+
const { Room } = require('@dtelecom/livekit-client');
|
|
30
62
|
```
|
|
31
63
|
|
|
32
64
|
### Connecting to a room, publish video & audio
|
|
33
65
|
|
|
34
66
|
```typescript
|
|
35
67
|
import {
|
|
68
|
+
DisconnectReason,
|
|
69
|
+
LocalParticipant,
|
|
70
|
+
LocalTrackPublication,
|
|
36
71
|
Participant,
|
|
37
72
|
RemoteParticipant,
|
|
38
73
|
RemoteTrack,
|
|
39
74
|
RemoteTrackPublication,
|
|
40
75
|
Room,
|
|
41
76
|
RoomEvent,
|
|
77
|
+
Track,
|
|
78
|
+
VideoPresets,
|
|
42
79
|
} from '@dtelecom/livekit-client';
|
|
43
80
|
|
|
44
|
-
//
|
|
81
|
+
// token and wsUrl come from your backend (see "Getting a token")
|
|
82
|
+
const { token, wsUrl } = await (await fetch('/api/token')).json();
|
|
83
|
+
|
|
45
84
|
const room = new Room({
|
|
46
85
|
// automatically manage subscribed video quality
|
|
47
86
|
adaptiveStream: true,
|
|
@@ -63,8 +102,8 @@ room
|
|
|
63
102
|
.on(RoomEvent.Disconnected, handleDisconnect)
|
|
64
103
|
.on(RoomEvent.LocalTrackUnpublished, handleLocalTrackUnpublished);
|
|
65
104
|
|
|
66
|
-
// connect to
|
|
67
|
-
await room.connect(
|
|
105
|
+
// connect to the node your backend got with the token
|
|
106
|
+
await room.connect(wsUrl, token);
|
|
68
107
|
console.log('connected to room', room.name);
|
|
69
108
|
|
|
70
109
|
// publish local camera and mic tracks
|
|
@@ -91,27 +130,25 @@ function handleTrackUnsubscribed(
|
|
|
91
130
|
track.detach();
|
|
92
131
|
}
|
|
93
132
|
|
|
94
|
-
function handleLocalTrackUnpublished(
|
|
133
|
+
function handleLocalTrackUnpublished(publication: LocalTrackPublication, participant: LocalParticipant) {
|
|
95
134
|
// when local tracks are ended, update UI to remove them from rendering
|
|
96
|
-
track
|
|
135
|
+
publication.track?.detach();
|
|
97
136
|
}
|
|
98
137
|
|
|
99
138
|
function handleActiveSpeakerChange(speakers: Participant[]) {
|
|
100
139
|
// show UI indicators when participant is speaking
|
|
101
140
|
}
|
|
102
141
|
|
|
103
|
-
function handleDisconnect() {
|
|
104
|
-
|
|
142
|
+
function handleDisconnect(reason?: DisconnectReason) {
|
|
143
|
+
// CLIENT_INITIATED: room.disconnect(); PARTICIPANT_REMOVED: removed by your backend or after
|
|
144
|
+
// the token expired; DUPLICATE_IDENTITY: the same identity joined elsewhere; ROOM_DELETED
|
|
145
|
+
console.log('disconnected from room', reason);
|
|
105
146
|
}
|
|
106
147
|
```
|
|
107
148
|
|
|
108
|
-
In order to connect to a room, you need to first create an access token.
|
|
109
|
-
|
|
110
|
-
See [access token docs](https://docs.dtelecom.org/guides/access-tokens) for details
|
|
111
|
-
|
|
112
149
|
### Handling common track types
|
|
113
150
|
|
|
114
|
-
|
|
151
|
+
There are shortcuts that make working with common track types simple. For a user's camera, microphone, and screen share, you can enable them with the following `LocalParticipant` methods:
|
|
115
152
|
|
|
116
153
|
```typescript
|
|
117
154
|
const p = room.localParticipant;
|
|
@@ -14202,7 +14202,7 @@ function getMatch(exp, ua) {
|
|
|
14202
14202
|
return match && match.length >= id && match[id] || '';
|
|
14203
14203
|
}
|
|
14204
14204
|
|
|
14205
|
-
var version$1 = "1.12.
|
|
14205
|
+
var version$1 = "1.12.25";
|
|
14206
14206
|
|
|
14207
14207
|
const version = version$1;
|
|
14208
14208
|
const protocolVersion = 9;
|
|
@@ -16589,6 +16589,7 @@ class LocalTrack extends Track {
|
|
|
16589
16589
|
this.muteLock = new Mutex();
|
|
16590
16590
|
this.pauseUpstreamLock = new Mutex();
|
|
16591
16591
|
this.processorLock = new Mutex();
|
|
16592
|
+
this.manuallyStopped = false;
|
|
16592
16593
|
this.setMediaStreamTrack(mediaTrack, true);
|
|
16593
16594
|
// added to satisfy TS compiler, constraints are synced with MediaStreamTrack
|
|
16594
16595
|
this._constraints = mediaTrack.getConstraints();
|
|
@@ -16711,6 +16712,9 @@ class LocalTrack extends Track {
|
|
|
16711
16712
|
}
|
|
16712
16713
|
unmute() {
|
|
16713
16714
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16715
|
+
if (this.manuallyStopped) {
|
|
16716
|
+
return this;
|
|
16717
|
+
}
|
|
16714
16718
|
this.setTrackMuted(false);
|
|
16715
16719
|
return this;
|
|
16716
16720
|
});
|
|
@@ -16734,6 +16738,7 @@ class LocalTrack extends Track {
|
|
|
16734
16738
|
}
|
|
16735
16739
|
restart(constraints) {
|
|
16736
16740
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16741
|
+
this.manuallyStopped = false;
|
|
16737
16742
|
if (!constraints) {
|
|
16738
16743
|
constraints = this._constraints;
|
|
16739
16744
|
}
|
|
@@ -16760,6 +16765,10 @@ class LocalTrack extends Track {
|
|
|
16760
16765
|
// create new track and attach
|
|
16761
16766
|
const mediaStream = yield navigator.mediaDevices.getUserMedia(streamConstraints);
|
|
16762
16767
|
const newTrack = mediaStream.getTracks()[0];
|
|
16768
|
+
if (this.manuallyStopped) {
|
|
16769
|
+
newTrack.stop();
|
|
16770
|
+
return this;
|
|
16771
|
+
}
|
|
16763
16772
|
newTrack.addEventListener('ended', this.handleEnded);
|
|
16764
16773
|
livekitLogger.debug('re-acquired MediaStreamTrack');
|
|
16765
16774
|
yield this.setMediaStreamTrack(newTrack);
|
|
@@ -16773,6 +16782,9 @@ class LocalTrack extends Track {
|
|
|
16773
16782
|
});
|
|
16774
16783
|
}
|
|
16775
16784
|
this.emit(TrackEvent.Restarted, this);
|
|
16785
|
+
if (this.manuallyStopped) {
|
|
16786
|
+
this.stop();
|
|
16787
|
+
}
|
|
16776
16788
|
return this;
|
|
16777
16789
|
});
|
|
16778
16790
|
}
|
|
@@ -16807,6 +16819,7 @@ class LocalTrack extends Track {
|
|
|
16807
16819
|
}
|
|
16808
16820
|
stop() {
|
|
16809
16821
|
var _a;
|
|
16822
|
+
this.manuallyStopped = true;
|
|
16810
16823
|
super.stop();
|
|
16811
16824
|
this._mediaStreamTrack.removeEventListener('ended', this.handleEnded);
|
|
16812
16825
|
this._mediaStreamTrack.removeEventListener('mute', this.pauseUpstream);
|