diff --git a/__tests__/create-test-client.ts b/__tests__/create-test-client.ts index 0705084..43577b0 100644 --- a/__tests__/create-test-client.ts +++ b/__tests__/create-test-client.ts @@ -5,5 +5,5 @@ const apiKey = process.env.STREAM_API_KEY!; const secret = process.env.STREAM_SECRET!; export const createTestClient = () => { - return new StreamClient(apiKey, secret, undefined, { timeout: 7500 }); + return new StreamClient(apiKey, secret, { timeout: 7500 }); }; diff --git a/src/StreamCall.ts b/src/StreamCall.ts index 0e4fa70..dd258b3 100644 --- a/src/StreamCall.ts +++ b/src/StreamCall.ts @@ -28,7 +28,8 @@ export class StreamCall { this.baseRequest = { id: this.id, type: this.type }; const configuration = this.streamClient.getConfiguration({ basePath: - this.streamClient.basePath || "https://video.stream-io-api.com/video", + this.streamClient.options.basePath || + "https://video.stream-io-api.com/video", }); this.apiClient = new DefaultApi(configuration); } @@ -77,7 +78,10 @@ export class StreamCall { }; muteUsers = (videoMuteUsersRequest: VideoMuteUsersRequest) => { - return this.apiClient.muteUsers({ ...this.baseRequest, videoMuteUsersRequest }); + return this.apiClient.muteUsers({ + ...this.baseRequest, + videoMuteUsersRequest, + }); }; queryMembers = (request?: OmitTypeId) => { @@ -135,7 +139,9 @@ export class StreamCall { }); }; - updateCallMembers = (videoUpdateCallMembersRequest: VideoUpdateCallMembersRequest) => { + updateCallMembers = ( + videoUpdateCallMembersRequest: VideoUpdateCallMembersRequest + ) => { return this.apiClient.updateCallMembers({ videoUpdateCallMembersRequest, ...this.baseRequest, @@ -156,6 +162,9 @@ export class StreamCall { }; unpinVideo = (videoUnpinRequest: VideoUnpinRequest) => { - return this.apiClient.videoUnpin({ videoUnpinRequest, ...this.baseRequest }); + return this.apiClient.videoUnpin({ + videoUnpinRequest, + ...this.baseRequest, + }); }; } diff --git a/src/StreamClient.ts b/src/StreamClient.ts index 4a77ec8..d7133c6 100644 --- a/src/StreamClient.ts +++ b/src/StreamClient.ts @@ -60,11 +60,13 @@ import { JWTServerToken, JWTUserToken } from "./utils/create-token"; export type StreamClientOptions = { timeout?: number; + basePath?: string; }; export class StreamClient { public readonly video: StreamVideoClient; public readonly chat: StreamChatClient; + public readonly options: StreamClientOptions = {}; private readonly usersApi: UsersApi; private readonly devicesApi: DevicesApi; private readonly pushApi: PushApi; @@ -75,20 +77,28 @@ export class StreamClient { private readonly eventsApi: EventsApi; private readonly tasksApi: TasksApi; private token: string; - private static readonly defaultTimeout = 3000; + private static readonly DEFAULT_TIMEOUT = 3000; + /** + * + * @param apiKey + * @param secret + * @param config can be a string, which will be interpreted as base path (deprecated), or a config object + */ constructor( private apiKey: string, private secret: string, - public readonly basePath?: string, - public readonly options: StreamClientOptions = {} + readonly config?: string | StreamClientOptions ) { this.token = JWTServerToken(this.secret); this.video = new StreamVideoClient(this); this.chat = new StreamChatClient(this); - if (!options.timeout) { - options.timeout = StreamClient.defaultTimeout; + if (typeof config === "string") { + this.options.basePath = config; + this.options.timeout = StreamClient.DEFAULT_TIMEOUT; + } else { + this.options.timeout = config?.timeout || StreamClient.DEFAULT_TIMEOUT; } const chatConfiguration = this.getConfiguration(); @@ -422,7 +432,7 @@ export class StreamClient { return mapping[name]; }, - basePath: options?.basePath || this.basePath, + basePath: options?.basePath || this.options.basePath, headers: { "X-Stream-Client": "stream-node-" + process.env.PKG_VERSION, }, diff --git a/src/StreamVideoClient.ts b/src/StreamVideoClient.ts index 6ae9e7e..7904593 100644 --- a/src/StreamVideoClient.ts +++ b/src/StreamVideoClient.ts @@ -17,7 +17,8 @@ export class StreamVideoClient { constructor(private streamClient: StreamClient) { const configuration = this.streamClient.getConfiguration({ basePath: - this.streamClient.basePath || "https://video.stream-io-api.com/video", + this.streamClient.options.basePath || + "https://video.stream-io-api.com/video", }); this.apiClient = new DefaultApi(configuration); this.videoServerSideApiClient = new ServerSideApi(configuration);