Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Last active October 22, 2016 13:25
Show Gist options
  • Save bnhansn/94aaca47a1e2572b410840100b4948ab to your computer and use it in GitHub Desktop.
Save bnhansn/94aaca47a1e2572b410840100b4948ab to your computer and use it in GitHub Desktop.
export function connectToChannel(socket, roomId) {
return (dispatch) => {
if (!socket) { return false; }
const channel = socket.channel(`rooms:${roomId}`);
channel.join().receive('ok', (response) => {
dispatch({ type: 'ROOM_CONNECTED_TO_CHANNEL', response, channel });
});
return false;
};
}
export function leaveChannel(channel) {
return (dispatch) => {
if (channel) {
channel.leave();
}
dispatch({ type: 'USER_LEFT_ROOM' });
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment