aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/jarvis.js3
-rw-r--r--utils/ident.js4
2 files changed, 4 insertions, 3 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index a8373ce..b82584f 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -14,8 +14,7 @@ const id = require('../utils/ident');
//// Basic handling on open and close of the socket
var main = new Socket();
-id(main, initOnce, init);
-main.on('close', deinit);
+id(main, initOnce, init, deinit);
//// tileUpdates require knowledge of the prog's identity (sender)
var sender;
diff --git a/utils/ident.js b/utils/ident.js
index 6d18b88..f526afc 100644
--- a/utils/ident.js
+++ b/utils/ident.js
@@ -1,6 +1,6 @@
// A portable script to find the sender when the server websocket opens (by cursor movement)
-module.exports = function identify(sock, initOnce, init){
+module.exports = function identify(sock, initOnce, init, deinit){
// `sock` should be Socket instance.
// initOnce and init should be functions that act like they describe; initOnce runs once per program execution and init whenever the socket turns back on
@@ -17,6 +17,8 @@ module.exports = function identify(sock, initOnce, init){
}
}
+ sock.on('close', deinit);
+
// Calls initOnce and init on successful identification.
let initialized = false;
function identity(send){