Skip to content

Commit

Permalink
fix: support https proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed May 16, 2024
1 parent 87c5b8e commit ca28beb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
23 changes: 14 additions & 9 deletions packages/hms-video-store/src/analytics/HTTPAnalyticsTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CLIENT_ANAYLTICS_QA_ENDPOINT,
CLIENT_ANAYLTICS_STORAGE_LIMIT,
} from '../utils/constants';
import { getEndpointFromProxy } from '../utils/get-endpoint-from-proxy';
import { LocalStorage } from '../utils/local-storage';
import HMSLogger from '../utils/logger';
import { ENV } from '../utils/support';
Expand Down Expand Up @@ -49,8 +50,6 @@ class ClientAnalyticsTransport implements IAnalyticsTransportProvider {

setWebsocketEndpoint(ws: string, proxy?: HMSProxyConfig) {
this.proxy = proxy;
console.log(this.proxy);
// proxy - ws
this.websocketURL = ws;
}

Expand All @@ -71,14 +70,20 @@ class ClientAnalyticsTransport implements IAnalyticsTransportProvider {
},
};
const url = this.env === ENV.PROD ? CLIENT_ANAYLTICS_PROD_ENDPOINT : CLIENT_ANAYLTICS_QA_ENDPOINT;
// proxy - analytics
fetch(url, {

const proxyUrl = getEndpointFromProxy(this.proxy);
const headers = {
'Content-Type': 'application/json',
Authorization: `Bearer ${event.metadata.token}`,
user_agent_v2: event.metadata.userAgent,
'Target-URL': url,
};
if (proxyUrl) {
headers['Target-URL'] = url;
}
fetch(proxyUrl || url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${event.metadata.token}`,
user_agent_v2: event.metadata.userAgent,
},
headers,
body: JSON.stringify(requestBody),
})
.then(response => {
Expand Down
2 changes: 1 addition & 1 deletion packages/hms-video-store/src/interfaces/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type HMSICEServer = {
};

enum HMSProxyType {
Socks5 = 0,
HTTPS = 0,
}

export type HMSProxyConfig = {
Expand Down
14 changes: 8 additions & 6 deletions packages/hms-video-store/src/signal/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { InitConfig } from './models';
import { ErrorFactory } from '../../error/ErrorFactory';
import { HMSAction } from '../../error/HMSAction';
import { HMSICEServer, HMSProxyConfig } from '../../interfaces';
import { getEndpointFromProxy } from '../../utils/get-endpoint-from-proxy';
import { transformIceServerConfig } from '../../utils/ice-server-config';
import HMSLogger from '../../utils/logger';

Expand Down Expand Up @@ -42,12 +43,13 @@ export default class InitService {
HMSLogger.d(TAG, `fetchInitConfig: initEndpoint=${initEndpoint} token=${token} peerId=${peerId} region=${region} `);
const url = getUrl(initEndpoint, peerId, userAgent, region);
try {
// proxy - init
console.log(proxy);
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
},
const proxyUrl = getEndpointFromProxy(proxy);
const headers: Record<string, string> = { Authorization: `Bearer ${token}` };
if (proxyUrl) {
headers['Target-URL'] = url;
}
const response = await fetch(proxyUrl || url, {
headers,
});
try {
const config = await response.clone().json();
Expand Down
4 changes: 2 additions & 2 deletions packages/hms-video-store/src/utils/get-endpoint-from-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export const getEndpointFromProxy = (proxy?: HMSProxyConfig) => {
let endpoint = `://${proxy.host}:${proxy.port}`;
switch (proxy.type) {
case 0:
endpoint = `socks5${endpoint}`;
endpoint = `https${endpoint}`;
break;
default:
endpoint = `socks5${endpoint}`;
endpoint = `https${endpoint}`;
}
return endpoint;
};

0 comments on commit ca28beb

Please sign in to comment.