Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion packages/js-server-sdk/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios from 'axios';
import axios, { RawAxiosResponseHeaders } from 'axios';
import {
RoomApi,
ViewerApi,
Expand All @@ -23,6 +23,7 @@ export class FishjamClient {
private readonly viewerApi: ViewerApi;
private readonly streamerApi: StreamerApi;
private readonly fishjamConfig: FishjamConfig;
private deprecationWarningShown: boolean = false;

/**
* Create new instance of Fishjam Client.
Expand All @@ -43,6 +44,11 @@ export class FishjamClient {
},
});

client.interceptors.response.use((response) => {
this.handleDeprecationHeader(response.headers);
return response;
});

const fishjamUrl = getFishjamUrl(config);

this.roomApi = new RoomApi(undefined, fishjamUrl, client);
Expand All @@ -51,6 +57,23 @@ export class FishjamClient {
this.fishjamConfig = config;
}

private handleDeprecationHeader(headers: RawAxiosResponseHeaders): void {
try {
const deprecationHeader = headers['x-fishjam-api-deprecated'];
if (!deprecationHeader || this.deprecationWarningShown) return;
const deprecationStatus = JSON.parse(deprecationHeader as string);

if (deprecationStatus.status === 'unsupported') {
console.error(deprecationStatus.message);
} else if (deprecationStatus.status === 'deprecated') {
console.warn(deprecationStatus.message);
}
this.deprecationWarningShown = true;
} catch {
// ignore parsing errors
}
}

/**
* Create a new room. All peers connected to the same room will be able to send/receive streams to each other.
*/
Expand Down