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
package/server_static/rpc/rpc.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
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;
|