tlsd 2.3.0 → 2.4.1

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": "tlsd",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
4
4
  "description": "A server for web app prototyping with HTTPS and Websockets",
5
5
  "main": "tlsd.js",
6
6
  "bin": {
@@ -6,13 +6,13 @@
6
6
  // Send msg via Websocket if it's less than around 5K stringified, otherwise use POST
7
7
  RPC( msg_object, okay, fail );
8
8
 
9
- RPC.on_connect = () => {
9
+ RPC.connect( function() {
10
10
  RPC( { action: "Hello, I'm a client" }, rsp => {
11
11
  console.log( rsp ) // "Welcome client, I'm a server"
12
12
  }, error => {
13
13
  alert( error )
14
14
  } );
15
- };
15
+ } );
16
16
 
17
17
  RPC.debug = true; // enable on console debug output
18
18
 
@@ -215,6 +215,14 @@
215
215
  conn.send( { msg }, okay );
216
216
  };
217
217
 
218
+ const connect = function( cb ) {
219
+ if( RPC.connected ) {
220
+ cb();
221
+ } else {
222
+ RPC.on_connect = cb;
223
+ }
224
+ };
225
+
218
226
  const RPC = function( msg, okay = ()=>{}, fail = ()=>{} ) {
219
227
  const json = o2j( msg );
220
228
  if( json.length > 5000 ) {
@@ -226,18 +234,21 @@
226
234
  }
227
235
  };
228
236
 
237
+ RPC.connect = connect;
229
238
  RPC.POST = via_post;
230
239
  RPC.WS = via_ws;
231
240
  RPC.debug = false;
232
241
  RPC.connected = false;
233
242
 
234
243
  ws_connect( msg => {
235
- DBG( "Server says: " + msg ); // msg initiated by server
244
+ // msg initiated by server
245
+ DBG( "Server says: " + msg );
236
246
  const fn = RPC[ "onmessage" ];
237
247
  if( typeof fn == "function" ) {
238
248
  fn( msg );
239
249
  }
240
250
  }, ( evt, detail ) => {
251
+ // event occurred
241
252
  DBG( "Event: " + evt );
242
253
  if( evt === "connect" ) {
243
254
  RPC.connected = true;
@@ -5,7 +5,7 @@
5
5
 
6
6
  <script>
7
7
  RPC.debug = true;
8
- RPC.on_connect = evt => {
8
+ RPC.connect( function() {
9
9
  RPC( { action: "ping" }, console.log, alert );
10
- };
10
+ } );
11
11
  </script>