Skip to content

Commit 7aa9127

Browse files
authored
show deprecation warning (#226)
## Description Describe your changes. ## 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. ## Documentation impact - [ ] Documentation update required - [ ] Documentation updated [in another PR](_) - [x] No documentation update required ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [x] 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 36709af commit 7aa9127

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from 'axios';
1+
import axios, { RawAxiosResponseHeaders } from 'axios';
22
import {
33
RoomApi,
44
ViewerApi,
@@ -23,6 +23,7 @@ export class FishjamClient {
2323
private readonly viewerApi: ViewerApi;
2424
private readonly streamerApi: StreamerApi;
2525
private readonly fishjamConfig: FishjamConfig;
26+
private deprecationWarningShown: boolean = false;
2627

2728
/**
2829
* Create new instance of Fishjam Client.
@@ -43,6 +44,11 @@ export class FishjamClient {
4344
},
4445
});
4546

47+
client.interceptors.response.use((response) => {
48+
this.handleDeprecationHeader(response.headers);
49+
return response;
50+
});
51+
4652
const fishjamUrl = getFishjamUrl(config);
4753

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

60+
private handleDeprecationHeader(headers: RawAxiosResponseHeaders): void {
61+
try {
62+
const deprecationHeader = headers['x-fishjam-api-deprecated'];
63+
if (!deprecationHeader || this.deprecationWarningShown) return;
64+
const deprecationStatus = JSON.parse(deprecationHeader as string);
65+
66+
if (deprecationStatus.status === 'unsupported') {
67+
console.error(deprecationStatus.message);
68+
} else if (deprecationStatus.status === 'deprecated') {
69+
console.warn(deprecationStatus.message);
70+
}
71+
this.deprecationWarningShown = true;
72+
} catch {
73+
// ignore parsing errors
74+
}
75+
}
76+
5477
/**
5578
* Create a new room. All peers connected to the same room will be able to send/receive streams to each other.
5679
*/

0 commit comments

Comments
 (0)