summaryrefslogtreecommitdiff
path: root/webcards/scripts/socket/sock.js
diff options
context:
space:
mode:
authorKyle Gunger <corechg@gmail.com>2020-09-18 12:22:26 -0400
committerKyle Gunger <corechg@gmail.com>2020-09-18 12:22:26 -0400
commit9681347b8e9f6059c3f5f02528e0893bef5acca4 (patch)
tree16e5dff45804d13abeda17041668eff0485483c7 /webcards/scripts/socket/sock.js
parent2ce432034eb35f763182de03fb7b42d2a07afc4b (diff)
Move webcards to seperate repo
Diffstat (limited to 'webcards/scripts/socket/sock.js')
-rw-r--r--webcards/scripts/socket/sock.js65
1 files changed, 0 insertions, 65 deletions
diff --git a/webcards/scripts/socket/sock.js b/webcards/scripts/socket/sock.js
deleted file mode 100644
index 4eacc18..0000000
--- a/webcards/scripts/socket/sock.js
+++ /dev/null
@@ -1,65 +0,0 @@
-// A wrapper around the wrapper
-class SockWorker extends EventTarget{
- constructor (serveraddr, version)
- {
- super();
-
- this.server = serveraddr;
- this.version = version;
- }
-
- // Initialize the connection.
- init () {
- if(this.server == "" || this.server == null) {
- return;
- }
- try {
- this.socket = new WebSocket(this.server);
-
- this.socket.addEventListener("open", this.o.bind(this));
- this.socket.addEventListener("message", this.msg.bind(this));
-
- this.socket.addEventListener("closed", this.c.bind(this));
- this.socket.addEventListener("error", this.err.bind(this));
- } catch (e) {
- this.err();
- }
- }
-
- // Called when the connection connects to the server
- o () {
- this.send("version", this.version);
- }
-
- // Called when the connection gets a message from the server
- // Attempts to turn the message into a usable object and pass it to the callback
- msg (e) {
- if(typeof e.data == "string") {
- var dat = JSON.parse(e.data)
- this.dispatchEvent(new Event(dat.type, dat.data));
- }
- }
-
- // Called when the connection closes.
- // Passes a close object to the callback.
- c () {
- this.dispatchEvent(new Event("closed"));
- }
-
- // Called when the connection encounters an error.
- // Passes an error to the callback
- err () {
- this.dispatchEvent(new Event("error"));
- }
-
- // Call to close the connection to the server
- close () {
- this.socket.close();
- }
-
- // Send a message to the server
- send (type, data) {
- var m = new Message(type, data);
- this.socket.send(m.stringify())
- }
-}