@livekit/rtc-node 0.10.2 → 0.10.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "LiveKit RTC Node",
4
4
  "license": "Apache-2.0",
5
5
  "author": "LiveKit",
6
- "version": "0.10.2",
6
+ "version": "0.10.4",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "type": "module",
@@ -43,11 +43,11 @@
43
43
  "prettier": "^3.0.3"
44
44
  },
45
45
  "optionalDependencies": {
46
- "@livekit/rtc-node-darwin-arm64": "0.10.2",
47
- "@livekit/rtc-node-darwin-x64": "0.10.2",
48
- "@livekit/rtc-node-linux-x64-gnu": "0.10.2",
49
- "@livekit/rtc-node-win32-x64-msvc": "0.10.2",
50
- "@livekit/rtc-node-linux-arm64-gnu": "0.10.2"
46
+ "@livekit/rtc-node-darwin-arm64": "0.10.4",
47
+ "@livekit/rtc-node-linux-arm64-gnu": "0.10.4",
48
+ "@livekit/rtc-node-darwin-x64": "0.10.4",
49
+ "@livekit/rtc-node-linux-x64-gnu": "0.10.4",
50
+ "@livekit/rtc-node-win32-x64-msvc": "0.10.4"
51
51
  },
52
52
  "engines": {
53
53
  "node": ">= 18"
package/src/index.ts CHANGED
@@ -43,3 +43,4 @@ export { StreamState, TrackKind, TrackSource } from './proto/track_pb.js';
43
43
  export { VideoBufferType, VideoRotation, VideoCodec } from './proto/video_frame_pb.js';
44
44
  export { ParticipantKind } from './proto/participant_pb.js';
45
45
  export { dispose } from './ffi_client.js';
46
+ export type { ChatMessage } from './types.js';
@@ -3,11 +3,14 @@
3
3
 
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
- export function livekitInitialize(callback: (data: Uint8Array) => void, captureLogs: boolean): void;
7
- export function livekitFfiRequest(data: Uint8Array): Uint8Array;
8
- export function livekitRetrievePtr(handle: Uint8Array): bigint;
9
- export function livekitCopyBuffer(ptr: bigint, len: number): Uint8Array;
10
- export function livekitDispose(): Promise<void>;
6
+ export declare function livekitInitialize(
7
+ callback: (data: Uint8Array) => void,
8
+ captureLogs: boolean,
9
+ ): void;
10
+ export declare function livekitFfiRequest(data: Uint8Array): Uint8Array;
11
+ export declare function livekitRetrievePtr(handle: Uint8Array): bigint;
12
+ export declare function livekitCopyBuffer(ptr: bigint, len: number): Uint8Array;
13
+ export declare function livekitDispose(): Promise<void>;
11
14
  export declare class FfiHandle {
12
15
  constructor(handle: bigint);
13
16
  dispose(): void;
@@ -3,7 +3,8 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import { FfiClient, FfiHandle } from './ffi_client.js';
5
5
  import type { OwnedParticipant, ParticipantInfo, ParticipantKind } from './proto/participant_pb.js';
6
- import type {
6
+ import {
7
+ ChatMessage as ChatMessageModel,
7
8
  PublishDataCallback,
8
9
  PublishDataResponse,
9
10
  PublishSipDtmfCallback,
@@ -12,6 +13,8 @@ import type {
12
13
  PublishTrackResponse,
13
14
  PublishTranscriptionCallback,
14
15
  PublishTranscriptionResponse,
16
+ SendChatMessageCallback,
17
+ SendChatMessageResponse,
15
18
  SetLocalAttributesCallback,
16
19
  SetLocalAttributesResponse,
17
20
  SetLocalMetadataCallback,
@@ -23,11 +26,13 @@ import type {
23
26
  UnpublishTrackResponse,
24
27
  } from './proto/room_pb.js';
25
28
  import {
29
+ EditChatMessageRequest,
26
30
  TranscriptionSegment as ProtoTranscriptionSegment,
27
31
  PublishDataRequest,
28
32
  PublishSipDtmfRequest,
29
33
  PublishTrackRequest,
30
34
  PublishTranscriptionRequest,
35
+ SendChatMessageRequest,
31
36
  SetLocalAttributesRequest,
32
37
  SetLocalMetadataRequest,
33
38
  SetLocalNameRequest,
@@ -37,6 +42,7 @@ import type { LocalTrack } from './track.js';
37
42
  import type { RemoteTrackPublication, TrackPublication } from './track_publication.js';
38
43
  import { LocalTrackPublication } from './track_publication.js';
39
44
  import type { Transcription } from './transcription.js';
45
+ import { ChatMessage } from './types.js';
40
46
 
41
47
  export abstract class Participant {
42
48
  /** @internal */
@@ -185,6 +191,79 @@ export class LocalParticipant extends Participant {
185
191
  });
186
192
  }
187
193
 
194
+ /**
195
+ * Sends a chat message to participants in the room
196
+ *
197
+ * @param text - The text content of the chat message.
198
+ * @param destinationIdentities - An optional array of recipient identities to whom the message will be sent. If omitted, the message is broadcast to all participants.
199
+ * @param senderIdentity - An optional identity of the sender. If omitted, the default sender identity is used.
200
+ *
201
+ */
202
+ async sendChatMessage(
203
+ text: string,
204
+ destinationIdentities?: Array<string>,
205
+ senderIdentity?: string,
206
+ ): Promise<ChatMessage> {
207
+ const req = new SendChatMessageRequest({
208
+ localParticipantHandle: this.ffi_handle.handle,
209
+ message: text,
210
+ destinationIdentities,
211
+ senderIdentity,
212
+ });
213
+
214
+ const res = FfiClient.instance.request<SendChatMessageResponse>({
215
+ message: { case: 'sendChatMessage', value: req },
216
+ });
217
+
218
+ const cb = await FfiClient.instance.waitFor<SendChatMessageCallback>((ev) => {
219
+ return ev.message.case == 'chatMessage' && ev.message.value.asyncId == res.asyncId;
220
+ });
221
+
222
+ if (cb.error) {
223
+ throw new Error(cb.error);
224
+ }
225
+ const { id, timestamp, editTimestamp, message } = cb.chatMessage!;
226
+ return { id, timestamp: Number(timestamp), editTimestamp: Number(editTimestamp), message };
227
+ }
228
+
229
+ /**
230
+ * @experimental
231
+ */
232
+ async editChatMessage(
233
+ editText: string,
234
+ originalMessage: ChatMessage,
235
+ destinationIdentities?: Array<string>,
236
+ senderIdentity?: string,
237
+ ): Promise<ChatMessage> {
238
+ const req = new EditChatMessageRequest({
239
+ localParticipantHandle: this.ffi_handle.handle,
240
+ editText,
241
+ originalMessage: new ChatMessageModel({
242
+ ...originalMessage,
243
+ timestamp: BigInt(originalMessage.timestamp),
244
+ editTimestamp: originalMessage.editTimestamp
245
+ ? BigInt(originalMessage.editTimestamp)
246
+ : undefined,
247
+ }),
248
+ destinationIdentities,
249
+ senderIdentity,
250
+ });
251
+
252
+ const res = FfiClient.instance.request<SendChatMessageResponse>({
253
+ message: { case: 'editChatMessage', value: req },
254
+ });
255
+
256
+ const cb = await FfiClient.instance.waitFor<SendChatMessageCallback>((ev) => {
257
+ return ev.message.case == 'chatMessage' && ev.message.value.asyncId == res.asyncId;
258
+ });
259
+
260
+ if (cb.error) {
261
+ throw new Error(cb.error);
262
+ }
263
+ const { id, timestamp, editTimestamp, message } = cb.chatMessage!;
264
+ return { id, timestamp: Number(timestamp), editTimestamp: Number(editTimestamp), message };
265
+ }
266
+
188
267
  async updateName(name: string) {
189
268
  const req = new SetLocalNameRequest({
190
269
  localParticipantHandle: this.ffi_handle.handle,
@@ -237,7 +316,7 @@ export class LocalParticipant extends Participant {
237
316
  throw new Error(cb.error);
238
317
  }
239
318
 
240
- const track_publication = new LocalTrackPublication(cb.publication);
319
+ const track_publication = new LocalTrackPublication(cb.publication!);
241
320
  track_publication.track = track;
242
321
  this.trackPublications.set(track_publication.sid, track_publication);
243
322
 
@@ -263,7 +342,9 @@ export class LocalParticipant extends Participant {
263
342
  }
264
343
 
265
344
  const pub = this.trackPublications.get(trackSid);
266
- pub.track = undefined;
345
+ if (pub) {
346
+ pub.track = undefined;
347
+ }
267
348
  this.trackPublications.delete(trackSid);
268
349
  }
269
350
  }
@@ -19,7 +19,7 @@
19
19
 
20
20
  import type { BinaryReadOptions, FieldList, JsonReadOptions, JsonValue, PartialMessage, PlainMessage } from "@bufbuild/protobuf";
21
21
  import { Message, proto3, protoInt64 } from "@bufbuild/protobuf";
22
- import { ConnectCallback, ConnectRequest, ConnectResponse, DisconnectCallback, DisconnectRequest, DisconnectResponse, GetSessionStatsCallback, GetSessionStatsRequest, GetSessionStatsResponse, PublishDataCallback, PublishDataRequest, PublishDataResponse, PublishSipDtmfCallback, PublishSipDtmfRequest, PublishSipDtmfResponse, PublishTrackCallback, PublishTrackRequest, PublishTrackResponse, PublishTranscriptionCallback, PublishTranscriptionRequest, PublishTranscriptionResponse, RoomEvent, SetLocalAttributesCallback, SetLocalAttributesRequest, SetLocalAttributesResponse, SetLocalMetadataCallback, SetLocalMetadataRequest, SetLocalMetadataResponse, SetLocalNameCallback, SetLocalNameRequest, SetLocalNameResponse, SetSubscribedRequest, SetSubscribedResponse, UnpublishTrackCallback, UnpublishTrackRequest, UnpublishTrackResponse } from "./room_pb.js";
22
+ import { ConnectCallback, ConnectRequest, ConnectResponse, DisconnectCallback, DisconnectRequest, DisconnectResponse, EditChatMessageRequest, GetSessionStatsCallback, GetSessionStatsRequest, GetSessionStatsResponse, PublishDataCallback, PublishDataRequest, PublishDataResponse, PublishSipDtmfCallback, PublishSipDtmfRequest, PublishSipDtmfResponse, PublishTrackCallback, PublishTrackRequest, PublishTrackResponse, PublishTranscriptionCallback, PublishTranscriptionRequest, PublishTranscriptionResponse, RoomEvent, SendChatMessageCallback, SendChatMessageRequest, SendChatMessageResponse, SetLocalAttributesCallback, SetLocalAttributesRequest, SetLocalAttributesResponse, SetLocalMetadataCallback, SetLocalMetadataRequest, SetLocalMetadataResponse, SetLocalNameCallback, SetLocalNameRequest, SetLocalNameResponse, SetSubscribedRequest, SetSubscribedResponse, UnpublishTrackCallback, UnpublishTrackRequest, UnpublishTrackResponse } from "./room_pb.js";
23
23
  import { CreateAudioTrackRequest, CreateAudioTrackResponse, CreateVideoTrackRequest, CreateVideoTrackResponse, EnableRemoteTrackRequest, EnableRemoteTrackResponse, GetStatsCallback, GetStatsRequest, GetStatsResponse, LocalTrackMuteRequest, LocalTrackMuteResponse, TrackEvent } from "./track_pb.js";
24
24
  import { CaptureVideoFrameRequest, CaptureVideoFrameResponse, NewVideoSourceRequest, NewVideoSourceResponse, NewVideoStreamRequest, NewVideoStreamResponse, VideoConvertRequest, VideoConvertResponse, VideoStreamEvent, VideoStreamFromParticipantRequest, VideoStreamFromParticipantResponse } from "./video_frame_pb.js";
25
25
  import { AudioStreamEvent, AudioStreamFromParticipantRequest, AudioStreamFromParticipantResponse, CaptureAudioFrameCallback, CaptureAudioFrameRequest, CaptureAudioFrameResponse, ClearAudioBufferRequest, ClearAudioBufferResponse, FlushSoxResamplerRequest, FlushSoxResamplerResponse, NewAudioResamplerRequest, NewAudioResamplerResponse, NewAudioSourceRequest, NewAudioSourceResponse, NewAudioStreamRequest, NewAudioStreamResponse, NewSoxResamplerRequest, NewSoxResamplerResponse, PushSoxResamplerRequest, PushSoxResamplerResponse, RemixAndResampleRequest, RemixAndResampleResponse } from "./audio_frame_pb.js";
@@ -285,6 +285,18 @@ export class FfiRequest extends Message<FfiRequest> {
285
285
  */
286
286
  value: FlushSoxResamplerRequest;
287
287
  case: "flushSoxResampler";
288
+ } | {
289
+ /**
290
+ * @generated from field: livekit.proto.SendChatMessageRequest send_chat_message = 36;
291
+ */
292
+ value: SendChatMessageRequest;
293
+ case: "sendChatMessage";
294
+ } | {
295
+ /**
296
+ * @generated from field: livekit.proto.EditChatMessageRequest edit_chat_message = 37;
297
+ */
298
+ value: EditChatMessageRequest;
299
+ case: "editChatMessage";
288
300
  } | { case: undefined; value?: undefined } = { case: undefined };
289
301
 
290
302
  constructor(data?: PartialMessage<FfiRequest>) {
@@ -329,6 +341,8 @@ export class FfiRequest extends Message<FfiRequest> {
329
341
  { no: 33, name: "new_sox_resampler", kind: "message", T: NewSoxResamplerRequest, oneof: "message" },
330
342
  { no: 34, name: "push_sox_resampler", kind: "message", T: PushSoxResamplerRequest, oneof: "message" },
331
343
  { no: 35, name: "flush_sox_resampler", kind: "message", T: FlushSoxResamplerRequest, oneof: "message" },
344
+ { no: 36, name: "send_chat_message", kind: "message", T: SendChatMessageRequest, oneof: "message" },
345
+ { no: 37, name: "edit_chat_message", kind: "message", T: EditChatMessageRequest, oneof: "message" },
332
346
  ]);
333
347
 
334
348
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): FfiRequest {
@@ -569,6 +583,12 @@ export class FfiResponse extends Message<FfiResponse> {
569
583
  */
570
584
  value: FlushSoxResamplerResponse;
571
585
  case: "flushSoxResampler";
586
+ } | {
587
+ /**
588
+ * @generated from field: livekit.proto.SendChatMessageResponse send_chat_message = 36;
589
+ */
590
+ value: SendChatMessageResponse;
591
+ case: "sendChatMessage";
572
592
  } | { case: undefined; value?: undefined } = { case: undefined };
573
593
 
574
594
  constructor(data?: PartialMessage<FfiResponse>) {
@@ -613,6 +633,7 @@ export class FfiResponse extends Message<FfiResponse> {
613
633
  { no: 33, name: "new_sox_resampler", kind: "message", T: NewSoxResamplerResponse, oneof: "message" },
614
634
  { no: 34, name: "push_sox_resampler", kind: "message", T: PushSoxResamplerResponse, oneof: "message" },
615
635
  { no: 35, name: "flush_sox_resampler", kind: "message", T: FlushSoxResamplerResponse, oneof: "message" },
636
+ { no: 36, name: "send_chat_message", kind: "message", T: SendChatMessageResponse, oneof: "message" },
616
637
  ]);
617
638
 
618
639
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): FfiResponse {
@@ -763,6 +784,12 @@ export class FfiEvent extends Message<FfiEvent> {
763
784
  */
764
785
  value: PublishSipDtmfCallback;
765
786
  case: "publishSipDtmf";
787
+ } | {
788
+ /**
789
+ * @generated from field: livekit.proto.SendChatMessageCallback chat_message = 22;
790
+ */
791
+ value: SendChatMessageCallback;
792
+ case: "chatMessage";
766
793
  } | { case: undefined; value?: undefined } = { case: undefined };
767
794
 
768
795
  constructor(data?: PartialMessage<FfiEvent>) {
@@ -793,6 +820,7 @@ export class FfiEvent extends Message<FfiEvent> {
793
820
  { no: 19, name: "get_session_stats", kind: "message", T: GetSessionStatsCallback, oneof: "message" },
794
821
  { no: 20, name: "panic", kind: "message", T: Panic, oneof: "message" },
795
822
  { no: 21, name: "publish_sip_dtmf", kind: "message", T: PublishSipDtmfCallback, oneof: "message" },
823
+ { no: 22, name: "chat_message", kind: "message", T: SendChatMessageCallback, oneof: "message" },
796
824
  ]);
797
825
 
798
826
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): FfiEvent {
@@ -1375,6 +1375,208 @@ export class SetLocalMetadataCallback extends Message<SetLocalMetadataCallback>
1375
1375
  }
1376
1376
  }
1377
1377
 
1378
+ /**
1379
+ * @generated from message livekit.proto.SendChatMessageRequest
1380
+ */
1381
+ export class SendChatMessageRequest extends Message<SendChatMessageRequest> {
1382
+ /**
1383
+ * @generated from field: uint64 local_participant_handle = 1;
1384
+ */
1385
+ localParticipantHandle = protoInt64.zero;
1386
+
1387
+ /**
1388
+ * @generated from field: string message = 2;
1389
+ */
1390
+ message = "";
1391
+
1392
+ /**
1393
+ * @generated from field: repeated string destination_identities = 3;
1394
+ */
1395
+ destinationIdentities: string[] = [];
1396
+
1397
+ /**
1398
+ * @generated from field: optional string sender_identity = 4;
1399
+ */
1400
+ senderIdentity?: string;
1401
+
1402
+ constructor(data?: PartialMessage<SendChatMessageRequest>) {
1403
+ super();
1404
+ proto3.util.initPartial(data, this);
1405
+ }
1406
+
1407
+ static readonly runtime: typeof proto3 = proto3;
1408
+ static readonly typeName = "livekit.proto.SendChatMessageRequest";
1409
+ static readonly fields: FieldList = proto3.util.newFieldList(() => [
1410
+ { no: 1, name: "local_participant_handle", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
1411
+ { no: 2, name: "message", kind: "scalar", T: 9 /* ScalarType.STRING */ },
1412
+ { no: 3, name: "destination_identities", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
1413
+ { no: 4, name: "sender_identity", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
1414
+ ]);
1415
+
1416
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): SendChatMessageRequest {
1417
+ return new SendChatMessageRequest().fromBinary(bytes, options);
1418
+ }
1419
+
1420
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): SendChatMessageRequest {
1421
+ return new SendChatMessageRequest().fromJson(jsonValue, options);
1422
+ }
1423
+
1424
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): SendChatMessageRequest {
1425
+ return new SendChatMessageRequest().fromJsonString(jsonString, options);
1426
+ }
1427
+
1428
+ static equals(a: SendChatMessageRequest | PlainMessage<SendChatMessageRequest> | undefined, b: SendChatMessageRequest | PlainMessage<SendChatMessageRequest> | undefined): boolean {
1429
+ return proto3.util.equals(SendChatMessageRequest, a, b);
1430
+ }
1431
+ }
1432
+
1433
+ /**
1434
+ * @generated from message livekit.proto.EditChatMessageRequest
1435
+ */
1436
+ export class EditChatMessageRequest extends Message<EditChatMessageRequest> {
1437
+ /**
1438
+ * @generated from field: uint64 local_participant_handle = 1;
1439
+ */
1440
+ localParticipantHandle = protoInt64.zero;
1441
+
1442
+ /**
1443
+ * @generated from field: string edit_text = 2;
1444
+ */
1445
+ editText = "";
1446
+
1447
+ /**
1448
+ * @generated from field: livekit.proto.ChatMessage original_message = 3;
1449
+ */
1450
+ originalMessage?: ChatMessage;
1451
+
1452
+ /**
1453
+ * @generated from field: repeated string destination_identities = 4;
1454
+ */
1455
+ destinationIdentities: string[] = [];
1456
+
1457
+ /**
1458
+ * @generated from field: optional string sender_identity = 5;
1459
+ */
1460
+ senderIdentity?: string;
1461
+
1462
+ constructor(data?: PartialMessage<EditChatMessageRequest>) {
1463
+ super();
1464
+ proto3.util.initPartial(data, this);
1465
+ }
1466
+
1467
+ static readonly runtime: typeof proto3 = proto3;
1468
+ static readonly typeName = "livekit.proto.EditChatMessageRequest";
1469
+ static readonly fields: FieldList = proto3.util.newFieldList(() => [
1470
+ { no: 1, name: "local_participant_handle", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
1471
+ { no: 2, name: "edit_text", kind: "scalar", T: 9 /* ScalarType.STRING */ },
1472
+ { no: 3, name: "original_message", kind: "message", T: ChatMessage },
1473
+ { no: 4, name: "destination_identities", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true },
1474
+ { no: 5, name: "sender_identity", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
1475
+ ]);
1476
+
1477
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): EditChatMessageRequest {
1478
+ return new EditChatMessageRequest().fromBinary(bytes, options);
1479
+ }
1480
+
1481
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): EditChatMessageRequest {
1482
+ return new EditChatMessageRequest().fromJson(jsonValue, options);
1483
+ }
1484
+
1485
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): EditChatMessageRequest {
1486
+ return new EditChatMessageRequest().fromJsonString(jsonString, options);
1487
+ }
1488
+
1489
+ static equals(a: EditChatMessageRequest | PlainMessage<EditChatMessageRequest> | undefined, b: EditChatMessageRequest | PlainMessage<EditChatMessageRequest> | undefined): boolean {
1490
+ return proto3.util.equals(EditChatMessageRequest, a, b);
1491
+ }
1492
+ }
1493
+
1494
+ /**
1495
+ * @generated from message livekit.proto.SendChatMessageResponse
1496
+ */
1497
+ export class SendChatMessageResponse extends Message<SendChatMessageResponse> {
1498
+ /**
1499
+ * @generated from field: uint64 async_id = 1;
1500
+ */
1501
+ asyncId = protoInt64.zero;
1502
+
1503
+ constructor(data?: PartialMessage<SendChatMessageResponse>) {
1504
+ super();
1505
+ proto3.util.initPartial(data, this);
1506
+ }
1507
+
1508
+ static readonly runtime: typeof proto3 = proto3;
1509
+ static readonly typeName = "livekit.proto.SendChatMessageResponse";
1510
+ static readonly fields: FieldList = proto3.util.newFieldList(() => [
1511
+ { no: 1, name: "async_id", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
1512
+ ]);
1513
+
1514
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): SendChatMessageResponse {
1515
+ return new SendChatMessageResponse().fromBinary(bytes, options);
1516
+ }
1517
+
1518
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): SendChatMessageResponse {
1519
+ return new SendChatMessageResponse().fromJson(jsonValue, options);
1520
+ }
1521
+
1522
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): SendChatMessageResponse {
1523
+ return new SendChatMessageResponse().fromJsonString(jsonString, options);
1524
+ }
1525
+
1526
+ static equals(a: SendChatMessageResponse | PlainMessage<SendChatMessageResponse> | undefined, b: SendChatMessageResponse | PlainMessage<SendChatMessageResponse> | undefined): boolean {
1527
+ return proto3.util.equals(SendChatMessageResponse, a, b);
1528
+ }
1529
+ }
1530
+
1531
+ /**
1532
+ * @generated from message livekit.proto.SendChatMessageCallback
1533
+ */
1534
+ export class SendChatMessageCallback extends Message<SendChatMessageCallback> {
1535
+ /**
1536
+ * @generated from field: uint64 async_id = 1;
1537
+ */
1538
+ asyncId = protoInt64.zero;
1539
+
1540
+ /**
1541
+ * @generated from field: optional string error = 2;
1542
+ */
1543
+ error?: string;
1544
+
1545
+ /**
1546
+ * @generated from field: optional livekit.proto.ChatMessage chat_message = 3;
1547
+ */
1548
+ chatMessage?: ChatMessage;
1549
+
1550
+ constructor(data?: PartialMessage<SendChatMessageCallback>) {
1551
+ super();
1552
+ proto3.util.initPartial(data, this);
1553
+ }
1554
+
1555
+ static readonly runtime: typeof proto3 = proto3;
1556
+ static readonly typeName = "livekit.proto.SendChatMessageCallback";
1557
+ static readonly fields: FieldList = proto3.util.newFieldList(() => [
1558
+ { no: 1, name: "async_id", kind: "scalar", T: 4 /* ScalarType.UINT64 */ },
1559
+ { no: 2, name: "error", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
1560
+ { no: 3, name: "chat_message", kind: "message", T: ChatMessage, opt: true },
1561
+ ]);
1562
+
1563
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): SendChatMessageCallback {
1564
+ return new SendChatMessageCallback().fromBinary(bytes, options);
1565
+ }
1566
+
1567
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): SendChatMessageCallback {
1568
+ return new SendChatMessageCallback().fromJson(jsonValue, options);
1569
+ }
1570
+
1571
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): SendChatMessageCallback {
1572
+ return new SendChatMessageCallback().fromJsonString(jsonString, options);
1573
+ }
1574
+
1575
+ static equals(a: SendChatMessageCallback | PlainMessage<SendChatMessageCallback> | undefined, b: SendChatMessageCallback | PlainMessage<SendChatMessageCallback> | undefined): boolean {
1576
+ return proto3.util.equals(SendChatMessageCallback, a, b);
1577
+ }
1578
+ }
1579
+
1378
1580
  /**
1379
1581
  * Change the local participant's attributes
1380
1582
  *
@@ -2491,6 +2693,12 @@ export class RoomEvent extends Message<RoomEvent> {
2491
2693
  */
2492
2694
  value: TranscriptionReceived;
2493
2695
  case: "transcriptionReceived";
2696
+ } | {
2697
+ /**
2698
+ * @generated from field: livekit.proto.ChatMessageReceived chat_message = 29;
2699
+ */
2700
+ value: ChatMessageReceived;
2701
+ case: "chatMessage";
2494
2702
  } | { case: undefined; value?: undefined } = { case: undefined };
2495
2703
 
2496
2704
  constructor(data?: PartialMessage<RoomEvent>) {
@@ -2529,6 +2737,7 @@ export class RoomEvent extends Message<RoomEvent> {
2529
2737
  { no: 26, name: "eos", kind: "message", T: RoomEOS, oneof: "message" },
2530
2738
  { no: 27, name: "data_packet_received", kind: "message", T: DataPacketReceived, oneof: "message" },
2531
2739
  { no: 28, name: "transcription_received", kind: "message", T: TranscriptionReceived, oneof: "message" },
2740
+ { no: 29, name: "chat_message", kind: "message", T: ChatMessageReceived, oneof: "message" },
2532
2741
  ]);
2533
2742
 
2534
2743
  static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): RoomEvent {
@@ -3517,6 +3726,116 @@ export class UserPacket extends Message<UserPacket> {
3517
3726
  }
3518
3727
  }
3519
3728
 
3729
+ /**
3730
+ * @generated from message livekit.proto.ChatMessage
3731
+ */
3732
+ export class ChatMessage extends Message<ChatMessage> {
3733
+ /**
3734
+ * @generated from field: string id = 1;
3735
+ */
3736
+ id = "";
3737
+
3738
+ /**
3739
+ * @generated from field: int64 timestamp = 2;
3740
+ */
3741
+ timestamp = protoInt64.zero;
3742
+
3743
+ /**
3744
+ * @generated from field: string message = 3;
3745
+ */
3746
+ message = "";
3747
+
3748
+ /**
3749
+ * @generated from field: optional int64 edit_timestamp = 4;
3750
+ */
3751
+ editTimestamp?: bigint;
3752
+
3753
+ /**
3754
+ * @generated from field: optional bool deleted = 5;
3755
+ */
3756
+ deleted?: boolean;
3757
+
3758
+ /**
3759
+ * @generated from field: optional bool generated = 6;
3760
+ */
3761
+ generated?: boolean;
3762
+
3763
+ constructor(data?: PartialMessage<ChatMessage>) {
3764
+ super();
3765
+ proto3.util.initPartial(data, this);
3766
+ }
3767
+
3768
+ static readonly runtime: typeof proto3 = proto3;
3769
+ static readonly typeName = "livekit.proto.ChatMessage";
3770
+ static readonly fields: FieldList = proto3.util.newFieldList(() => [
3771
+ { no: 1, name: "id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
3772
+ { no: 2, name: "timestamp", kind: "scalar", T: 3 /* ScalarType.INT64 */ },
3773
+ { no: 3, name: "message", kind: "scalar", T: 9 /* ScalarType.STRING */ },
3774
+ { no: 4, name: "edit_timestamp", kind: "scalar", T: 3 /* ScalarType.INT64 */, opt: true },
3775
+ { no: 5, name: "deleted", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true },
3776
+ { no: 6, name: "generated", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true },
3777
+ ]);
3778
+
3779
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ChatMessage {
3780
+ return new ChatMessage().fromBinary(bytes, options);
3781
+ }
3782
+
3783
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ChatMessage {
3784
+ return new ChatMessage().fromJson(jsonValue, options);
3785
+ }
3786
+
3787
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ChatMessage {
3788
+ return new ChatMessage().fromJsonString(jsonString, options);
3789
+ }
3790
+
3791
+ static equals(a: ChatMessage | PlainMessage<ChatMessage> | undefined, b: ChatMessage | PlainMessage<ChatMessage> | undefined): boolean {
3792
+ return proto3.util.equals(ChatMessage, a, b);
3793
+ }
3794
+ }
3795
+
3796
+ /**
3797
+ * @generated from message livekit.proto.ChatMessageReceived
3798
+ */
3799
+ export class ChatMessageReceived extends Message<ChatMessageReceived> {
3800
+ /**
3801
+ * @generated from field: livekit.proto.ChatMessage message = 1;
3802
+ */
3803
+ message?: ChatMessage;
3804
+
3805
+ /**
3806
+ * @generated from field: string participant_identity = 2;
3807
+ */
3808
+ participantIdentity = "";
3809
+
3810
+ constructor(data?: PartialMessage<ChatMessageReceived>) {
3811
+ super();
3812
+ proto3.util.initPartial(data, this);
3813
+ }
3814
+
3815
+ static readonly runtime: typeof proto3 = proto3;
3816
+ static readonly typeName = "livekit.proto.ChatMessageReceived";
3817
+ static readonly fields: FieldList = proto3.util.newFieldList(() => [
3818
+ { no: 1, name: "message", kind: "message", T: ChatMessage },
3819
+ { no: 2, name: "participant_identity", kind: "scalar", T: 9 /* ScalarType.STRING */ },
3820
+ ]);
3821
+
3822
+ static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): ChatMessageReceived {
3823
+ return new ChatMessageReceived().fromBinary(bytes, options);
3824
+ }
3825
+
3826
+ static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): ChatMessageReceived {
3827
+ return new ChatMessageReceived().fromJson(jsonValue, options);
3828
+ }
3829
+
3830
+ static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): ChatMessageReceived {
3831
+ return new ChatMessageReceived().fromJsonString(jsonString, options);
3832
+ }
3833
+
3834
+ static equals(a: ChatMessageReceived | PlainMessage<ChatMessageReceived> | undefined, b: ChatMessageReceived | PlainMessage<ChatMessageReceived> | undefined): boolean {
3835
+ return proto3.util.equals(ChatMessageReceived, a, b);
3836
+ }
3837
+ }
3838
+
3520
3839
  /**
3521
3840
  * @generated from message livekit.proto.SipDTMF
3522
3841
  */
package/src/room.ts CHANGED
@@ -32,6 +32,7 @@ import type { LocalTrack, RemoteTrack } from './track.js';
32
32
  import { RemoteAudioTrack, RemoteVideoTrack } from './track.js';
33
33
  import type { LocalTrackPublication, TrackPublication } from './track_publication.js';
34
34
  import { RemoteTrackPublication } from './track_publication.js';
35
+ import type { ChatMessage } from './types.js';
35
36
 
36
37
  export interface RtcConfiguration {
37
38
  iceTransportType: IceTransportType;
@@ -262,6 +263,17 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
262
263
  } else if (ev.case == 'connectionQualityChanged') {
263
264
  const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity);
264
265
  this.emit(RoomEvent.ConnectionQualityChanged, ev.value.quality, participant);
266
+ } else if (ev.case == 'chatMessage') {
267
+ const participant = this.retrieveParticipantByIdentity(ev.value.participantIdentity);
268
+ const { id, message: messageText, timestamp, editTimestamp, generated } = ev.value.message;
269
+ const message: ChatMessage = {
270
+ id,
271
+ message: messageText,
272
+ timestamp: Number(timestamp),
273
+ editTimestamp: Number(editTimestamp),
274
+ generated,
275
+ };
276
+ this.emit(RoomEvent.ChatMessage, message, participant);
265
277
  } else if (ev.case == 'dataPacketReceived') {
266
278
  // Can be undefined if the data is sent from a Server SDK
267
279
  const participant = this.remoteParticipants.get(ev.value.participantIdentity);
@@ -285,7 +297,6 @@ export class Room extends (EventEmitter as new () => TypedEmitter<RoomCallbacks>
285
297
  const { code, digit } = dataPacket.value;
286
298
  this.emit(RoomEvent.DtmfReceived, code, digit, participant);
287
299
  break;
288
-
289
300
  default:
290
301
  break;
291
302
  }
@@ -376,6 +387,7 @@ export type RoomCallbacks = {
376
387
  kind?: DataPacketKind,
377
388
  topic?: string,
378
389
  ) => void;
390
+ chatMessage: (message: ChatMessage, participant?: Participant) => void;
379
391
  dtmfReceived: (code: number, digit: string, participant: RemoteParticipant) => void;
380
392
  encryptionError: (error: Error) => void;
381
393
  connectionStateChanged: (state: ConnectionState) => void;
@@ -405,6 +417,7 @@ export enum RoomEvent {
405
417
  ParticipantAttributesChanged = 'participantAttributesChanged',
406
418
  ConnectionQualityChanged = 'connectionQualityChanged',
407
419
  DataReceived = 'dataReceived',
420
+ ChatMessage = 'chatMessage',
408
421
  DtmfReceived = 'dtmfReceived',
409
422
  EncryptionError = 'encryptionError',
410
423
  ConnectionStateChanged = 'connectionStateChanged',
package/src/types.ts ADDED
@@ -0,0 +1,10 @@
1
+ // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ export interface ChatMessage {
5
+ id: string;
6
+ timestamp: number;
7
+ message: string;
8
+ editTimestamp?: number;
9
+ generated?: boolean;
10
+ }