livekit-server-sdk 2.8.1 → 2.9.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 +1 -1
- package/dist/AccessToken.cjs +169 -0
- package/dist/AccessToken.cjs.map +1 -0
- package/dist/AccessToken.js +130 -137
- package/dist/AccessToken.js.map +1 -1
- package/dist/AccessToken.test.cjs +147 -0
- package/dist/AccessToken.test.cjs.map +1 -0
- package/dist/AccessToken.test.js +129 -0
- package/dist/AccessToken.test.js.map +1 -0
- package/dist/AgentDispatchClient.cjs +133 -0
- package/dist/AgentDispatchClient.cjs.map +1 -0
- package/dist/AgentDispatchClient.js +102 -79
- package/dist/AgentDispatchClient.js.map +1 -1
- package/dist/EgressClient.cjs +381 -0
- package/dist/EgressClient.cjs.map +1 -0
- package/dist/EgressClient.js +349 -288
- package/dist/EgressClient.js.map +1 -1
- package/dist/IngressClient.cjs +164 -0
- package/dist/IngressClient.cjs.map +1 -0
- package/dist/IngressClient.js +131 -106
- package/dist/IngressClient.js.map +1 -1
- package/dist/RoomServiceClient.cjs +240 -0
- package/dist/RoomServiceClient.cjs.map +1 -0
- package/dist/RoomServiceClient.js +219 -151
- package/dist/RoomServiceClient.js.map +1 -1
- package/dist/ServiceBase.cjs +49 -0
- package/dist/ServiceBase.cjs.map +1 -0
- package/dist/ServiceBase.js +25 -28
- package/dist/ServiceBase.js.map +1 -1
- package/dist/SipClient.cjs +379 -0
- package/dist/SipClient.cjs.map +1 -0
- package/dist/SipClient.d.ts +15 -0
- package/dist/SipClient.d.ts.map +1 -1
- package/dist/SipClient.js +360 -260
- package/dist/SipClient.js.map +1 -1
- package/dist/TwirpRPC.cjs +71 -0
- package/dist/TwirpRPC.cjs.map +1 -0
- package/dist/TwirpRPC.d.ts.map +1 -1
- package/dist/TwirpRPC.js +32 -29
- package/dist/TwirpRPC.js.map +1 -1
- package/dist/WebhookReceiver.cjs +78 -0
- package/dist/WebhookReceiver.cjs.map +1 -0
- package/dist/WebhookReceiver.js +48 -45
- package/dist/WebhookReceiver.js.map +1 -1
- package/dist/WebhookReceiver.test.cjs +38 -0
- package/dist/WebhookReceiver.test.cjs.map +1 -0
- package/dist/WebhookReceiver.test.js +37 -0
- package/dist/WebhookReceiver.test.js.map +1 -0
- package/dist/grants.cjs +53 -0
- package/dist/grants.cjs.map +1 -0
- package/dist/grants.js +25 -23
- package/dist/grants.js.map +1 -1
- package/dist/grants.test.cjs +27 -0
- package/dist/grants.test.cjs.map +1 -0
- package/dist/grants.test.js +26 -0
- package/dist/grants.test.js.map +1 -0
- package/dist/index.cjs +136 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +104 -12
- package/dist/index.js.map +1 -1
- package/package.json +12 -3
- package/src/SipClient.ts +33 -0
- package/src/TwirpRPC.ts +1 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var RoomServiceClient_exports = {};
|
|
30
|
+
__export(RoomServiceClient_exports, {
|
|
31
|
+
RoomServiceClient: () => RoomServiceClient
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(RoomServiceClient_exports);
|
|
34
|
+
var import_protocol = require("@livekit/protocol");
|
|
35
|
+
var import_ServiceBase = __toESM(require("./ServiceBase.cjs"), 1);
|
|
36
|
+
var import_TwirpRPC = require("./TwirpRPC.cjs");
|
|
37
|
+
const svc = "RoomService";
|
|
38
|
+
class RoomServiceClient extends import_ServiceBase.default {
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
|
|
42
|
+
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
|
|
43
|
+
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
44
|
+
*/
|
|
45
|
+
constructor(host, apiKey, secret) {
|
|
46
|
+
super(apiKey, secret);
|
|
47
|
+
this.rpc = new import_TwirpRPC.TwirpRpc(host, import_TwirpRPC.livekitPackage);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new room. Explicit room creation is not required, since rooms will
|
|
51
|
+
* be automatically created when the first participant joins. This method can be
|
|
52
|
+
* used to customize room settings.
|
|
53
|
+
* @param options -
|
|
54
|
+
*/
|
|
55
|
+
async createRoom(options) {
|
|
56
|
+
const data = await this.rpc.request(
|
|
57
|
+
svc,
|
|
58
|
+
"CreateRoom",
|
|
59
|
+
new import_protocol.CreateRoomRequest(options).toJson(),
|
|
60
|
+
await this.authHeader({ roomCreate: true })
|
|
61
|
+
);
|
|
62
|
+
return import_protocol.Room.fromJson(data, { ignoreUnknownFields: true });
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* List active rooms
|
|
66
|
+
* @param names - when undefined or empty, list all rooms.
|
|
67
|
+
* otherwise returns rooms with matching names
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
async listRooms(names) {
|
|
71
|
+
const data = await this.rpc.request(
|
|
72
|
+
svc,
|
|
73
|
+
"ListRooms",
|
|
74
|
+
new import_protocol.ListRoomsRequest({ names: names ?? [] }).toJson(),
|
|
75
|
+
await this.authHeader({ roomList: true })
|
|
76
|
+
);
|
|
77
|
+
const res = import_protocol.ListRoomsResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
78
|
+
return res.rooms ?? [];
|
|
79
|
+
}
|
|
80
|
+
async deleteRoom(room) {
|
|
81
|
+
await this.rpc.request(
|
|
82
|
+
svc,
|
|
83
|
+
"DeleteRoom",
|
|
84
|
+
new import_protocol.DeleteRoomRequest({ room }).toJson(),
|
|
85
|
+
await this.authHeader({ roomCreate: true })
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Update metadata of a room
|
|
90
|
+
* @param room - name of the room
|
|
91
|
+
* @param metadata - the new metadata for the room
|
|
92
|
+
*/
|
|
93
|
+
async updateRoomMetadata(room, metadata) {
|
|
94
|
+
const data = await this.rpc.request(
|
|
95
|
+
svc,
|
|
96
|
+
"UpdateRoomMetadata",
|
|
97
|
+
new import_protocol.UpdateRoomMetadataRequest({ room, metadata }).toJson(),
|
|
98
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
99
|
+
);
|
|
100
|
+
return import_protocol.Room.fromJson(data, { ignoreUnknownFields: true });
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* List participants in a room
|
|
104
|
+
* @param room - name of the room
|
|
105
|
+
*/
|
|
106
|
+
async listParticipants(room) {
|
|
107
|
+
const data = await this.rpc.request(
|
|
108
|
+
svc,
|
|
109
|
+
"ListParticipants",
|
|
110
|
+
new import_protocol.ListParticipantsRequest({ room }).toJson(),
|
|
111
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
112
|
+
);
|
|
113
|
+
const res = import_protocol.ListParticipantsResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
114
|
+
return res.participants ?? [];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get information on a specific participant, including the tracks that participant
|
|
118
|
+
* has published
|
|
119
|
+
* @param room - name of the room
|
|
120
|
+
* @param identity - identity of the participant to return
|
|
121
|
+
*/
|
|
122
|
+
async getParticipant(room, identity) {
|
|
123
|
+
const data = await this.rpc.request(
|
|
124
|
+
svc,
|
|
125
|
+
"GetParticipant",
|
|
126
|
+
new import_protocol.RoomParticipantIdentity({ room, identity }).toJson(),
|
|
127
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
128
|
+
);
|
|
129
|
+
return import_protocol.ParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Removes a participant in the room. This will disconnect the participant
|
|
133
|
+
* and will emit a Disconnected event for that participant.
|
|
134
|
+
* Even after being removed, the participant can still re-join the room.
|
|
135
|
+
* @param room -
|
|
136
|
+
* @param identity -
|
|
137
|
+
*/
|
|
138
|
+
async removeParticipant(room, identity) {
|
|
139
|
+
await this.rpc.request(
|
|
140
|
+
svc,
|
|
141
|
+
"RemoveParticipant",
|
|
142
|
+
new import_protocol.RoomParticipantIdentity({ room, identity }).toJson(),
|
|
143
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Mutes a track that the participant has published.
|
|
148
|
+
* @param room -
|
|
149
|
+
* @param identity -
|
|
150
|
+
* @param trackSid - sid of the track to be muted
|
|
151
|
+
* @param muted - true to mute, false to unmute
|
|
152
|
+
*/
|
|
153
|
+
async mutePublishedTrack(room, identity, trackSid, muted) {
|
|
154
|
+
const req = new import_protocol.MuteRoomTrackRequest({
|
|
155
|
+
room,
|
|
156
|
+
identity,
|
|
157
|
+
trackSid,
|
|
158
|
+
muted
|
|
159
|
+
}).toJson();
|
|
160
|
+
const data = await this.rpc.request(
|
|
161
|
+
svc,
|
|
162
|
+
"MutePublishedTrack",
|
|
163
|
+
req,
|
|
164
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
165
|
+
);
|
|
166
|
+
const res = import_protocol.MuteRoomTrackResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
167
|
+
return res.track;
|
|
168
|
+
}
|
|
169
|
+
async updateParticipant(room, identity, metadataOrOptions, maybePermission, maybeName) {
|
|
170
|
+
const hasOptions = typeof metadataOrOptions === "object";
|
|
171
|
+
const metadata = hasOptions ? metadataOrOptions == null ? void 0 : metadataOrOptions.metadata : metadataOrOptions;
|
|
172
|
+
const permission = hasOptions ? metadataOrOptions.permission : maybePermission;
|
|
173
|
+
const name = hasOptions ? metadataOrOptions.name : maybeName;
|
|
174
|
+
const attributes = hasOptions ? metadataOrOptions.attributes : {};
|
|
175
|
+
const req = new import_protocol.UpdateParticipantRequest({
|
|
176
|
+
room,
|
|
177
|
+
identity,
|
|
178
|
+
attributes,
|
|
179
|
+
metadata,
|
|
180
|
+
name
|
|
181
|
+
});
|
|
182
|
+
if (permission) {
|
|
183
|
+
req.permission = new import_protocol.ParticipantPermission(permission);
|
|
184
|
+
}
|
|
185
|
+
const data = await this.rpc.request(
|
|
186
|
+
svc,
|
|
187
|
+
"UpdateParticipant",
|
|
188
|
+
req.toJson(),
|
|
189
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
190
|
+
);
|
|
191
|
+
return import_protocol.ParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Updates a participant's subscription to tracks
|
|
195
|
+
* @param room -
|
|
196
|
+
* @param identity -
|
|
197
|
+
* @param trackSids -
|
|
198
|
+
* @param subscribe - true to subscribe, false to unsubscribe
|
|
199
|
+
*/
|
|
200
|
+
async updateSubscriptions(room, identity, trackSids, subscribe) {
|
|
201
|
+
const req = new import_protocol.UpdateSubscriptionsRequest({
|
|
202
|
+
room,
|
|
203
|
+
identity,
|
|
204
|
+
trackSids,
|
|
205
|
+
subscribe,
|
|
206
|
+
participantTracks: []
|
|
207
|
+
}).toJson();
|
|
208
|
+
await this.rpc.request(
|
|
209
|
+
svc,
|
|
210
|
+
"UpdateSubscriptions",
|
|
211
|
+
req,
|
|
212
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
async sendData(room, data, kind, options = {}) {
|
|
216
|
+
const destinationSids = Array.isArray(options) ? options : options.destinationSids;
|
|
217
|
+
const topic = Array.isArray(options) ? void 0 : options.topic;
|
|
218
|
+
const req = new import_protocol.SendDataRequest({
|
|
219
|
+
room,
|
|
220
|
+
data,
|
|
221
|
+
kind,
|
|
222
|
+
destinationSids: destinationSids ?? [],
|
|
223
|
+
topic
|
|
224
|
+
});
|
|
225
|
+
if (!Array.isArray(options) && options.destinationIdentities) {
|
|
226
|
+
req.destinationIdentities = options.destinationIdentities;
|
|
227
|
+
}
|
|
228
|
+
await this.rpc.request(
|
|
229
|
+
svc,
|
|
230
|
+
"SendData",
|
|
231
|
+
req.toJson(),
|
|
232
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
237
|
+
0 && (module.exports = {
|
|
238
|
+
RoomServiceClient
|
|
239
|
+
});
|
|
240
|
+
//# sourceMappingURL=RoomServiceClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/RoomServiceClient.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { DataPacket_Kind, RoomEgress, TrackInfo } from '@livekit/protocol';\nimport {\n CreateRoomRequest,\n DeleteRoomRequest,\n ListParticipantsRequest,\n ListParticipantsResponse,\n ListRoomsRequest,\n ListRoomsResponse,\n MuteRoomTrackRequest,\n MuteRoomTrackResponse,\n ParticipantInfo,\n ParticipantPermission,\n Room,\n RoomParticipantIdentity,\n SendDataRequest,\n UpdateParticipantRequest,\n UpdateRoomMetadataRequest,\n UpdateSubscriptionsRequest,\n} from '@livekit/protocol';\nimport ServiceBase from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\n\n/**\n * Options for when creating a room\n */\nexport interface CreateOptions {\n /**\n * name of the room. required\n */\n name: string;\n\n /**\n * number of seconds to keep the room open before any participant joins\n */\n emptyTimeout?: number;\n\n /**\n * number of seconds to keep the room open after the last participant leaves\n * this option is helpful to give a grace period for participants to re-join\n */\n departureTimeout?: number;\n\n /**\n * limit to the number of participants in a room at a time\n */\n maxParticipants?: number;\n\n /**\n * initial room metadata\n */\n metadata?: string;\n\n /**\n * add egress options\n */\n egress?: RoomEgress;\n\n /**\n * minimum playout delay in milliseconds\n */\n minPlayoutDelay?: number;\n\n /**\n * maximum playout delay in milliseconds\n */\n maxPlayoutDelay?: number;\n\n /**\n * improves A/V sync when min_playout_delay set to a value larger than 200ms.\n * It will disables transceiver re-use -- this option is not recommended\n * for rooms with frequent subscription changes\n */\n syncStreams?: boolean;\n\n /**\n * override the node room is allocated to, for debugging\n * does not work with Cloud\n */\n nodeId?: string;\n}\n\nexport type SendDataOptions = {\n /** If set, only deliver to listed participant identities */\n destinationIdentities?: string[];\n destinationSids?: string[];\n topic?: string;\n};\n\nexport type UpdateParticipantOptions = {\n /** only attributes you'd want to update should be set, set value to empty string to remove it */\n attributes?: { [key: string]: string };\n metadata?: string;\n /** permissions are updated atomically - all desired permissions would need to be set */\n permission?: Partial<ParticipantPermission>;\n name?: string;\n};\n\nconst svc = 'RoomService';\n\n/**\n * Client to access Room APIs\n */\nexport class RoomServiceClient extends ServiceBase {\n private readonly rpc: Rpc;\n\n /**\n *\n * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'\n * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY\n * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET\n */\n constructor(host: string, apiKey?: string, secret?: string) {\n super(apiKey, secret);\n this.rpc = new TwirpRpc(host, livekitPackage);\n }\n\n /**\n * Creates a new room. Explicit room creation is not required, since rooms will\n * be automatically created when the first participant joins. This method can be\n * used to customize room settings.\n * @param options -\n */\n async createRoom(options: CreateOptions): Promise<Room> {\n const data = await this.rpc.request(\n svc,\n 'CreateRoom',\n new CreateRoomRequest(options).toJson(),\n await this.authHeader({ roomCreate: true }),\n );\n return Room.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * List active rooms\n * @param names - when undefined or empty, list all rooms.\n * otherwise returns rooms with matching names\n * @returns\n */\n async listRooms(names?: string[]): Promise<Room[]> {\n const data = await this.rpc.request(\n svc,\n 'ListRooms',\n new ListRoomsRequest({ names: names ?? [] }).toJson(),\n await this.authHeader({ roomList: true }),\n );\n const res = ListRoomsResponse.fromJson(data, { ignoreUnknownFields: true });\n return res.rooms ?? [];\n }\n\n async deleteRoom(room: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'DeleteRoom',\n new DeleteRoomRequest({ room }).toJson(),\n await this.authHeader({ roomCreate: true }),\n );\n }\n\n /**\n * Update metadata of a room\n * @param room - name of the room\n * @param metadata - the new metadata for the room\n */\n async updateRoomMetadata(room: string, metadata: string) {\n const data = await this.rpc.request(\n svc,\n 'UpdateRoomMetadata',\n new UpdateRoomMetadataRequest({ room, metadata }).toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n return Room.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * List participants in a room\n * @param room - name of the room\n */\n async listParticipants(room: string): Promise<ParticipantInfo[]> {\n const data = await this.rpc.request(\n svc,\n 'ListParticipants',\n new ListParticipantsRequest({ room }).toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n const res = ListParticipantsResponse.fromJson(data, { ignoreUnknownFields: true });\n return res.participants ?? [];\n }\n\n /**\n * Get information on a specific participant, including the tracks that participant\n * has published\n * @param room - name of the room\n * @param identity - identity of the participant to return\n */\n async getParticipant(room: string, identity: string): Promise<ParticipantInfo> {\n const data = await this.rpc.request(\n svc,\n 'GetParticipant',\n new RoomParticipantIdentity({ room, identity }).toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n\n return ParticipantInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * Removes a participant in the room. This will disconnect the participant\n * and will emit a Disconnected event for that participant.\n * Even after being removed, the participant can still re-join the room.\n * @param room -\n * @param identity -\n */\n async removeParticipant(room: string, identity: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'RemoveParticipant',\n new RoomParticipantIdentity({ room, identity }).toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n }\n\n /**\n * Mutes a track that the participant has published.\n * @param room -\n * @param identity -\n * @param trackSid - sid of the track to be muted\n * @param muted - true to mute, false to unmute\n */\n async mutePublishedTrack(\n room: string,\n identity: string,\n trackSid: string,\n muted: boolean,\n ): Promise<TrackInfo> {\n const req = new MuteRoomTrackRequest({\n room,\n identity,\n trackSid,\n muted,\n }).toJson();\n const data = await this.rpc.request(\n svc,\n 'MutePublishedTrack',\n req,\n await this.authHeader({ roomAdmin: true, room }),\n );\n const res = MuteRoomTrackResponse.fromJson(data, { ignoreUnknownFields: true });\n return res.track!;\n }\n\n /**\n * Updates a participant's state or permissions\n * @param room - target room\n * @param identity - participant identity\n * @param options - participant fields to update\n */\n async updateParticipant(\n room: string,\n identity: string,\n options: UpdateParticipantOptions,\n ): Promise<ParticipantInfo>;\n /**\n * Updates a participant's state or permissions\n * @param room - target room\n * @param identity - participant identity\n * @param options - participant fields to update\n */\n async updateParticipant(\n room: string,\n identity: string,\n metadata?: string,\n permission?: Partial<ParticipantPermission>,\n name?: string,\n ): Promise<ParticipantInfo>;\n async updateParticipant(\n room: string,\n identity: string,\n metadataOrOptions?: string | UpdateParticipantOptions,\n maybePermission?: Partial<ParticipantPermission>,\n maybeName?: string,\n ): Promise<ParticipantInfo> {\n const hasOptions = typeof metadataOrOptions === 'object';\n const metadata = hasOptions ? metadataOrOptions?.metadata : metadataOrOptions;\n const permission = hasOptions ? metadataOrOptions.permission : maybePermission;\n const name = hasOptions ? metadataOrOptions.name : maybeName;\n const attributes: Record<string, string> | undefined = hasOptions\n ? metadataOrOptions.attributes\n : {};\n\n const req = new UpdateParticipantRequest({\n room,\n identity,\n attributes,\n metadata,\n name,\n });\n if (permission) {\n req.permission = new ParticipantPermission(permission);\n }\n const data = await this.rpc.request(\n svc,\n 'UpdateParticipant',\n req.toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n return ParticipantInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * Updates a participant's subscription to tracks\n * @param room -\n * @param identity -\n * @param trackSids -\n * @param subscribe - true to subscribe, false to unsubscribe\n */\n async updateSubscriptions(\n room: string,\n identity: string,\n trackSids: string[],\n subscribe: boolean,\n ): Promise<void> {\n const req = new UpdateSubscriptionsRequest({\n room,\n identity,\n trackSids,\n subscribe,\n participantTracks: [],\n }).toJson();\n await this.rpc.request(\n svc,\n 'UpdateSubscriptions',\n req,\n await this.authHeader({ roomAdmin: true, room }),\n );\n }\n\n /**\n * Sends data message to participants in the room\n * @param room -\n * @param data - opaque payload to send\n * @param kind - delivery reliability\n * @param options - optionally specify a topic and destinationSids (when destinationSids is empty, message is sent to everyone)\n */\n async sendData(\n room: string,\n data: Uint8Array,\n kind: DataPacket_Kind,\n options: SendDataOptions,\n ): Promise<void>;\n /**\n * Sends data message to participants in the room\n * @deprecated use sendData(room, data, kind, options) instead\n * @param room -\n * @param data - opaque payload to send\n * @param kind - delivery reliability\n * @param destinationSids - optional. when empty, message is sent to everyone\n */\n async sendData(\n room: string,\n data: Uint8Array,\n kind: DataPacket_Kind,\n destinationSids?: string[],\n ): Promise<void>;\n async sendData(\n room: string,\n data: Uint8Array,\n kind: DataPacket_Kind,\n options: SendDataOptions | string[] = {},\n ): Promise<void> {\n const destinationSids = Array.isArray(options) ? options : options.destinationSids;\n const topic = Array.isArray(options) ? undefined : options.topic;\n const req = new SendDataRequest({\n room,\n data,\n kind,\n destinationSids: destinationSids ?? [],\n topic,\n });\n if (!Array.isArray(options) && options.destinationIdentities) {\n req.destinationIdentities = options.destinationIdentities;\n }\n await this.rpc.request(\n svc,\n 'SendData',\n req.toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAiBO;AACP,yBAAwB;AAExB,sBAAyC;AA6EzC,MAAM,MAAM;AAKL,MAAM,0BAA0B,mBAAAA,QAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASjD,YAAY,MAAc,QAAiB,QAAiB;AAC1D,UAAM,QAAQ,MAAM;AACpB,SAAK,MAAM,IAAI,yBAAS,MAAM,8BAAc;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,SAAuC;AACtD,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,IAAI,kCAAkB,OAAO,EAAE,OAAO;AAAA,MACtC,MAAM,KAAK,WAAW,EAAE,YAAY,KAAK,CAAC;AAAA,IAC5C;AACA,WAAO,qBAAK,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,UAAU,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A,MACA;AAAA,MACA,IAAI,OAAO;AAAA,MACX,MAAM,KAAK,WAAW,EAAE,WAAW,MAAM,KAAK,CAAC;AAAA,IACjD;AAAA,EACF;AACF;","names":["ServiceBase"]}
|
|
@@ -1,155 +1,223 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import {
|
|
2
|
+
CreateRoomRequest,
|
|
3
|
+
DeleteRoomRequest,
|
|
4
|
+
ListParticipantsRequest,
|
|
5
|
+
ListParticipantsResponse,
|
|
6
|
+
ListRoomsRequest,
|
|
7
|
+
ListRoomsResponse,
|
|
8
|
+
MuteRoomTrackRequest,
|
|
9
|
+
MuteRoomTrackResponse,
|
|
10
|
+
ParticipantInfo,
|
|
11
|
+
ParticipantPermission,
|
|
12
|
+
Room,
|
|
13
|
+
RoomParticipantIdentity,
|
|
14
|
+
SendDataRequest,
|
|
15
|
+
UpdateParticipantRequest,
|
|
16
|
+
UpdateRoomMetadataRequest,
|
|
17
|
+
UpdateSubscriptionsRequest
|
|
18
|
+
} from "@livekit/protocol";
|
|
19
|
+
import ServiceBase from "./ServiceBase.js";
|
|
20
|
+
import { TwirpRpc, livekitPackage } from "./TwirpRPC.js";
|
|
21
|
+
const svc = "RoomService";
|
|
22
|
+
class RoomServiceClient extends ServiceBase {
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
|
|
26
|
+
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
|
|
27
|
+
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
28
|
+
*/
|
|
29
|
+
constructor(host, apiKey, secret) {
|
|
30
|
+
super(apiKey, secret);
|
|
31
|
+
this.rpc = new TwirpRpc(host, livekitPackage);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new room. Explicit room creation is not required, since rooms will
|
|
35
|
+
* be automatically created when the first participant joins. This method can be
|
|
36
|
+
* used to customize room settings.
|
|
37
|
+
* @param options -
|
|
38
|
+
*/
|
|
39
|
+
async createRoom(options) {
|
|
40
|
+
const data = await this.rpc.request(
|
|
41
|
+
svc,
|
|
42
|
+
"CreateRoom",
|
|
43
|
+
new CreateRoomRequest(options).toJson(),
|
|
44
|
+
await this.authHeader({ roomCreate: true })
|
|
45
|
+
);
|
|
46
|
+
return Room.fromJson(data, { ignoreUnknownFields: true });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* List active rooms
|
|
50
|
+
* @param names - when undefined or empty, list all rooms.
|
|
51
|
+
* otherwise returns rooms with matching names
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
async listRooms(names) {
|
|
55
|
+
const data = await this.rpc.request(
|
|
56
|
+
svc,
|
|
57
|
+
"ListRooms",
|
|
58
|
+
new ListRoomsRequest({ names: names ?? [] }).toJson(),
|
|
59
|
+
await this.authHeader({ roomList: true })
|
|
60
|
+
);
|
|
61
|
+
const res = ListRoomsResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
62
|
+
return res.rooms ?? [];
|
|
63
|
+
}
|
|
64
|
+
async deleteRoom(room) {
|
|
65
|
+
await this.rpc.request(
|
|
66
|
+
svc,
|
|
67
|
+
"DeleteRoom",
|
|
68
|
+
new DeleteRoomRequest({ room }).toJson(),
|
|
69
|
+
await this.authHeader({ roomCreate: true })
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Update metadata of a room
|
|
74
|
+
* @param room - name of the room
|
|
75
|
+
* @param metadata - the new metadata for the room
|
|
76
|
+
*/
|
|
77
|
+
async updateRoomMetadata(room, metadata) {
|
|
78
|
+
const data = await this.rpc.request(
|
|
79
|
+
svc,
|
|
80
|
+
"UpdateRoomMetadata",
|
|
81
|
+
new UpdateRoomMetadataRequest({ room, metadata }).toJson(),
|
|
82
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
83
|
+
);
|
|
84
|
+
return Room.fromJson(data, { ignoreUnknownFields: true });
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* List participants in a room
|
|
88
|
+
* @param room - name of the room
|
|
89
|
+
*/
|
|
90
|
+
async listParticipants(room) {
|
|
91
|
+
const data = await this.rpc.request(
|
|
92
|
+
svc,
|
|
93
|
+
"ListParticipants",
|
|
94
|
+
new ListParticipantsRequest({ room }).toJson(),
|
|
95
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
96
|
+
);
|
|
97
|
+
const res = ListParticipantsResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
98
|
+
return res.participants ?? [];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get information on a specific participant, including the tracks that participant
|
|
102
|
+
* has published
|
|
103
|
+
* @param room - name of the room
|
|
104
|
+
* @param identity - identity of the participant to return
|
|
105
|
+
*/
|
|
106
|
+
async getParticipant(room, identity) {
|
|
107
|
+
const data = await this.rpc.request(
|
|
108
|
+
svc,
|
|
109
|
+
"GetParticipant",
|
|
110
|
+
new RoomParticipantIdentity({ room, identity }).toJson(),
|
|
111
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
112
|
+
);
|
|
113
|
+
return ParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Removes a participant in the room. This will disconnect the participant
|
|
117
|
+
* and will emit a Disconnected event for that participant.
|
|
118
|
+
* Even after being removed, the participant can still re-join the room.
|
|
119
|
+
* @param room -
|
|
120
|
+
* @param identity -
|
|
121
|
+
*/
|
|
122
|
+
async removeParticipant(room, identity) {
|
|
123
|
+
await this.rpc.request(
|
|
124
|
+
svc,
|
|
125
|
+
"RemoveParticipant",
|
|
126
|
+
new RoomParticipantIdentity({ room, identity }).toJson(),
|
|
127
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Mutes a track that the participant has published.
|
|
132
|
+
* @param room -
|
|
133
|
+
* @param identity -
|
|
134
|
+
* @param trackSid - sid of the track to be muted
|
|
135
|
+
* @param muted - true to mute, false to unmute
|
|
136
|
+
*/
|
|
137
|
+
async mutePublishedTrack(room, identity, trackSid, muted) {
|
|
138
|
+
const req = new MuteRoomTrackRequest({
|
|
139
|
+
room,
|
|
140
|
+
identity,
|
|
141
|
+
trackSid,
|
|
142
|
+
muted
|
|
143
|
+
}).toJson();
|
|
144
|
+
const data = await this.rpc.request(
|
|
145
|
+
svc,
|
|
146
|
+
"MutePublishedTrack",
|
|
147
|
+
req,
|
|
148
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
149
|
+
);
|
|
150
|
+
const res = MuteRoomTrackResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
151
|
+
return res.track;
|
|
152
|
+
}
|
|
153
|
+
async updateParticipant(room, identity, metadataOrOptions, maybePermission, maybeName) {
|
|
154
|
+
const hasOptions = typeof metadataOrOptions === "object";
|
|
155
|
+
const metadata = hasOptions ? metadataOrOptions == null ? void 0 : metadataOrOptions.metadata : metadataOrOptions;
|
|
156
|
+
const permission = hasOptions ? metadataOrOptions.permission : maybePermission;
|
|
157
|
+
const name = hasOptions ? metadataOrOptions.name : maybeName;
|
|
158
|
+
const attributes = hasOptions ? metadataOrOptions.attributes : {};
|
|
159
|
+
const req = new UpdateParticipantRequest({
|
|
160
|
+
room,
|
|
161
|
+
identity,
|
|
162
|
+
attributes,
|
|
163
|
+
metadata,
|
|
164
|
+
name
|
|
165
|
+
});
|
|
166
|
+
if (permission) {
|
|
167
|
+
req.permission = new ParticipantPermission(permission);
|
|
18
168
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return (_a = res.participants) !== null && _a !== void 0 ? _a : [];
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Get information on a specific participant, including the tracks that participant
|
|
65
|
-
* has published
|
|
66
|
-
* @param room - name of the room
|
|
67
|
-
* @param identity - identity of the participant to return
|
|
68
|
-
*/
|
|
69
|
-
async getParticipant(room, identity) {
|
|
70
|
-
const data = await this.rpc.request(svc, 'GetParticipant', new RoomParticipantIdentity({ room, identity }).toJson(), await this.authHeader({ roomAdmin: true, room }));
|
|
71
|
-
return ParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Removes a participant in the room. This will disconnect the participant
|
|
75
|
-
* and will emit a Disconnected event for that participant.
|
|
76
|
-
* Even after being removed, the participant can still re-join the room.
|
|
77
|
-
* @param room -
|
|
78
|
-
* @param identity -
|
|
79
|
-
*/
|
|
80
|
-
async removeParticipant(room, identity) {
|
|
81
|
-
await this.rpc.request(svc, 'RemoveParticipant', new RoomParticipantIdentity({ room, identity }).toJson(), await this.authHeader({ roomAdmin: true, room }));
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Mutes a track that the participant has published.
|
|
85
|
-
* @param room -
|
|
86
|
-
* @param identity -
|
|
87
|
-
* @param trackSid - sid of the track to be muted
|
|
88
|
-
* @param muted - true to mute, false to unmute
|
|
89
|
-
*/
|
|
90
|
-
async mutePublishedTrack(room, identity, trackSid, muted) {
|
|
91
|
-
const req = new MuteRoomTrackRequest({
|
|
92
|
-
room,
|
|
93
|
-
identity,
|
|
94
|
-
trackSid,
|
|
95
|
-
muted,
|
|
96
|
-
}).toJson();
|
|
97
|
-
const data = await this.rpc.request(svc, 'MutePublishedTrack', req, await this.authHeader({ roomAdmin: true, room }));
|
|
98
|
-
const res = MuteRoomTrackResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
99
|
-
return res.track;
|
|
100
|
-
}
|
|
101
|
-
async updateParticipant(room, identity, metadataOrOptions, maybePermission, maybeName) {
|
|
102
|
-
const hasOptions = typeof metadataOrOptions === 'object';
|
|
103
|
-
const metadata = hasOptions ? metadataOrOptions === null || metadataOrOptions === void 0 ? void 0 : metadataOrOptions.metadata : metadataOrOptions;
|
|
104
|
-
const permission = hasOptions ? metadataOrOptions.permission : maybePermission;
|
|
105
|
-
const name = hasOptions ? metadataOrOptions.name : maybeName;
|
|
106
|
-
const attributes = hasOptions
|
|
107
|
-
? metadataOrOptions.attributes
|
|
108
|
-
: {};
|
|
109
|
-
const req = new UpdateParticipantRequest({
|
|
110
|
-
room,
|
|
111
|
-
identity,
|
|
112
|
-
attributes,
|
|
113
|
-
metadata,
|
|
114
|
-
name,
|
|
115
|
-
});
|
|
116
|
-
if (permission) {
|
|
117
|
-
req.permission = new ParticipantPermission(permission);
|
|
118
|
-
}
|
|
119
|
-
const data = await this.rpc.request(svc, 'UpdateParticipant', req.toJson(), await this.authHeader({ roomAdmin: true, room }));
|
|
120
|
-
return ParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Updates a participant's subscription to tracks
|
|
124
|
-
* @param room -
|
|
125
|
-
* @param identity -
|
|
126
|
-
* @param trackSids -
|
|
127
|
-
* @param subscribe - true to subscribe, false to unsubscribe
|
|
128
|
-
*/
|
|
129
|
-
async updateSubscriptions(room, identity, trackSids, subscribe) {
|
|
130
|
-
const req = new UpdateSubscriptionsRequest({
|
|
131
|
-
room,
|
|
132
|
-
identity,
|
|
133
|
-
trackSids,
|
|
134
|
-
subscribe,
|
|
135
|
-
participantTracks: [],
|
|
136
|
-
}).toJson();
|
|
137
|
-
await this.rpc.request(svc, 'UpdateSubscriptions', req, await this.authHeader({ roomAdmin: true, room }));
|
|
138
|
-
}
|
|
139
|
-
async sendData(room, data, kind, options = {}) {
|
|
140
|
-
const destinationSids = Array.isArray(options) ? options : options.destinationSids;
|
|
141
|
-
const topic = Array.isArray(options) ? undefined : options.topic;
|
|
142
|
-
const req = new SendDataRequest({
|
|
143
|
-
room,
|
|
144
|
-
data,
|
|
145
|
-
kind,
|
|
146
|
-
destinationSids: destinationSids !== null && destinationSids !== void 0 ? destinationSids : [],
|
|
147
|
-
topic,
|
|
148
|
-
});
|
|
149
|
-
if (!Array.isArray(options) && options.destinationIdentities) {
|
|
150
|
-
req.destinationIdentities = options.destinationIdentities;
|
|
151
|
-
}
|
|
152
|
-
await this.rpc.request(svc, 'SendData', req.toJson(), await this.authHeader({ roomAdmin: true, room }));
|
|
169
|
+
const data = await this.rpc.request(
|
|
170
|
+
svc,
|
|
171
|
+
"UpdateParticipant",
|
|
172
|
+
req.toJson(),
|
|
173
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
174
|
+
);
|
|
175
|
+
return ParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Updates a participant's subscription to tracks
|
|
179
|
+
* @param room -
|
|
180
|
+
* @param identity -
|
|
181
|
+
* @param trackSids -
|
|
182
|
+
* @param subscribe - true to subscribe, false to unsubscribe
|
|
183
|
+
*/
|
|
184
|
+
async updateSubscriptions(room, identity, trackSids, subscribe) {
|
|
185
|
+
const req = new UpdateSubscriptionsRequest({
|
|
186
|
+
room,
|
|
187
|
+
identity,
|
|
188
|
+
trackSids,
|
|
189
|
+
subscribe,
|
|
190
|
+
participantTracks: []
|
|
191
|
+
}).toJson();
|
|
192
|
+
await this.rpc.request(
|
|
193
|
+
svc,
|
|
194
|
+
"UpdateSubscriptions",
|
|
195
|
+
req,
|
|
196
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
async sendData(room, data, kind, options = {}) {
|
|
200
|
+
const destinationSids = Array.isArray(options) ? options : options.destinationSids;
|
|
201
|
+
const topic = Array.isArray(options) ? void 0 : options.topic;
|
|
202
|
+
const req = new SendDataRequest({
|
|
203
|
+
room,
|
|
204
|
+
data,
|
|
205
|
+
kind,
|
|
206
|
+
destinationSids: destinationSids ?? [],
|
|
207
|
+
topic
|
|
208
|
+
});
|
|
209
|
+
if (!Array.isArray(options) && options.destinationIdentities) {
|
|
210
|
+
req.destinationIdentities = options.destinationIdentities;
|
|
153
211
|
}
|
|
212
|
+
await this.rpc.request(
|
|
213
|
+
svc,
|
|
214
|
+
"SendData",
|
|
215
|
+
req.toJson(),
|
|
216
|
+
await this.authHeader({ roomAdmin: true, room })
|
|
217
|
+
);
|
|
218
|
+
}
|
|
154
219
|
}
|
|
220
|
+
export {
|
|
221
|
+
RoomServiceClient
|
|
222
|
+
};
|
|
155
223
|
//# sourceMappingURL=RoomServiceClient.js.map
|