This repository has been archived by the owner on May 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mihai Voinea
committed
Jun 2, 2020
1 parent
ec7fdcb
commit 8ced734
Showing
3 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import ReconnectingWebSocket from "reconnecting-websocket"; | ||
|
||
import store from "./store"; | ||
|
||
let rws; | ||
|
||
const setupRws = () => { | ||
// eslint-disable-next-line no-console | ||
console.log("setupRws() called"); | ||
if (rws) rws.close(); | ||
rws = new ReconnectingWebSocket( | ||
`wss://api.getmakerlog.com/users/${store.state.user.id}/stream/` | ||
); | ||
// eslint-disable-next-line no-console | ||
rws.onmessage = (e) => { | ||
const data = JSON.parse(e.data); | ||
switch (data.type) { | ||
case "task.created": | ||
store.commit("ADD_TASK", data.payload); | ||
break; | ||
case "task.deleted": | ||
store.commit("DELETE_TASK", data.payload); | ||
break; | ||
case "task.updated": | ||
store.commit("UPDATE_TASK", data.payload); | ||
break; | ||
default: | ||
// eslint-disable-next-line no-console | ||
console.log("rws other event catched", data.payload); | ||
break; | ||
} | ||
}; | ||
}; | ||
|
||
export default setupRws; |
This file contains 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