Skip to content

Commit

Permalink
Add support for ParticipantKind (#1150)
Browse files Browse the repository at this point in the history
* Add support for ParticipantKind

* Create fifty-suns-sort.md

* export ParticipantKind enum
  • Loading branch information
lukasIO authored May 31, 2024
1 parent a8a2aed commit a28b2c5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-suns-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Add support for ParticipantKind
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LogLevel, LoggerNames, getLogger, setLogExtension, setLogLevel } from '
import DefaultReconnectPolicy from './room/DefaultReconnectPolicy';
import Room, { ConnectionState } from './room/Room';
import LocalParticipant from './room/participant/LocalParticipant';
import Participant, { ConnectionQuality } from './room/participant/Participant';
import Participant, { ConnectionQuality, ParticipantKind } from './room/participant/Participant';
import type { ParticipantTrackPermission } from './room/participant/ParticipantTrackPermission';
import RemoteParticipant from './room/participant/RemoteParticipant';
import CriticalTimers from './room/timers';
Expand Down Expand Up @@ -63,6 +63,7 @@ export {
Participant,
RemoteAudioTrack,
RemoteParticipant,
ParticipantKind,
RemoteTrack,
RemoteTrackPublication,
RemoteVideoTrack,
Expand Down
5 changes: 4 additions & 1 deletion src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,10 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
private createParticipant(identity: string, info?: ParticipantInfo): RemoteParticipant {
let participant: RemoteParticipant;
if (info) {
participant = RemoteParticipant.fromParticipantInfo(this.engine.client, info);
participant = RemoteParticipant.fromParticipantInfo(this.engine.client, info, {
loggerContextCb: () => this.logContext,
loggerName: this.options.loggerName,
});
} else {
participant = new RemoteParticipant(this.engine.client, '', identity, undefined, undefined, {
loggerContextCb: () => this.logContext,
Expand Down
13 changes: 12 additions & 1 deletion src/room/participant/Participant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DataPacket_Kind,
ParticipantInfo,
ParticipantInfo_Kind as ParticipantKind,
ParticipantPermission,
ConnectionQuality as ProtoQuality,
type SipDTMF,
Expand Down Expand Up @@ -46,6 +47,8 @@ function qualityFromProto(q: ProtoQuality): ConnectionQuality {
}
}

export { ParticipantKind };

export default class Participant extends (EventEmitter as new () => TypedEmitter<ParticipantEventCallbacks>) {
protected participantInfo?: ParticipantInfo;

Expand Down Expand Up @@ -78,6 +81,8 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter

permissions?: ParticipantPermission;

protected _kind: ParticipantKind;

private _connectionQuality: ConnectionQuality = ConnectionQuality.Unknown;

protected audioContext?: AudioContext;
Expand All @@ -100,7 +105,11 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter
}

get isAgent() {
return this.permissions?.agent ?? false;
return this.permissions?.agent || this.kind === ParticipantKind.AGENT;
}

get kind() {
return this._kind;
}

/** @internal */
Expand All @@ -110,6 +119,7 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter
name?: string,
metadata?: string,
loggerOptions?: LoggerOptions,
kind: ParticipantKind = ParticipantKind.STANDARD,
) {
super();

Expand All @@ -124,6 +134,7 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter
this.audioTrackPublications = new Map();
this.videoTrackPublications = new Map();
this.trackPublications = new Map();
this._kind = kind;
}

getTrackPublications(): TrackPublication[] {
Expand Down
21 changes: 17 additions & 4 deletions src/room/participant/RemoteParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { AudioOutputOptions } from '../track/options';
import type { AdaptiveStreamSettings } from '../track/types';
import { getLogContextFromTrack } from '../track/utils';
import type { LoggerOptions } from '../types';
import Participant from './Participant';
import Participant, { ParticipantKind } from './Participant';
import type { ParticipantEventCallbacks } from './Participant';

export default class RemoteParticipant extends Participant {
Expand All @@ -33,8 +33,20 @@ export default class RemoteParticipant extends Participant {
private audioOutput?: AudioOutputOptions;

/** @internal */
static fromParticipantInfo(signalClient: SignalClient, pi: ParticipantInfo): RemoteParticipant {
return new RemoteParticipant(signalClient, pi.sid, pi.identity, pi.name, pi.metadata);
static fromParticipantInfo(
signalClient: SignalClient,
pi: ParticipantInfo,
loggerOptions: LoggerOptions,
): RemoteParticipant {
return new RemoteParticipant(
signalClient,
pi.sid,
pi.identity,
pi.name,
pi.metadata,
loggerOptions,
pi.kind,
);
}

protected get logContext() {
Expand All @@ -53,8 +65,9 @@ export default class RemoteParticipant extends Participant {
name?: string,
metadata?: string,
loggerOptions?: LoggerOptions,
kind: ParticipantKind = ParticipantKind.STANDARD,
) {
super(sid, identity || '', name, metadata, loggerOptions);
super(sid, identity || '', name, metadata, loggerOptions, kind);
this.signalClient = signalClient;
this.trackPublications = new Map();
this.audioTrackPublications = new Map();
Expand Down

0 comments on commit a28b2c5

Please sign in to comment.