virtual-keypad 5.0.0 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "virtual-keypad",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "User response at a distance. Simple utility to summon forth a virtual keypad webapp.",
5
5
  "main": "dist/main.js",
6
6
  "directories": {
package/src/keypad.js CHANGED
@@ -122,6 +122,8 @@ class Keypad extends KeypadPeer {
122
122
  console.log("No target element used.");
123
123
  document.getElementsByTagName("main")[0].appendChild(keypadElem);
124
124
  }
125
+ window.onbeforeunload = () => {this.conn?.close(); console.log("closing connection on page unload.")};
126
+ window.onvisibilitychange = () => {this.conn?.close(); console.log("closing connection on page unload.")};
125
127
  };
126
128
  #populateKeypad = () => {
127
129
  const buttonResponseFn = (button) => {
package/src/receiver.js CHANGED
@@ -23,9 +23,9 @@ class Receiver extends KeypadPeer {
23
23
 
24
24
  this.onData = onDataCallback; // What to do on a button-press
25
25
  this.onHandshake = handshakeCallback; // What to do when the connection is established
26
- this.onConnection = (connection) => {customConnectionCallback(connection); this.#onPeerConnection(connection)};
27
- this.onClose = () => {customCloseCallback(); this.onPeerClose()};
28
- this.onError = (err) => {customErrorCallback(err); this.onPeerError(err)};
26
+ this.onConnection = (connection) => {this.#onPeerConnection(connection); customConnectionCallback(connection)};
27
+ this.onClose = () => {this.onPeerClose(); customCloseCallback()};
28
+ this.onError = (err) => {this.onPeerError(err); customErrorCallback(err)};
29
29
 
30
30
  /* Set up callbacks that handle any events related to our peer object. */
31
31
  this.peer.on("open", this.#onPeerOpen); // On creation of Receiver (local) Peer object