-
-
Save BrightnBubbly/1760fa16394daa1effbd840c453f8713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { StreamChat, Channel, ConnectAPIResponse } from 'stream-chat'; | |
declare interface UserInfo { | |
token: string; | |
apiKey: string; | |
username: string; | |
} | |
@Injectable({ | |
providedIn: 'root', | |
}) | |
export class StreamService { | |
constructor() {} | |
streamClient: StreamChat; | |
currentUser: ConnectAPIResponse; | |
public async initClient(user: UserInfo): Promise<Channel> { | |
this.streamClient = new StreamChat(user.apiKey); | |
this.currentUser = await this.streamClient.setUser( | |
{ | |
id: user.username, | |
name: user.username, | |
}, | |
user.token | |
); | |
return this.streamClient.channel('messaging', 'General'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment