Skip to content

Commit

Permalink
WIP stuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuel Evans committed Sep 16, 2016
1 parent 0e43900 commit fd30ef8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/socket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ export const startSocket = (store, socketConstructor = Socket) => {
store.dispatch(startPolling(payload));
};

const handleLeave = () => {
if (!channel) {
throw new Error("Leaving a channel when channel isn't joined");
}

channel.leave();
channel = null;
console.log("LEFT CHANNEL!");
store.dispatch(connectionClosed());
};

const connectToSocket = ({ socket: socketState, worker }) => {
const workerUUID = worker.get('uuid');
const socketAuth = socketState.get('auth');
Expand Down Expand Up @@ -88,6 +99,9 @@ export const startSocket = (store, socketConstructor = Socket) => {
channel.on('start_polling', payload => {
handleStartPolling(payload);
});
channel.on('leave', payload => {
handleLeave(payload);
});
channel.join()
.receive('ok', resp => {
pushWorkerState(workerState());
Expand Down

0 comments on commit fd30ef8

Please sign in to comment.