Skip to content

Commit f22ceba

Browse files
fixup
1 parent 57e9a6c commit f22ceba

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

src/client.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
SERVER_REQUEST,
1919
WS_CLOSE_CODE
2020
} from "#src/shared/enums.ts";
21-
import type { JSONSerializable, StreamType, BusMessage } from "#src/shared/types";
21+
import type { JSONSerializable, StreamType, BusMessage, AvailableFeatures } from "#src/shared/types";
2222
import type { TransportConfig, SessionId, SessionInfo } from "#src/models/session";
2323

2424
interface Consumers {
@@ -141,6 +141,10 @@ const ACTIVE_STATES = new Set<SfuClientState>([
141141
export class SfuClient extends EventTarget {
142142
/** Connection errors encountered */
143143
public errors: Error[] = [];
144+
public availableFeatures: AvailableFeatures = {
145+
"rtc": false,
146+
"recording": false,
147+
};
144148
/** Current client state */
145149
private _state: SfuClientState = SfuClientState.DISCONNECTED;
146150
/** Communication bus */
@@ -445,7 +449,8 @@ export class SfuClient extends EventTarget {
445449
*/
446450
webSocket.addEventListener(
447451
"message",
448-
() => {
452+
(message) => {
453+
this.availableFeatures = JSON.parse(message.data) as AvailableFeatures;
449454
resolve(new Bus(webSocket));
450455
},
451456
{ once: true }

src/models/channel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ export class Channel extends EventEmitter {
8585
public readonly key?: Buffer;
8686
/** mediasoup Router for media routing */
8787
public readonly router?: Router;
88+
/** Manages the recording of this channel, undefined if the feature is disabled */
89+
public readonly recorder?: Recorder;
8890
/** Active sessions in this channel */
8991
public readonly sessions = new Map<SessionId, Session>();
9092
/** mediasoup Worker handling this channel */
9193
private readonly _worker?: RtcWorker;
92-
/** Manages the recording of this channel, undefined if the feature is disabled */
93-
private recorder?: Recorder;
9494
/** Timeout for auto-closing empty channels */
9595
private _closeTimeout?: NodeJS.Timeout;
9696

src/models/session.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
SERVER_REQUEST,
2121
STREAM_TYPE
2222
} from "#src/shared/enums.ts";
23-
import type { JSONSerializable, StreamType, BusMessage } from "#src/shared/types";
23+
import type {JSONSerializable, StreamType, BusMessage, AvailableFeatures } from "#src/shared/types";
2424
import type { Bus } from "#src/shared/bus.ts";
2525
import type { Channel } from "#src/models/channel.ts";
2626

@@ -167,6 +167,13 @@ export class Session extends EventEmitter {
167167
this.setMaxListeners(config.CHANNEL_SIZE * 2);
168168
}
169169

170+
get availableFeatures(): AvailableFeatures {
171+
return {
172+
"rtc": Boolean(this._channel.router),
173+
"recording": Boolean(this._channel.router && this._channel.recorder && this.permissions.recording)
174+
}
175+
}
176+
170177
get name(): string {
171178
return `${this._channel.name}:${this.id}@${this.remote}`;
172179
}

src/services/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface PrivateJWTClaims {
4343
sfu_channel_uuid?: string;
4444
session_id?: SessionId;
4545
ice_servers?: object[];
46-
permissions: SessionPermissions,
46+
permissions?: SessionPermissions,
4747
sessionIdsByChannel?: Record<string, SessionId[]>;
4848
/** If provided when requesting a channel, this key will be used instead of the global key to verify JWTs related to this channel */
4949
key?: string;

src/services/ws.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ function connect(webSocket: WebSocket, credentials: Credentials): Session {
128128
if (!session_id) {
129129
throw new AuthenticationError("Malformed JWT payload");
130130
}
131-
webSocket.send(""); // client can start using ws after this message.
132131
const bus = new Bus(webSocket, { batchDelay: config.timeouts.busBatch });
133132
const { session } = Channel.join(channel.uuid, session_id);
134-
session.permissions = permissions;
133+
if (permissions) {
134+
Object.assign(session.permissions, permissions);
135+
}
136+
webSocket.send(JSON.stringify(session.availableFeatures)); // client can start using ws after this message.
135137
session.once("close", ({ code }: { code: string }) => {
136138
let wsCloseCode = WS_CLOSE_CODE.CLEAN;
137139
switch (code) {

src/shared/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export type StreamType = "audio" | "camera" | "screen";
1010

1111
export type StringLike = Buffer | string;
1212

13+
export type AvailableFeatures = {
14+
"rtc": boolean,
15+
"recording": boolean,
16+
}
17+
1318
import type { DownloadStates } from "#src/client.ts";
1419
import type { SessionId, SessionInfo, TransportConfig } from "#src/models/session.ts";
1520

0 commit comments

Comments
 (0)