livekit-server-sdk 2.15.3 → 2.15.4
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/dist/RoomServiceClient.cjs +7 -2
- package/dist/RoomServiceClient.cjs.map +1 -1
- package/dist/RoomServiceClient.d.cts +9 -2
- package/dist/RoomServiceClient.d.ts +9 -2
- package/dist/RoomServiceClient.d.ts.map +1 -1
- package/dist/RoomServiceClient.js +7 -2
- package/dist/RoomServiceClient.js.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/RoomServiceClient.ts +18 -2
|
@@ -127,12 +127,17 @@ class RoomServiceClient extends import_ServiceBase.ServiceBase {
|
|
|
127
127
|
* Even after being removed, the participant can still re-join the room.
|
|
128
128
|
* @param room -
|
|
129
129
|
* @param identity -
|
|
130
|
+
* @param options - removal options
|
|
130
131
|
*/
|
|
131
|
-
async removeParticipant(room, identity) {
|
|
132
|
+
async removeParticipant(room, identity, options) {
|
|
132
133
|
await this.rpc.request(
|
|
133
134
|
svc,
|
|
134
135
|
"RemoveParticipant",
|
|
135
|
-
new import_protocol.RoomParticipantIdentity({
|
|
136
|
+
new import_protocol.RoomParticipantIdentity({
|
|
137
|
+
room,
|
|
138
|
+
identity,
|
|
139
|
+
revokeTokenTs: options == null ? void 0 : options.revokeTokenTs
|
|
140
|
+
}).toJson(),
|
|
136
141
|
await this.authHeader({ roomAdmin: true, room })
|
|
137
142
|
);
|
|
138
143
|
}
|
|
@@ -1 +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, RoomAgentDispatch, RoomEgress, TrackInfo } from '@livekit/protocol';\nimport {\n CreateRoomRequest,\n DeleteRoomRequest,\n ForwardParticipantRequest,\n ListParticipantsRequest,\n ListParticipantsResponse,\n ListRoomsRequest,\n ListRoomsResponse,\n MoveParticipantRequest,\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 type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\nimport { getRandomBytes } from './crypto/uuid.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 * agents that should be dispatched to this room\n */\n agents?: RoomAgentDispatch[];\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 * @param options - client options\n */\n constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n super(apiKey, secret);\n const rpcOptions = options?.requestTimeout\n ? { requestTimeout: options.requestTimeout }\n : undefined;\n this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);\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 * Forwards a participant's track to another room. This will create a\n * participant to join the destination room that has same information\n * with the source participant except the kind to be `Forwarded`. All\n * changes to the source participant will be reflected to the forwarded\n * participant. When the source participant disconnects or the\n * `RemoveParticipant` method is called in the destination room, the\n * forwarding will be stopped.\n * @param room -\n * @param identity -\n * @param destinationRoom - the room to forward the participant to\n */\n async forwardParticipant(room: string, identity: string, destinationRoom: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'ForwardParticipant',\n new ForwardParticipantRequest({ room, identity, destinationRoom }).toJson(),\n await this.authHeader({ roomAdmin: true, room, destinationRoom }),\n );\n }\n\n /**\n * Move a connected participant to a different room. Requires `roomAdmin` and `destinationRoom`.\n * The participant will be removed from the current room and added to the destination room.\n * From the other observers' perspective, the participant would've disconnected from the previous room and joined the new one.\n * @param room -\n * @param identity -\n * @param destinationRoom - the room to move the participant to\n */\n async moveParticipant(room: string, identity: string, destinationRoom: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'MoveParticipant',\n new MoveParticipantRequest({ room, identity, destinationRoom }).toJson(),\n await this.authHeader({ roomAdmin: true, room, destinationRoom }),\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 req.nonce = await getRandomBytes(16);\n await this.rpc.request(\n svc,\n 'SendData',\n req.toJson(),\n await this.authHeader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ACA;AAAA,MACA;AAAA,MACA,iBAAiB,mBAAmB,CAAC;AAAA,MACrC;AAAA,IACF,CAAC;AACD,QAAI,CAAC,MAAM,QAAQ,OAAO,KAAK,QAAQ,uBAAuB;AAC5D,UAAI,wBAAwB,QAAQ;AAAA,IACtC;AACA,QAAI,QAAQ,UAAM,4BAAe,EAAE;AACnC,UAAM,KAAK,IAAI;AAAA,MACb;AAAA,MACA;AAAA,MACA,IAAI,OAAO;AAAA,MACX,MAAM,KAAK,WAAW,EAAE,WAAW,MAAM,KAAK,CAAC;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
|
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, RoomAgentDispatch, RoomEgress, TrackInfo } from '@livekit/protocol';\nimport {\n CreateRoomRequest,\n DeleteRoomRequest,\n ForwardParticipantRequest,\n ListParticipantsRequest,\n ListParticipantsResponse,\n ListRoomsRequest,\n ListRoomsResponse,\n MoveParticipantRequest,\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 type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\nimport { getRandomBytes } from './crypto/uuid.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 * agents that should be dispatched to this room\n */\n agents?: RoomAgentDispatch[];\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\nexport type RemoveParticipantOptions = {\n /**\n * Unix timestamp used to invalidate tokens whose nbf is before this value.\n */\n revokeTokenTs?: bigint;\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 * @param options - client options\n */\n constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n super(apiKey, secret);\n const rpcOptions = options?.requestTimeout\n ? { requestTimeout: options.requestTimeout }\n : undefined;\n this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);\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 * @param options - removal options\n */\n async removeParticipant(\n room: string,\n identity: string,\n options?: RemoveParticipantOptions,\n ): Promise<void> {\n await this.rpc.request(\n svc,\n 'RemoveParticipant',\n new RoomParticipantIdentity({\n room,\n identity,\n revokeTokenTs: options?.revokeTokenTs,\n }).toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n }\n\n /**\n * Forwards a participant's track to another room. This will create a\n * participant to join the destination room that has same information\n * with the source participant except the kind to be `Forwarded`. All\n * changes to the source participant will be reflected to the forwarded\n * participant. When the source participant disconnects or the\n * `RemoveParticipant` method is called in the destination room, the\n * forwarding will be stopped.\n * @param room -\n * @param identity -\n * @param destinationRoom - the room to forward the participant to\n */\n async forwardParticipant(room: string, identity: string, destinationRoom: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'ForwardParticipant',\n new ForwardParticipantRequest({ room, identity, destinationRoom }).toJson(),\n await this.authHeader({ roomAdmin: true, room, destinationRoom }),\n );\n }\n\n /**\n * Move a connected participant to a different room. Requires `roomAdmin` and `destinationRoom`.\n * The participant will be removed from the current room and added to the destination room.\n * From the other observers' perspective, the participant would've disconnected from the previous room and joined the new one.\n * @param room -\n * @param identity -\n * @param destinationRoom - the room to move the participant to\n */\n async moveParticipant(room: string, identity: string, destinationRoom: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'MoveParticipant',\n new MoveParticipantRequest({ room, identity, destinationRoom }).toJson(),\n await this.authHeader({ roomAdmin: true, room, destinationRoom }),\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 req.nonce = await getRandomBytes(16);\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,sBAmBO;AAEP,yBAA4B;AAE5B,sBAAyC;AACzC,kBAA+B;AAyF/B,MAAM,MAAM;AAKL,MAAM,0BAA0B,+BAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUjD,YAAY,MAAc,QAAiB,QAAiB,SAAyB;AACnF,UAAM,QAAQ,MAAM;AACpB,UAAM,cAAa,mCAAS,kBACxB,EAAE,gBAAgB,QAAQ,eAAe,IACzC;AACJ,SAAK,MAAM,IAAI,yBAAS,MAAM,gCAAgB,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
|
|
@@ -73,6 +73,12 @@ type UpdateParticipantOptions = {
|
|
|
73
73
|
permission?: Partial<ParticipantPermission>;
|
|
74
74
|
name?: string;
|
|
75
75
|
};
|
|
76
|
+
type RemoveParticipantOptions = {
|
|
77
|
+
/**
|
|
78
|
+
* Unix timestamp used to invalidate tokens whose nbf is before this value.
|
|
79
|
+
*/
|
|
80
|
+
revokeTokenTs?: bigint;
|
|
81
|
+
};
|
|
76
82
|
/**
|
|
77
83
|
* Client to access Room APIs
|
|
78
84
|
*/
|
|
@@ -125,8 +131,9 @@ declare class RoomServiceClient extends ServiceBase {
|
|
|
125
131
|
* Even after being removed, the participant can still re-join the room.
|
|
126
132
|
* @param room -
|
|
127
133
|
* @param identity -
|
|
134
|
+
* @param options - removal options
|
|
128
135
|
*/
|
|
129
|
-
removeParticipant(room: string, identity: string): Promise<void>;
|
|
136
|
+
removeParticipant(room: string, identity: string, options?: RemoveParticipantOptions): Promise<void>;
|
|
130
137
|
/**
|
|
131
138
|
* Forwards a participant's track to another room. This will create a
|
|
132
139
|
* participant to join the destination room that has same information
|
|
@@ -198,4 +205,4 @@ declare class RoomServiceClient extends ServiceBase {
|
|
|
198
205
|
sendData(room: string, data: Uint8Array, kind: DataPacket_Kind, destinationSids?: string[]): Promise<void>;
|
|
199
206
|
}
|
|
200
207
|
|
|
201
|
-
export { type CreateOptions, RoomServiceClient, type SendDataOptions, type UpdateParticipantOptions };
|
|
208
|
+
export { type CreateOptions, type RemoveParticipantOptions, RoomServiceClient, type SendDataOptions, type UpdateParticipantOptions };
|
|
@@ -73,6 +73,12 @@ type UpdateParticipantOptions = {
|
|
|
73
73
|
permission?: Partial<ParticipantPermission>;
|
|
74
74
|
name?: string;
|
|
75
75
|
};
|
|
76
|
+
type RemoveParticipantOptions = {
|
|
77
|
+
/**
|
|
78
|
+
* Unix timestamp used to invalidate tokens whose nbf is before this value.
|
|
79
|
+
*/
|
|
80
|
+
revokeTokenTs?: bigint;
|
|
81
|
+
};
|
|
76
82
|
/**
|
|
77
83
|
* Client to access Room APIs
|
|
78
84
|
*/
|
|
@@ -125,8 +131,9 @@ declare class RoomServiceClient extends ServiceBase {
|
|
|
125
131
|
* Even after being removed, the participant can still re-join the room.
|
|
126
132
|
* @param room -
|
|
127
133
|
* @param identity -
|
|
134
|
+
* @param options - removal options
|
|
128
135
|
*/
|
|
129
|
-
removeParticipant(room: string, identity: string): Promise<void>;
|
|
136
|
+
removeParticipant(room: string, identity: string, options?: RemoveParticipantOptions): Promise<void>;
|
|
130
137
|
/**
|
|
131
138
|
* Forwards a participant's track to another room. This will create a
|
|
132
139
|
* participant to join the destination room that has same information
|
|
@@ -198,4 +205,4 @@ declare class RoomServiceClient extends ServiceBase {
|
|
|
198
205
|
sendData(room: string, data: Uint8Array, kind: DataPacket_Kind, destinationSids?: string[]): Promise<void>;
|
|
199
206
|
}
|
|
200
207
|
|
|
201
|
-
export { type CreateOptions, RoomServiceClient, type SendDataOptions, type UpdateParticipantOptions };
|
|
208
|
+
export { type CreateOptions, type RemoveParticipantOptions, RoomServiceClient, type SendDataOptions, type UpdateParticipantOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RoomServiceClient.d.ts","sourceRoot":"","sources":["../src/RoomServiceClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,EAWL,eAAe,EACf,qBAAqB,EACrB,IAAI,EAML,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAK/C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,gBAAgB,CAA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E,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EAAE,EACnB,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,IAAI,CAAC;IAgBhB;;;;;;OAMG;IACG,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,IAAI,CAAC;IAChB;;;;;;;OAOG;IACG,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,eAAe,EACrB,eAAe,CAAC,EAAE,MAAM,EAAE,GACzB,OAAO,CAAC,IAAI,CAAC;CA2BjB"}
|
|
@@ -123,12 +123,17 @@ class RoomServiceClient extends ServiceBase {
|
|
|
123
123
|
* Even after being removed, the participant can still re-join the room.
|
|
124
124
|
* @param room -
|
|
125
125
|
* @param identity -
|
|
126
|
+
* @param options - removal options
|
|
126
127
|
*/
|
|
127
|
-
async removeParticipant(room, identity) {
|
|
128
|
+
async removeParticipant(room, identity, options) {
|
|
128
129
|
await this.rpc.request(
|
|
129
130
|
svc,
|
|
130
131
|
"RemoveParticipant",
|
|
131
|
-
new RoomParticipantIdentity({
|
|
132
|
+
new RoomParticipantIdentity({
|
|
133
|
+
room,
|
|
134
|
+
identity,
|
|
135
|
+
revokeTokenTs: options == null ? void 0 : options.revokeTokenTs
|
|
136
|
+
}).toJson(),
|
|
132
137
|
await this.authHeader({ roomAdmin: true, room })
|
|
133
138
|
);
|
|
134
139
|
}
|
|
@@ -1 +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, RoomAgentDispatch, RoomEgress, TrackInfo } from '@livekit/protocol';\nimport {\n CreateRoomRequest,\n DeleteRoomRequest,\n ForwardParticipantRequest,\n ListParticipantsRequest,\n ListParticipantsResponse,\n ListRoomsRequest,\n ListRoomsResponse,\n MoveParticipantRequest,\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 type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\nimport { getRandomBytes } from './crypto/uuid.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 * agents that should be dispatched to this room\n */\n agents?: RoomAgentDispatch[];\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 * @param options - client options\n */\n constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n super(apiKey, secret);\n const rpcOptions = options?.requestTimeout\n ? { requestTimeout: options.requestTimeout }\n : undefined;\n this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);\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 * Forwards a participant's track to another room. This will create a\n * participant to join the destination room that has same information\n * with the source participant except the kind to be `Forwarded`. All\n * changes to the source participant will be reflected to the forwarded\n * participant. When the source participant disconnects or the\n * `RemoveParticipant` method is called in the destination room, the\n * forwarding will be stopped.\n * @param room -\n * @param identity -\n * @param destinationRoom - the room to forward the participant to\n */\n async forwardParticipant(room: string, identity: string, destinationRoom: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'ForwardParticipant',\n new ForwardParticipantRequest({ room, identity, destinationRoom }).toJson(),\n await this.authHeader({ roomAdmin: true, room, destinationRoom }),\n );\n }\n\n /**\n * Move a connected participant to a different room. Requires `roomAdmin` and `destinationRoom`.\n * The participant will be removed from the current room and added to the destination room.\n * From the other observers' perspective, the participant would've disconnected from the previous room and joined the new one.\n * @param room -\n * @param identity -\n * @param destinationRoom - the room to move the participant to\n */\n async moveParticipant(room: string, identity: string, destinationRoom: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'MoveParticipant',\n new MoveParticipantRequest({ room, identity, destinationRoom }).toJson(),\n await this.authHeader({ roomAdmin: true, room, destinationRoom }),\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 req.nonce = await getRandomBytes(16);\n await this.rpc.request(\n svc,\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A,MACA,UAAsC,CAAC,GACxB;AACf,UAAM,kBAAkB,MAAM,QAAQ,OAAO,IAAI,UAAU,QAAQ;AACnE,UAAM,QAAQ,MAAM,QAAQ,OAAO,IAAI,SAAY,QAAQ;AAC3D,UAAM,MAAM,IAAI,gBAAgB;AAAA,MAC9B;AAAA,MACA;AAAA,MACA;AAAA,MACA,iBAAiB,mBAAmB,CAAC;AAAA,MACrC;AAAA,IACF,CAAC;AACD,QAAI,CAAC,MAAM,QAAQ,OAAO,KAAK,QAAQ,uBAAuB;AAC5D,UAAI,wBAAwB,QAAQ;AAAA,IACtC;AACA,QAAI,QAAQ,MAAM,eAAe,EAAE;AACnC,UAAM,KAAK,IAAI;AAAA,MACb;AAAA,MACA;AAAA,MACA,IAAI,OAAO;AAAA,MACX,MAAM,KAAK,WAAW,EAAE,WAAW,MAAM,KAAK,CAAC;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
|
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, RoomAgentDispatch, RoomEgress, TrackInfo } from '@livekit/protocol';\nimport {\n CreateRoomRequest,\n DeleteRoomRequest,\n ForwardParticipantRequest,\n ListParticipantsRequest,\n ListParticipantsResponse,\n ListRoomsRequest,\n ListRoomsResponse,\n MoveParticipantRequest,\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 type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\nimport { getRandomBytes } from './crypto/uuid.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 * agents that should be dispatched to this room\n */\n agents?: RoomAgentDispatch[];\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\nexport type RemoveParticipantOptions = {\n /**\n * Unix timestamp used to invalidate tokens whose nbf is before this value.\n */\n revokeTokenTs?: bigint;\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 * @param options - client options\n */\n constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n super(apiKey, secret);\n const rpcOptions = options?.requestTimeout\n ? { requestTimeout: options.requestTimeout }\n : undefined;\n this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);\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 * @param options - removal options\n */\n async removeParticipant(\n room: string,\n identity: string,\n options?: RemoveParticipantOptions,\n ): Promise<void> {\n await this.rpc.request(\n svc,\n 'RemoveParticipant',\n new RoomParticipantIdentity({\n room,\n identity,\n revokeTokenTs: options?.revokeTokenTs,\n }).toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n }\n\n /**\n * Forwards a participant's track to another room. This will create a\n * participant to join the destination room that has same information\n * with the source participant except the kind to be `Forwarded`. All\n * changes to the source participant will be reflected to the forwarded\n * participant. When the source participant disconnects or the\n * `RemoveParticipant` method is called in the destination room, the\n * forwarding will be stopped.\n * @param room -\n * @param identity -\n * @param destinationRoom - the room to forward the participant to\n */\n async forwardParticipant(room: string, identity: string, destinationRoom: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'ForwardParticipant',\n new ForwardParticipantRequest({ room, identity, destinationRoom }).toJson(),\n await this.authHeader({ roomAdmin: true, room, destinationRoom }),\n );\n }\n\n /**\n * Move a connected participant to a different room. Requires `roomAdmin` and `destinationRoom`.\n * The participant will be removed from the current room and added to the destination room.\n * From the other observers' perspective, the participant would've disconnected from the previous room and joined the new one.\n * @param room -\n * @param identity -\n * @param destinationRoom - the room to move the participant to\n */\n async moveParticipant(room: string, identity: string, destinationRoom: string): Promise<void> {\n await this.rpc.request(\n svc,\n 'MoveParticipant',\n new MoveParticipantRequest({ room, identity, destinationRoom }).toJson(),\n await this.authHeader({ roomAdmin: true, room, destinationRoom }),\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 req.nonce = await getRandomBytes(16);\n await this.rpc.request(\n svc,\n 'SendData',\n req.toJson(),\n await this.authHeader({ roomAdmin: true, room }),\n );\n }\n}\n"],"mappings":"AAIA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA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AAAA,MACA,iBAAiB,mBAAmB,CAAC;AAAA,MACrC;AAAA,IACF,CAAC;AACD,QAAI,CAAC,MAAM,QAAQ,OAAO,KAAK,QAAQ,uBAAuB;AAC5D,UAAI,wBAAwB,QAAQ;AAAA,IACtC;AACA,QAAI,QAAQ,MAAM,eAAe,EAAE;AACnC,UAAM,KAAK,IAAI;AAAA,MACb;AAAA,MACA;AAAA,MACA,IAAI,OAAO;AAAA,MACX,MAAM,KAAK,WAAW,EAAE,WAAW,MAAM,KAAK,CAAC;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ export { AcceptWhatsAppCallOptions, ConnectTwilioCallOptions, ConnectorClient, D
|
|
|
5
5
|
export { BaseOptions, EgressClient, EncodedOutputs, ListEgressOptions, ParticipantEgressOptions, RoomCompositeOptions, TrackCompositeOptions, WebOptions } from './EgressClient.cjs';
|
|
6
6
|
export { ClaimGrants, InferenceGrant, ObservabilityGrant, SIPGrant, VideoGrant, claimsToJwtPayload, trackSourceToString } from './grants.cjs';
|
|
7
7
|
export { CreateIngressOptions, IngressClient, ListIngressOptions, UpdateIngressOptions } from './IngressClient.cjs';
|
|
8
|
-
export { CreateOptions, RoomServiceClient, SendDataOptions, UpdateParticipantOptions } from './RoomServiceClient.cjs';
|
|
8
|
+
export { CreateOptions, RemoveParticipantOptions, RoomServiceClient, SendDataOptions, UpdateParticipantOptions } from './RoomServiceClient.cjs';
|
|
9
9
|
export { CreateSipDispatchRuleOptions, CreateSipInboundTrunkOptions, CreateSipOutboundTrunkOptions, CreateSipParticipantOptions, CreateSipTrunkOptions, ListSipDispatchRuleOptions, ListSipTrunkOptions, SipClient, SipDispatchRuleDirect, SipDispatchRuleIndividual, SipDispatchRuleUpdateOptions, SipInboundTrunkUpdateOptions, SipOutboundTrunkUpdateOptions, TransferSipParticipantOptions } from './SipClient.cjs';
|
|
10
10
|
export { TwirpError } from './TwirpRPC.cjs';
|
|
11
11
|
export { WebhookEvent, WebhookEventNames, WebhookReceiver, authorizeHeader } from './WebhookReceiver.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { AcceptWhatsAppCallOptions, ConnectTwilioCallOptions, ConnectorClient, D
|
|
|
5
5
|
export { BaseOptions, EgressClient, EncodedOutputs, ListEgressOptions, ParticipantEgressOptions, RoomCompositeOptions, TrackCompositeOptions, WebOptions } from './EgressClient.js';
|
|
6
6
|
export { ClaimGrants, InferenceGrant, ObservabilityGrant, SIPGrant, VideoGrant, claimsToJwtPayload, trackSourceToString } from './grants.js';
|
|
7
7
|
export { CreateIngressOptions, IngressClient, ListIngressOptions, UpdateIngressOptions } from './IngressClient.js';
|
|
8
|
-
export { CreateOptions, RoomServiceClient, SendDataOptions, UpdateParticipantOptions } from './RoomServiceClient.js';
|
|
8
|
+
export { CreateOptions, RemoveParticipantOptions, RoomServiceClient, SendDataOptions, UpdateParticipantOptions } from './RoomServiceClient.js';
|
|
9
9
|
export { CreateSipDispatchRuleOptions, CreateSipInboundTrunkOptions, CreateSipOutboundTrunkOptions, CreateSipParticipantOptions, CreateSipTrunkOptions, ListSipDispatchRuleOptions, ListSipTrunkOptions, SipClient, SipDispatchRuleDirect, SipDispatchRuleIndividual, SipDispatchRuleUpdateOptions, SipInboundTrunkUpdateOptions, SipOutboundTrunkUpdateOptions, TransferSipParticipantOptions } from './SipClient.js';
|
|
10
10
|
export { TwirpError } from './TwirpRPC.js';
|
|
11
11
|
export { WebhookEvent, WebhookEventNames, WebhookReceiver, authorizeHeader } from './WebhookReceiver.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "livekit-server-sdk",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.4",
|
|
4
4
|
"description": "Server-side SDK for LiveKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"require": "dist/index.cjs",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@bufbuild/protobuf": "^1.10.1",
|
|
34
|
-
"@livekit/protocol": "^1.
|
|
34
|
+
"@livekit/protocol": "^1.46.3",
|
|
35
35
|
"camelcase-keys": "^9.0.0",
|
|
36
36
|
"jose": "^5.1.2"
|
|
37
37
|
},
|
package/src/RoomServiceClient.ts
CHANGED
|
@@ -108,6 +108,13 @@ export type UpdateParticipantOptions = {
|
|
|
108
108
|
name?: string;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
+
export type RemoveParticipantOptions = {
|
|
112
|
+
/**
|
|
113
|
+
* Unix timestamp used to invalidate tokens whose nbf is before this value.
|
|
114
|
+
*/
|
|
115
|
+
revokeTokenTs?: bigint;
|
|
116
|
+
};
|
|
117
|
+
|
|
111
118
|
const svc = 'RoomService';
|
|
112
119
|
|
|
113
120
|
/**
|
|
@@ -226,12 +233,21 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
226
233
|
* Even after being removed, the participant can still re-join the room.
|
|
227
234
|
* @param room -
|
|
228
235
|
* @param identity -
|
|
236
|
+
* @param options - removal options
|
|
229
237
|
*/
|
|
230
|
-
async removeParticipant(
|
|
238
|
+
async removeParticipant(
|
|
239
|
+
room: string,
|
|
240
|
+
identity: string,
|
|
241
|
+
options?: RemoveParticipantOptions,
|
|
242
|
+
): Promise<void> {
|
|
231
243
|
await this.rpc.request(
|
|
232
244
|
svc,
|
|
233
245
|
'RemoveParticipant',
|
|
234
|
-
new RoomParticipantIdentity({
|
|
246
|
+
new RoomParticipantIdentity({
|
|
247
|
+
room,
|
|
248
|
+
identity,
|
|
249
|
+
revokeTokenTs: options?.revokeTokenTs,
|
|
250
|
+
}).toJson(),
|
|
235
251
|
await this.authHeader({ roomAdmin: true, room }),
|
|
236
252
|
);
|
|
237
253
|
}
|