Skip to content

Instantly share code, notes, and snippets.

@BrightnBubbly
Created May 4, 2020 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrightnBubbly/1760fa16394daa1effbd840c453f8713 to your computer and use it in GitHub Desktop.
Save BrightnBubbly/1760fa16394daa1effbd840c453f8713 to your computer and use it in GitHub Desktop.
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