@livekit/rtc-node 0.10.1 → 0.10.3

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/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
+ }