Skip to content

Instantly share code, notes, and snippets.

@nparsons08 nparsons08/13.js Secret
Created May 28, 2019

Embed
What would you like to do?
// src/App.vue
[...]
methods: {
async joinChat() {
const { data } = await axios.post(
`${process.env.VUE_APP_SERVER_API_ENDPOINT}/join`,
{
username: this.username
}
);
this.username = "";
this.hasJoinedChat = true;
this.user = data.user;
this.token = data.token;
await this.initializeStream();
await this.initializeChannel();
},
async initializeStream() {
const { username } = this.user;
this.client = new StreamChat(process.env.VUE_APP_API_KEY);
await this.client.setUser({ id: username, name: username }, this.token);
},
async initializeChannel() {
this.channel = this.client.channel("messaging", "vue-chat", {
name: "Vue Chat"
});
this.messages = (await this.channel.watch()).messages;
}
}
[...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.