Skip to content

Commit

Permalink
feat(disconnect, unsubscribe): Adicionar função para de desconectar d…
Browse files Browse the repository at this point in the history
…o broker e para se desinscrever
  • Loading branch information
matheuspiment committed Jul 2, 2018
1 parent f7e5cb5 commit b49de79
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ const connect = () => {
client = emitter.connect();
};

/**
* Disconnects from the emitter broker.
* @function
*/
const disconnect = () => {
client.disconnect();
client = undefined;
};

/**
* Subscribes to the channel.
* @function
Expand All @@ -83,6 +92,19 @@ const subscribe = (last) => {
});
};

/**
* Unsubscribes to the channel.
* @function
*/
const unsubscribe = () => {
hasClient();

client.unsubscribe({
key: EMITTER_CHANNEL_KEY,
channel: EMITTER_CHANNEL,
});
};

/**
* Publish a message to the channel.
* @function
Expand Down Expand Up @@ -132,7 +154,9 @@ const onMessage = (callback) => {

export default {
connect,
disconnect,
subscribe,
unsubscribe,
publish,
onMessage,
};
Expand Down

0 comments on commit b49de79

Please sign in to comment.