Skip to content

Commit 77f6a82

Browse files
Add tokenless livestreams (#165)
## Description Describe your changes in detail. ## Motivation and Context Why is this change required? What problem does it solve? If it fixes an open issue, please link to the issue here. ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
1 parent 4cf4492 commit 77f6a82

9 files changed

Lines changed: 45 additions & 17 deletions

File tree

examples/room-manager/openapi.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ paths:
3636
in: query
3737
name: roomType
3838
required: false
39+
- schema:
40+
type: boolean
41+
default: false
42+
in: query
43+
name: public
44+
required: false
3945
responses:
4046
"200":
4147
description: Default Response

examples/room-manager/src/plugins/fishjam.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
FishjamClient,
55
PeerId,
66
Room,
7+
RoomConfig,
78
RoomConfigRoomTypeEnum,
89
RoomId,
910
RoomNotFoundException,
@@ -17,7 +18,12 @@ import { PeerAccessData } from '../schema';
1718
declare module 'fastify' {
1819
interface FastifyInstance {
1920
fishjam: {
20-
getPeerAccess: (roomName: string, peerName: string, roomType?: RoomConfigRoomTypeEnum) => Promise<PeerAccessData>;
21+
getPeerAccess: (
22+
roomName: string,
23+
peerName: string,
24+
roomType?: RoomConfigRoomTypeEnum,
25+
isPublic?: boolean
26+
) => Promise<PeerAccessData>;
2127
handleFishjamMessage: (notification: ServerMessage) => Promise<void>;
2228
getLivestreamViewerToken: (roomName: string) => Promise<ViewerToken>;
2329
};
@@ -40,9 +46,16 @@ export const fishjamPlugin = fastifyPlugin(async (fastify: FastifyInstance): Pro
4046
async function getPeerAccess(
4147
roomName: string,
4248
peerName: string,
43-
roomType: RoomConfigRoomTypeEnum = 'conference'
49+
roomType: RoomConfigRoomTypeEnum = 'conference',
50+
isPublic: boolean = false
4451
): Promise<PeerAccessData> {
45-
const room = await findOrCreateRoomInFishjam(roomName, roomType);
52+
const config: RoomConfig = {
53+
maxPeers: fastify.config.MAX_PEERS,
54+
videoCodec: fastify.config.ROOM_VIDEO_CODEC as RoomConfigVideoCodecEnum,
55+
roomType,
56+
public: isPublic,
57+
};
58+
const room = await findOrCreateRoomInFishjam(roomName, config);
4659
const peerAccess = peerNameToAccessMap.get(peerName);
4760

4861
const peer = room.peers.find((peer) => peer.id === peerAccess?.peer.id);
@@ -138,7 +151,7 @@ export const fishjamPlugin = fastifyPlugin(async (fastify: FastifyInstance): Pro
138151
return peerAccess;
139152
}
140153

141-
async function findOrCreateRoomInFishjam(roomName: string, roomType: RoomConfigRoomTypeEnum): Promise<Room> {
154+
async function findOrCreateRoomInFishjam(roomName: string, roomConfig: RoomConfig): Promise<Room> {
142155
const roomId = roomNameToRoomIdMap.get(roomName);
143156

144157
if (roomId) {
@@ -158,14 +171,10 @@ export const fishjamPlugin = fastifyPlugin(async (fastify: FastifyInstance): Pro
158171
name: 'Creating room in Fishjam',
159172
roomId,
160173
roomName,
161-
roomType,
174+
...roomConfig,
162175
});
163176

164-
const newRoom = await fishjamClient.createRoom({
165-
maxPeers: fastify.config.MAX_PEERS,
166-
videoCodec: fastify.config.ROOM_VIDEO_CODEC as RoomConfigVideoCodecEnum,
167-
roomType,
168-
});
177+
const newRoom = await fishjamClient.createRoom(roomConfig);
169178

170179
roomNameToRoomIdMap.set(roomName, newRoom.id);
171180

examples/room-manager/src/routes/rooms.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { httpToWebsocket, removeTrailingSlash } from '../utils';
77

88
async function getRoomAccessHandler(fastify: FastifyInstance, params: GetPeerAccessQueryParams, res: FastifyReply) {
99
try {
10-
const accessData = await fastify.fishjam.getPeerAccess(params.roomName, params.peerName, params.roomType);
10+
const accessData = await fastify.fishjam.getPeerAccess(
11+
params.roomName,
12+
params.peerName,
13+
params.roomType,
14+
params.public
15+
);
1116
const url = httpToWebsocket(fastify.config.FISHJAM_URL);
1217

1318
// When creating a URL object from a URL without a path (e.g., `http://localhost:5002`),

examples/room-manager/src/schema.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface GetPeerAccessQueryParams {
1313
roomName: string;
1414
peerName: string;
1515
roomType: RoomConfigRoomTypeEnum;
16+
public: boolean;
1617
}
1718

1819
export interface PeerAccessData {
@@ -42,7 +43,8 @@ const parameterSchema = S.object()
4243
S.string()
4344
.enum(['conference', 'audio_only', 'livestream'] satisfies RoomConfigRoomTypeEnum[])
4445
.default('conference')
45-
);
46+
)
47+
.prop('public', S.boolean().default(false));
4648

4749
export const peerEndpointSchema: FastifySchema = {
4850
querystring: parameterSchema,

packages/fishjam-openapi/src/generated/api.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Fishjam Media Server
55
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
66
*
7-
* The version of the OpenAPI document: 0.17.0
7+
* The version of the OpenAPI document: 0.18.0
88
*
99
*
1010
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
@@ -871,6 +871,12 @@ export interface RoomConfig {
871871
* @memberof RoomConfig
872872
*/
873873
'maxPeers'?: number | null;
874+
/**
875+
* True if livestream viewers can omit specifying a token.
876+
* @type {boolean}
877+
* @memberof RoomConfig
878+
*/
879+
'public'?: boolean;
874880
/**
875881
* The use-case of the room. If not provided, this defaults to conference.
876882
* @type {string}

packages/fishjam-openapi/src/generated/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Fishjam Media Server
55
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
66
*
7-
* The version of the OpenAPI document: 0.17.0
7+
* The version of the OpenAPI document: 0.18.0
88
*
99
*
1010
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).

packages/fishjam-openapi/src/generated/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Fishjam Media Server
55
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
66
*
7-
* The version of the OpenAPI document: 0.17.0
7+
* The version of the OpenAPI document: 0.18.0
88
*
99
*
1010
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).

packages/fishjam-openapi/src/generated/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Fishjam Media Server
55
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
66
*
7-
* The version of the OpenAPI document: 0.17.0
7+
* The version of the OpenAPI document: 0.18.0
88
*
99
*
1010
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).

packages/fishjam-openapi/src/generated/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Fishjam Media Server
55
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
66
*
7-
* The version of the OpenAPI document: 0.17.0
7+
* The version of the OpenAPI document: 0.18.0
88
*
99
*
1010
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).

0 commit comments

Comments
 (0)