Skip to content

Commit 10c920d

Browse files
authored
Revert "Revert "FCE-1780 / accept fishjam id to configure the sdk"" (#176)
Reverts #175 Now, that the deploy workflow is disabled, we can safely merge the code.
1 parent 287049a commit 10c920d

12 files changed

Lines changed: 57 additions & 29 deletions

File tree

.github/workflows/static.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: yarn typecheck
4141

4242
- name: Generate OpenAPI reference 📸
43-
run: yarn gen:openapi ref.yaml
43+
run: FISHJAM_ID="openapi" yarn gen:openapi ref.yaml
4444

4545
- name: Compare OpenAPI reference 🔦
4646
run: |

examples/room-manager/openapi.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ paths:
5252
properties:
5353
peerToken:
5454
type: string
55-
url:
56-
type: string
5755
room:
5856
type: object
5957
properties:
@@ -70,7 +68,6 @@ paths:
7068
type: string
7169
required:
7270
- peerToken
73-
- url
7471
"401":
7572
description: Default Response
7673
content:

examples/room-manager/src/config.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ declare module 'fastify' {
44
PORT: number;
55
ENABLE_SIMULCAST: boolean;
66
MAX_PEERS?: number;
7-
FISHJAM_URL: string;
7+
FISHJAM_ID?: string;
8+
FISHJAM_URL?: string;
89
FISHJAM_SERVER_TOKEN?: string;
910
// TODO[FCE-1283] make this param required
1011
FISHJAM_MANAGEMENT_TOKEN?: string;
@@ -16,7 +17,7 @@ declare module 'fastify' {
1617
export const configSchema = {
1718
type: 'object',
1819
// TODO[FCE-1283] uncomment FISHJAM_MANAGEMENT_TOKEN
19-
required: ['PORT', 'ENABLE_SIMULCAST', 'FISHJAM_URL' /*'FISHJAM_MANAGEMENT_TOKEN'*/],
20+
required: ['PORT', 'ENABLE_SIMULCAST' /*'FISHJAM_MANAGEMENT_TOKEN'*/],
2021
properties: {
2122
PORT: {
2223
type: 'string',
@@ -30,9 +31,13 @@ export const configSchema = {
3031
type: 'number',
3132
default: undefined,
3233
},
34+
FISHJAM_ID: {
35+
type: 'string',
36+
default: undefined,
37+
},
3338
FISHJAM_URL: {
3439
type: 'string',
35-
default: 'http://localhost:5002',
40+
default: undefined,
3641
},
3742
FISHJAM_SERVER_TOKEN: {
3843
type: 'string',

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const fishjamPlugin = fastifyPlugin(async (fastify: FastifyInstance): Pro
3737
}
3838

3939
const fishjamClient = new FishjamClient({
40+
fishjamId: fastify.config.FISHJAM_ID,
4041
fishjamUrl: fastify.config.FISHJAM_URL,
4142
managementToken: fastify.config.FISHJAM_MANAGEMENT_TOKEN ?? fastify.config.FISHJAM_SERVER_TOKEN ?? 'development',
4243
});

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
streamEndpointSchema,
1010
viewerEndpointSchema,
1111
} from '../schema';
12-
import { httpToWebsocket, removeTrailingSlash } from '../utils';
1312

1413
async function getRoomAccessHandler(fastify: FastifyInstance, params: GetPeerAccessQueryParams, res: FastifyReply) {
1514
try {
@@ -19,13 +18,8 @@ async function getRoomAccessHandler(fastify: FastifyInstance, params: GetPeerAcc
1918
params.roomType,
2019
params.public
2120
);
22-
const url = httpToWebsocket(fastify.config.FISHJAM_URL);
2321

24-
// When creating a URL object from a URL without a path (e.g., `http://localhost:5002`),
25-
// the `href` field may contain an additional '/' at the end (`http://localhost:5002/`).
26-
const urlWithoutTrailingSlash = removeTrailingSlash(url);
27-
28-
return { ...accessData, url: urlWithoutTrailingSlash };
22+
return accessData;
2923
} catch (error: unknown) {
3024
const [parsedError, errorCode] = parseError(error);
3125

examples/room-manager/src/schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export interface LivestreamData {
3434

3535
const response200 = S.object()
3636
.prop('peerToken', S.string().required())
37-
.prop('url', S.string().required())
3837
.prop('room', S.object().prop('id', S.string()).prop('name', S.string()))
3938
.prop('peer', S.object().prop('id', S.string()).prop('name', S.string()));
4039

packages/js-server-sdk/src/client.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios from 'axios';
22
import { RoomApi, PeerOptions, ViewerApi, RoomConfig, StreamerApi } from '@fishjam-cloud/fishjam-openapi';
33
import { FishjamConfig, PeerId, Room, RoomId, Peer } from './types';
44
import { mapException } from './exceptions/mapper';
5+
import { getFishjamUrl } from './utils';
56

67
/**
78
* Client class that allows to manage Rooms and Peers for a Fishjam App.
@@ -31,9 +32,11 @@ export class FishjamClient {
3132
},
3233
});
3334

34-
this.roomApi = new RoomApi(undefined, config.fishjamUrl, client);
35-
this.viewerApi = new ViewerApi(undefined, config.fishjamUrl, client);
36-
this.streamerApi = new StreamerApi(undefined, config.fishjamUrl, client);
35+
const fishjamUrl = getFishjamUrl(config);
36+
37+
this.roomApi = new RoomApi(undefined, fishjamUrl, client);
38+
this.viewerApi = new ViewerApi(undefined, fishjamUrl, client);
39+
this.streamerApi = new StreamerApi(undefined, fishjamUrl, client);
3740
}
3841

3942
/**

packages/js-server-sdk/src/exceptions/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import axios from 'axios';
22

3+
export class MissingFishjamIdException extends Error {
4+
constructor() {
5+
super('Fishjam ID is required');
6+
}
7+
}
8+
39
export class FishjamBaseException extends Error {
410
statusCode: number;
511
axiosCode?: string;

packages/js-server-sdk/src/types.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ export type Room = {
2626
};
2727

2828
export type FishjamConfig = {
29-
fishjamUrl: string;
29+
/*
30+
* Fishjam ID is a unique identifier for your account and environment.
31+
* Visit https://fishjam.io/app/ to get your Fishjam ID.
32+
*/
33+
fishjamId?: string;
34+
/*
35+
* @deprecated
36+
*/
37+
fishjamUrl?: string;
38+
/*
39+
* Management token is a secret token authorizing to perform actions on your account.
40+
* Never share this token with anyone.
41+
* Visit https://fishjam.io/app/ to get your Management Token.
42+
*/
3043
managementToken: string;
3144
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { MissingFishjamIdException } from './exceptions';
2+
import type { FishjamConfig } from './types';
3+
4+
export const httpToWebsocket = (httpUrl: string) => {
5+
const url = new URL(httpUrl);
6+
7+
// note that this will handle http as well as https
8+
url.protocol = url.protocol.replace('http', 'ws');
9+
return url.href;
10+
};
11+
12+
export const getFishjamUrl = (config: FishjamConfig) => {
13+
if (!config.fishjamId && !config.fishjamUrl) throw new MissingFishjamIdException();
14+
15+
return config.fishjamUrl ?? `https://fishjam.io/api/v1/connect/${config.fishjamId}`;
16+
};

0 commit comments

Comments
 (0)