summaryrefslogtreecommitdiff
path: root/scripts/socket/sock.js
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2021-10-16 17:12:32 -0400
committerKyle Gunger <kgunger12@gmail.com>2021-10-16 17:12:32 -0400
commitb8c91f08adc7bdb0095fb61a59bc03f0d568f478 (patch)
tree1c9f39c2d2c2279593d2117ef64274b561981db6 /scripts/socket/sock.js
parent8f71df8341224a0898984a9bc67005fdbea9ee30 (diff)
[Formatting] Tabs instead of spaces
Diffstat (limited to 'scripts/socket/sock.js')
-rw-r--r--scripts/socket/sock.js114
1 files changed, 57 insertions, 57 deletions
diff --git a/scripts/socket/sock.js b/scripts/socket/sock.js
index 36e28bc..0a04b63 100644
--- a/scripts/socket/sock.js
+++ b/scripts/socket/sock.js
@@ -1,71 +1,71 @@
'use strict';
// A wrapper around the wrapper
class SockWorker extends EventTarget{
- constructor (serveraddr, version)
- {
- super();
+ constructor (serveraddr, version)
+ {
+ super();
- this.server = serveraddr;
- this.version = version;
- }
+ this.server = serveraddr;
+ this.version = version;
+ }
- // Initialize the connection.
- init () {
- if(this.server == "" || this.server == null) {
- return;
- }
- try {
- this.socket = new WebSocket(this.server);
+ // 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("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();
- }
- }
+ 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 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 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 CustomEvent(dat.type, {detail: dat.data}));
+ }
+ }
- // Called when the connection closes.
- // Passes a close object to the callback.
- c () {
- this.dispatchEvent(new Event("closed"));
- }
+ // 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();
- }
+ // Called when the connection encounters an error.
+ // Passes an error to the callback
+ err () {
+ this.dispatchEvent(new Event("error"));
+ }
- // Send a message to the server
- send (type, data) {
- var m = new Message(type, data);
- this.socket.send(m.stringify())
- }
+ // Call to close the connection to the server
+ close () {
+ this.socket.close();
+ }
- // Raw message the server
- sendRaw (s) {
- this.socket.send(s)
- }
+ // Send a message to the server
+ send (type, data) {
+ var m = new Message(type, data);
+ this.socket.send(m.stringify())
+ }
+
+ // Raw message the server
+ sendRaw (s) {
+ this.socket.send(s)
+ }
}