Skip to content

Instantly share code, notes, and snippets.

@pmbanugo
Created December 23, 2019 14:09
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 pmbanugo/f8ef6db43c5cee805b4aee70f67cd98a to your computer and use it in GitHub Desktop.
Save pmbanugo/f8ef6db43c5cee805b4aee70f67cd98a to your computer and use it in GitHub Desktop.
initialiseChatClient = async () => {
const response = await fetch("http://localhost:8080/v1/token", {
method: "POST",
mode: "cors",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
id: this.user.id,
name: this.user.name
})
});
const streamServerInfo = await response.json();
this.chatClient = new StreamChat(streamServerInfo.apiKey);
this.chatClient.setUser(this.user, streamServerInfo.token);
this.conversation = this.chatClient.channel("commerce", "conversational-ui");
await this.conversation.watch();
this.conversation.on("message.new", this.onNewMessage;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment