tlsd 2.2.1 → 2.3.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 +2 -2
- package/scaffold/rpc/index.js +9 -0
- package/scaffold/static/index.html +14 -3
- package/server_static/rpc/rpc.js +22 -15
- package/tlsd.js +1 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tlsd",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "A server for web app prototyping with HTTPS and Websockets",
|
|
5
5
|
"main": "tlsd.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"tlsd": "tlsd"
|
package/scaffold/rpc/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
/*
|
|
3
|
+
This is the back end script that handles message from the front end.
|
|
4
|
+
The "input" object is the exact same that was given to RPC()
|
|
5
|
+
on the front end.
|
|
6
|
+
Use okay() to return a normal response, or fail() to return an error.
|
|
7
|
+
These correspond to the same okay()/fail() functions given to RPC() on
|
|
8
|
+
the front end.
|
|
9
|
+
*/
|
|
10
|
+
|
|
2
11
|
module.exports = ( input, okay, fail ) => {
|
|
3
12
|
|
|
4
13
|
const action = input.action;
|
|
@@ -6,9 +6,20 @@
|
|
|
6
6
|
<script src="/rpc/rpc.js"></script>
|
|
7
7
|
|
|
8
8
|
<script>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
RPC is used to send msgs to the back end.
|
|
12
|
+
If you call RPC() directly, it will decide whether or not
|
|
13
|
+
to use Websocket or REST as transport based on size of object.
|
|
14
|
+
Otherwise, you can explicitly choose the transport by using
|
|
15
|
+
RPC.POST() or RPC.WS().
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
RPC.on_connect = function( evt ) {
|
|
19
|
+
// RPC is ready to be used
|
|
20
|
+
RPC( { action: "hello" }, console.log, alert )
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
</script>
|
|
13
24
|
|
|
14
25
|
</body>
|
package/server_static/rpc/rpc.js
CHANGED
|
@@ -190,21 +190,6 @@
|
|
|
190
190
|
};
|
|
191
191
|
|
|
192
192
|
|
|
193
|
-
ws_connect( msg => {
|
|
194
|
-
DBG( "Server says: " + msg ); // msg initiated by server
|
|
195
|
-
const fn = RPC[ "onmessage" ];
|
|
196
|
-
if( typeof fn == "function" ) {
|
|
197
|
-
fn( msg );
|
|
198
|
-
}
|
|
199
|
-
}, ( evt, detail ) => {
|
|
200
|
-
DBG( "Event: " + evt );
|
|
201
|
-
const fn = RPC[ "on_" + evt ];
|
|
202
|
-
if( typeof fn == "function" ) {
|
|
203
|
-
fn( detail );
|
|
204
|
-
}
|
|
205
|
-
}, "/" );
|
|
206
|
-
|
|
207
|
-
|
|
208
193
|
const RPC_URL = "/rpc/";
|
|
209
194
|
|
|
210
195
|
const via_post = function( msg, okay = ()=>{}, fail = ()=>{} ) {
|
|
@@ -244,6 +229,28 @@
|
|
|
244
229
|
RPC.POST = via_post;
|
|
245
230
|
RPC.WS = via_ws;
|
|
246
231
|
RPC.debug = false;
|
|
232
|
+
RPC.connected = false;
|
|
233
|
+
|
|
234
|
+
ws_connect( msg => {
|
|
235
|
+
DBG( "Server says: " + msg ); // msg initiated by server
|
|
236
|
+
const fn = RPC[ "onmessage" ];
|
|
237
|
+
if( typeof fn == "function" ) {
|
|
238
|
+
fn( msg );
|
|
239
|
+
}
|
|
240
|
+
}, ( evt, detail ) => {
|
|
241
|
+
DBG( "Event: " + evt );
|
|
242
|
+
if( evt === "connect" ) {
|
|
243
|
+
RPC.connected = true;
|
|
244
|
+
}
|
|
245
|
+
if( evt === "disconnect" ) {
|
|
246
|
+
RPC.connected = false;
|
|
247
|
+
}
|
|
248
|
+
const fn = RPC[ "on_" + evt ];
|
|
249
|
+
if( typeof fn == "function" ) {
|
|
250
|
+
fn( detail );
|
|
251
|
+
}
|
|
252
|
+
}, "/" );
|
|
253
|
+
|
|
247
254
|
|
|
248
255
|
globalThis.RPC = RPC;
|
|
249
256
|
|