Created
January 6, 2020 15:59
-
-
Save pmbanugo/ce45810721485b0412514e64a0d020c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private conversation: Channel; | |
async initialiseChatClient(): Promise<void> { | |
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.user.avatarUrl = streamServerInfo.user.image; | |
const chatClient = new StreamChat(streamServerInfo.apiKey); | |
chatClient.setUser(this.user, streamServerInfo.token); | |
this.conversation = 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