web-repl 0.5 → 0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e6f59ae36066ce6cff2f0826db2749ff3929a57
4
- data.tar.gz: 4eb7847fd7444a0846d5ae2dbfe40bd339e4a4e6
3
+ metadata.gz: a9cb6f9d73523c501441de89215c76c8e7343161
4
+ data.tar.gz: bdb3396923e7fca4fc2a267162c9d5f1ff81cd53
5
5
  SHA512:
6
- metadata.gz: 657a2e5bba0fb94fe7c2162dfd30d2a436b918c6fe926948cb9fdb245f3cb834901df10c7a04069481954e28628221f815ef574a694e6d16c0e8dfcb024c6e42
7
- data.tar.gz: bedcf0013f25f8e86d6d354fc0e6a84f37c45d97d764f06f5dcd27f51bd9dca1d60d3c5a1a3e90adef151b8b341f49802e5199eab2608f3b37639ca114eaee3d
6
+ metadata.gz: 32a4b0890411729f1c1fbaec5ad54b0e78c81b6fdf98e54a342c6244d059db54f7386694adadde2d0767d771eb8123995afb2a0c6a007880a1be7a6d7846d357
7
+ data.tar.gz: 8abdfd2e5050b6c79671a77e24fb827343104b6b679f34c20986878aa0772153df88a6e24b0fb861fc930f66bf7bef4c36c01f6118ecdd1c699b970a6d9e71fc
@@ -0,0 +1 @@
1
+ function ReplConnection(e,t,n){n=typeof n==="undefined"?{}:n;this.debug=!!n.debug;this.reconnect=!!n.reconnect;this.retryTime=n.retryTime||1e3;this.evalFunction=n.evalFunction;this.host=e;this.port=t;this.active=false;this.socket;this.supported="WebSocket"in window;if(this.supported){console.log("REPL: socket ok")}else{console.log("REPL: socket not supported")}}ReplConnection.prototype.eval=function(statement){options=typeof options==="undefined"?{}:options;var response={};try{if(typeof this.evalFunction==="function"){response.value=this.evalFunction(statement)}else{response.value=eval(statement)}}catch(err){response.error=err.message}return response};ReplConnection.prototype.initSocket=function(e){if(this.socket!==undefined&&this.socket!==null){this.socket.close()}var t="ws://"+this.host+":"+this.port+"/echo";this.socket=new WebSocket(t);e()};ReplConnection.prototype.handleSocketOpen=function(){this.active=true;console.log("REPL: socket ready")};ReplConnection.prototype.tryConnection=function(){console.log("REPL: waiting for connection");if(this.reconnect){var e=this;window.setTimeout(function(){e.start()},this.retryTime)}};ReplConnection.prototype.handleSocketClose=function(e){if(!this.active){this.tryConnection()}else{console.log("REPL: socket closed");this.active=false;if(this.reconnect){this.tryConnection()}}};ReplConnection.prototype.convertTimestamp=function(e){var t=e.timestamp;e.timestamp=new Date(t);return e.timestamp};ReplConnection.prototype.handleMessageReceived=function(e){if(this.debug){console.log("REPL: message received");console.log(e)}var t=JSON.parse(e.data);this.convertTimestamp(t);var n=this.eval(t.statement);return this.send(n)};ReplConnection.prototype.send=function(e){var t=this.prepareJSON(e);if(this.debug){console.log("REPL: sending");console.log(t)}return this.socket.send(t)};ReplConnection.prototype.prepareJSON=function(e){var t;try{e.timestamp=(new Date).getTime();t=JSON.stringify(e)}catch(n){t=this.handleJsonError(e,n)}return t};ReplConnection.prototype.handleJsonError=function(e,t){e.value=null;e.error=t.message;return this.prepareJSONResponse(e)};ReplConnection.prototype.initEventHandling=function(){var e=this;this.socket.onopen=function(){e.handleSocketOpen()};this.socket.onclose=function(t){e.handleSocketClose(t)};this.socket.onmessage=function(t){e.handleMessageReceived(t)}};ReplConnection.prototype.start=function(e){if(this.supported){var t=this;this.initSocket(function(){t.initEventHandling();if(e!==undefined){e(t)}})}}
@@ -119,7 +119,7 @@ ReplConnection.prototype.prepareJSON = function(message) {
119
119
  // Handle an error when converting the message to JSON
120
120
  ReplConnection.prototype.handleJsonError = function(message, error) {
121
121
  message.value = null;
122
- message.error = err.message;
122
+ message.error = error.message;
123
123
  return this.prepareJSONResponse(message);
124
124
  }
125
125
 
@@ -13,7 +13,7 @@ require "web-repl/repl"
13
13
  # A Javascript REPL that runs in Ruby. Evaluation is done by a web browser instance.
14
14
  module WebRepl
15
15
 
16
- VERSION = "0.5"
16
+ VERSION = "0.6"
17
17
 
18
18
  # Shortcut to REPL.start
19
19
  def self.start(*a)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web-repl
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Russo
@@ -95,6 +95,7 @@ files:
95
95
  - js/replConnection-0.3.min.js
96
96
  - js/replConnection-0.4.min.js
97
97
  - js/replConnection-0.5.min.js
98
+ - js/replConnection-0.6.min.js
98
99
  - js/replConnection.js
99
100
  - lib/web-repl.rb
100
101
  - lib/web-repl/messager.rb