Skip to content

Commit 2df0bcb

Browse files
authored
Merge pull request #420 from GetStream/init-options
feat: add client options to init method
2 parents e2c97b6 + a07d52c commit 2df0bcb

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

projects/stream-chat-angular/src/lib/chat-client.service.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('ChatClientService', () => {
3333
mockChatClient.connectUser.calls.reset();
3434
await service.init(apiKey, userId, userToken);
3535

36-
expect(StreamChat.getInstance).toHaveBeenCalledWith(apiKey);
36+
expect(StreamChat.getInstance).toHaveBeenCalledWith(apiKey, undefined);
3737
const spy = jasmine.createSpy();
3838
service.appSettings$.subscribe(spy);
3939
const userSpy = jasmine.createSpy();
@@ -51,7 +51,7 @@ describe('ChatClientService', () => {
5151
mockChatClient.connectUser.calls.reset();
5252
await service.init(apiKey, userId, 'guest');
5353

54-
expect(StreamChat.getInstance).toHaveBeenCalledWith(apiKey);
54+
expect(StreamChat.getInstance).toHaveBeenCalledWith(apiKey, undefined);
5555
const spy = jasmine.createSpy();
5656
service.appSettings$.subscribe(spy);
5757
const userSpy = jasmine.createSpy();
@@ -124,6 +124,17 @@ describe('ChatClientService', () => {
124124
expect(mockChatClient.connectUser).toHaveBeenCalledWith(user, userToken);
125125
});
126126

127+
it('should init with options', async () => {
128+
const user = {
129+
id: userId,
130+
name: 'Test user',
131+
} as OwnUserResponse<DefaultStreamChatGenerics>;
132+
const options = { timeout: 5000 };
133+
await service.init(apiKey, user, userToken, options);
134+
135+
expect(StreamChat.getInstance).toHaveBeenCalledWith(apiKey, options as any);
136+
});
137+
127138
it('should init with token provider', async () => {
128139
const tokenProvider = () => Promise.resolve('test');
129140
mockChatClient.connectUser.calls.reset();

projects/stream-chat-angular/src/lib/chat-client.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ChannelResponse,
77
ConnectAPIResponse,
88
OwnUserResponse,
9+
StreamChatOptions,
910
UserFilters,
1011
UserResponse,
1112
} from 'stream-chat';
@@ -84,13 +85,15 @@ export class ChatClientService<
8485
* @param apiKey
8586
* @param userOrId
8687
* @param userTokenOrProvider You can provide a token, or the keyword 'guest' to connect as [guest user](https://getstream.io/chat/docs/javascript/authless_users/?language=javascript#guest-users)
88+
* @param clientOptions Setting to provide to the Stream client instance
8789
*/
8890
async init(
8991
apiKey: string,
9092
userOrId: string | OwnUserResponse<T> | UserResponse<T>,
91-
userTokenOrProvider: TokenOrProvider | 'guest'
93+
userTokenOrProvider: TokenOrProvider | 'guest',
94+
clientOptions?: StreamChatOptions
9295
): ConnectAPIResponse<T> {
93-
this.chatClient = StreamChat.getInstance<T>(apiKey);
96+
this.chatClient = StreamChat.getInstance<T>(apiKey, clientOptions);
9497
this.chatClient.devToken;
9598
let result;
9699
await this.ngZone.runOutsideAngular(async () => {

0 commit comments

Comments
 (0)