Skip to content

Instantly share code, notes, and snippets.

@bookercodes
Last active June 4, 2018 16:11
Show Gist options
  • Save bookercodes/46cfda6755e27cd32fe316b3ec9155a7 to your computer and use it in GitHub Desktop.
Save bookercodes/46cfda6755e27cd32fe316b3ec9155a7 to your computer and use it in GitHub Desktop.
// ./src/Chat.js
import React, { Component } from 'react'
import { ChatManager, TokenProvider } from '@pusher/chatkit'
class Chat extends Component {
state = {
currentUser: null
}
componentDidMount() {
const chatkit = new ChatManager({
instanceLocator: 'v1:us1:072d42ca-bcc6-4b19-bfe3-926a1e7d04db',
userId: this.props.currentId,
tokenProvider: new TokenProvider({
url:
'https://us1.pusherplatform.io/services/chatkit_token_provider/v1/072d42ca-bcc6-4b19-bfe3-926a1e7d04db/token'
})
})
chatkit
.connect()
.then(currentUser => {
this.setState({ currentUser })
console.log('Bleep bloop 🤖 You are connected to Chatkit')
})
.catch(error => console.error('error', error))
}
render() {
return (
<div>
<h1>Chat Screen</h1>
</div>
)
}
}
export default Chat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment