Last active
August 13, 2016 21:17
-
-
Save samcorcos/5993878324101e2304d43f9fce5c49cc 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
import React from 'react' | |
import { Socket } from 'phoenix' | |
class App extends React.Component { | |
componentDidMount() { | |
this.socket = new Socket('http://localhost:4000/socket') | |
this.socket.connect() | |
this.configureChannel("lobby") | |
} | |
componentWillUnmount() { | |
this.socket.leave() | |
} | |
configureChannel(room) { | |
this.channel = this.socket.channel(`rooms:${room}`) | |
this.channel.join() | |
.receive("ok", () => { | |
console.log(`Succesfully joined the ${room} chat room.`) | |
}) | |
.receive("error", () => { | |
console.log(`Unable to join the ${room} chat room.`) | |
}) | |
} | |
render() { | |
return ( | |
<div> | |
My App | |
</div> | |
) | |
} | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment