Skip to content

Commit

Permalink
change StreamClient ctr signature
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Nov 7, 2023
1 parent 66bac0a commit b83514b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion __tests__/create-test-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};
17 changes: 13 additions & 4 deletions src/StreamCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<VideoQueryMembersRequest>) => {
Expand Down Expand Up @@ -135,7 +139,9 @@ export class StreamCall {
});
};

updateCallMembers = (videoUpdateCallMembersRequest: VideoUpdateCallMembersRequest) => {
updateCallMembers = (
videoUpdateCallMembersRequest: VideoUpdateCallMembersRequest
) => {
return this.apiClient.updateCallMembers({
videoUpdateCallMembersRequest,
...this.baseRequest,
Expand All @@ -156,6 +162,9 @@ export class StreamCall {
};

unpinVideo = (videoUnpinRequest: VideoUnpinRequest) => {
return this.apiClient.videoUnpin({ videoUnpinRequest, ...this.baseRequest });
return this.apiClient.videoUnpin({
videoUnpinRequest,
...this.baseRequest,
});
};
}
22 changes: 16 additions & 6 deletions src/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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,
},
Expand Down
3 changes: 2 additions & 1 deletion src/StreamVideoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b83514b

Please sign in to comment.