From 7104cf75cb3df35097c10a719fea4b5e1fc69f57 Mon Sep 17 00:00:00 2001
From: stisa
Date: Sat, 25 Mar 2017 22:03:54 +0100
Subject: [PATCH] update readme and docs following pr
---
README.md | 22 ++---
docs/examples/ex1.html | 22 ++---
docs/examples/ex1.js | 89 +++---------------
docs/index.html | 8 +-
docs/jswebsockets.html | 201 +++++++++++++++++++++++++++--------------
5 files changed, 172 insertions(+), 170 deletions(-)
diff --git a/README.md b/README.md
index 46f474a..a11c22f 100644
--- a/README.md
+++ b/README.md
@@ -7,21 +7,19 @@ Beginning of a wrapper for websockets, for the javascript backend of [nim](https
[Generated Docs](http://stisa.space/jswebsockets/jswebsockets.html)
-**NOTE**: The `append` proc is only exported when compiling with `-d:test`.
-
```nim
import jswebsockets
-var ws = openws("ws://echo.websocket.org/")
-var outputid = "output" # convenience for appending
+var
+ socket = newWebSocket("ws://echo.websocket.org/")
-ws.onopen = proc(e:Event) =
- outputid.append("sent: test")
- ws.send("test")
-ws.onmessage = proc(e:MessageEvent) =
- outputid.append("received: ",e.data)
- ws.close(StatusCode(1000),"received msg")
-ws.onclose = proc(e:CloseEvent) =
- outputid.append("closing: ",e.reason)
+socket.onOpen = proc (e:Event) =
+ echo("sent: test")
+ socket.send("test")
+socket.onMessage = proc (e:MessageEvent) =
+ echo("received: ",e.data)
+ socket.close(StatusCode(1000),"received msg")
+socket.onClose = proc (e:CloseEvent) =
+ echo("closing: ",e.reason)
```
diff --git a/docs/examples/ex1.html b/docs/examples/ex1.html
index cbb59da..d530d22 100644
--- a/docs/examples/ex1.html
+++ b/docs/examples/ex1.html
@@ -6,7 +6,7 @@
-
+
@@ -27,7 +27,7 @@ Menu
Projects
About Me
- websockets
+ jswebsockets
@@ -40,19 +40,17 @@ Example: ex1
Code
import ../src/jswebsockets
-var ws = openws("ws://echo.websocket.org/")
+var socket = newWebSocket("ws://echo.websocket.org/")
var outputid = "output" # nicer syntax for appending
-ws.onopen = proc(e:Event) =
+socket.onOpen = proc (event: Event) =
outputid.append("sent: test")
- ws.send("test")
-ws.onmessage = proc(e:MessageEvent) =
- outputid.append("received: ",e.data)
- ws.close(scNormal,"received msg")
-ws.onclose = proc(e:CloseEvent) =
- outputid.append("closing: ",e.reason)
-
-
+ socket.send("test")
+socket.onMessage = proc (event: MessageEvent) =
+ outputid.append("received: ", event.data)
+ socket.close(scNormal,"received msg")
+socket.onClose = proc (event: CloseEvent) =
+ outputid.append("closing: ", event.reason)
diff --git a/docs/examples/ex1.js b/docs/examples/ex1.js
index caaf74b..bd2be9a 100644
--- a/docs/examples/ex1.js
+++ b/docs/examples/ex1.js
@@ -214,13 +214,6 @@ unhandledException(e_13206);
e_13206.trace = nimCopy(null, rawWriteStackTrace_13028(), NTI138);
throw e_13206;}
-function mnewString(len_14403) {
-
- var result = new Array(len_14403+1);
- result[0] = 0;
- result[len_14403] = 0;
- return result;
- }
var nimvm_5887 = false;
var nim_program_result = 0;
var globalRaiseHook_10805 = [null];
@@ -383,87 +376,31 @@ e_13659.message = nimCopy(null, makeNimstrLit("division by zero"), NTI138);
e_13659.parent = null;
raiseException(e_13659, "DivByZeroError");
}
-var ws_44001 = /**/[new WebSocket("ws://echo.websocket.org/")];
-var outputid_44002 = /**/[makeNimstrLit("output")];
-function nsuJoinSep(a_38651, sep_38652) {
-
-var result_38653 = null;
-if ((0 < (a_38651 != null ? a_38651.length : 0))) {
-var L_38668 = ((sep_38652 != null ? sep_38652.length-1 : 0) * ((a_38651 != null ? a_38651.length : 0) - 1));
-L1: do {
-var i_38678 = 0;
-var colontmp__38699 = 0;
-colontmp__38699 = (a_38651 != null ? (a_38651.length-1) : -1);
-var res_38702 = 0;
-L2: do {
-L3: while (true) {
-if (!(res_38702 <= colontmp__38699)) break L3;
-i_38678 = res_38702;
-L_38668 += (a_38651[i_38678] != null ? a_38651[i_38678].length-1 : 0);
-res_38702 += 1;
-}
-} while(false);
-} while(false);
-result_38653 = nimCopy(null, mnewString(0), NTI138);
-if (result_38653 != null) { result_38653 = (result_38653.slice(0, -1)).concat(a_38651[0]); } else { result_38653 = a_38651[0];};
-L4: do {
-var i_38697 = 0;
-var colontmp__38707 = 0;
-colontmp__38707 = (a_38651 != null ? (a_38651.length-1) : -1);
-var res_38710 = 1;
-L5: do {
-L6: while (true) {
-if (!(res_38710 <= colontmp__38707)) break L6;
-i_38697 = res_38710;
-if (result_38653 != null) { result_38653 = (result_38653.slice(0, -1)).concat(sep_38652); } else { result_38653 = sep_38652;};
-if (result_38653 != null) { result_38653 = (result_38653.slice(0, -1)).concat(a_38651[i_38697]); } else { result_38653 = a_38651[i_38697];};
-res_38710 += 1;
-}
-} while(false);
-} while(false);
-}
-else {
-result_38653 = nimCopy(null, makeNimstrLit(""), NTI138);
-}
-
-return result_38653;
-}
-function append_43001(toID_43003, s_43005) {
-
-var F={procname:"jswebsockets.append",prev:framePtr,filename:"C:\\Users\\stisa\\OneDrive\\Progetti\\websockets\\src\\jswebsockets.nim",line:0};
-framePtr = F;
-F.line = 107;
-var p_43006 = document.createElement("P");
-F.line = 108;
-p_43006.innerHTML = toJSStr(nsuJoinSep(s_43005, makeNimstrLit("")));
-F.line = 109;
-var parent_43007 = document.getElementById(toJSStr(toID_43003));
-parent_43007.appendChild(p_43006);
-framePtr = F.prev;
-}
-function colonanonymous__44003(e_44005) {
+var socket_45001 = /**/[new WebSocket("ws://echo.websocket.org/")];
+var outputid_45002 = /**/[makeNimstrLit("output")];
+function colonanonymous__45003(event_45005) {
var F={procname:"ex1.:anonymous",prev:framePtr,filename:"ex1.nim",line:0};
framePtr = F;
-append_43001(outputid_44002[0], [makeNimstrLit("sent: test")]);
-ws_44001[0].send("test");
+outputid_45002[0].append([makeNimstrLit("sent: test")]);
+socket_45001[0].send("test");
framePtr = F.prev;
}
-ws_44001[0].onopen = colonanonymous__44003;
-function colonanonymous__44008(e_44010) {
+socket_45001[0].onopen = colonanonymous__45003;
+function colonanonymous__45008(event_45010) {
var F={procname:"ex1.:anonymous",prev:framePtr,filename:"ex1.nim",line:0};
framePtr = F;
-append_43001(outputid_44002[0], [makeNimstrLit("received: "), cstrToNimstr(e_44010.data)]);
-ws_44001[0].close(1000, "received msg");
+outputid_45002[0].append([makeNimstrLit("received: "), cstrToNimstr(event_45010.data)]);
+socket_45001[0].close(1000, "received msg");
framePtr = F.prev;
}
-ws_44001[0].onmessage = colonanonymous__44008;
-function colonanonymous__44023(e_44025) {
+socket_45001[0].onmessage = colonanonymous__45008;
+function colonanonymous__45023(event_45025) {
var F={procname:"ex1.:anonymous",prev:framePtr,filename:"ex1.nim",line:0};
framePtr = F;
-append_43001(outputid_44002[0], [makeNimstrLit("closing: "), cstrToNimstr(e_44025.reason)]);
+outputid_45002[0].append([makeNimstrLit("closing: "), cstrToNimstr(event_45025.reason)]);
framePtr = F.prev;
}
-ws_44001[0].onclose = colonanonymous__44023;
+socket_45001[0].onclose = colonanonymous__45023;
diff --git a/docs/index.html b/docs/index.html
index 2670f54..ab1aa15 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -6,8 +6,8 @@
- websockets
-
+ jswebsockets
+
@@ -30,14 +30,14 @@ Menu
- Examples for websockets
+ Examples for jswebsockets
-
+
@@ -1196,17 +1211,6 @@
Module jswebsockets
-
- Search:
-
-
- Group by:
-
- Section
- Type
-
-
Imports
@@ -1226,14 +1230,24 @@ Module jswebsockets
scTLSHandshake = 1015"> Status Code
Message Event
+ data*: cstring
+ origin*: cstring"> Message Event
Close Event
+ Ready State
Web Socket
+ title="WebSocket = ref object of EventTarget
+ url*: cstring
+ protocol*: cstring
+ readyState*: ReadyState
+ onopen*: proc (event: Event)
+ onclose*: proc (event: CloseEvent)
+ onmessage*: proc (event: MessageEvent)"> Web Socket
@@ -1244,12 +1258,23 @@
Module jswebsockets
title="openws(url: cstring): WebSocket">
openws
WebSocket
openwsWebSocket
+
new Web SocketWebSocket
+
new Web SocketWebSocket
+
new Web SocketWebSocket
+
add Event ListenerMessageEvent
sendWebSocket
+ title="send(socket: WebSocket; data: cstring)">
send
WebSocket
closeWebSocket
+ title="close(socket: WebSocket)">
close
WebSocket
+
closeWebSocket
closeWebSocket
+ title="close[](socket: WebSocket; code: StatusCode | Natural; reason: cstring)">
close
WebSocket
@@ -1277,20 +1302,21 @@
Source
-Edit
+Edit
MessageEvent = object of Event
data * : cstring
+ origin * : cstring
Source
-Edit
+Edit
CloseEvent = object of Event
@@ -1299,42 +1325,37 @@
wasClean * : bool
-Status code Name Description
-0–999 Reserved and not used.
-1000 CLOSE_NORMAL Normal closure; the connection successfully completed whatever purpose for which it was created.
-1001 CLOSE_GOING_AWAY The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection.
-1002 CLOSE_PROTOCOL_ERROR The endpoint is terminating the connection due to a protocol error.
-1003 CLOSE_UNSUPPORTED The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data).
-1004 Reserved. A meaning might be defined in the future.
-1005 CLOSE_NO_STATUS Reserved. Indicates that no status code was provided even though one was expected.
-1006 CLOSE_ABNORMAL Reserved. Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected.
-1007 Unsupported Data The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message).
-1008 Policy Violation The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable.
-1009 CLOSE_TOO_LARGE The endpoint is terminating the connection because a data frame was received that is too large.
-1010 Missing Extension The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't.
-1011 Internal Error The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
-1012 Service Restart The server is terminating the connection because it is restarting. [Ref]
-1013 Try Again Later The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients. [Ref]
-1014 Reserved for future use by the WebSocket standard.
-1015 TLS Handshake Reserved. Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).
-1016–1999 Reserved for future use by the WebSocket standard.
-2000–2999 Reserved for use by WebSocket extensions.
-3000–3999 Available for use by libraries and frameworks. May not be used by applications. Available for registration at the IANA via first-come, first-serve.
-4000–4999 Available for use by applications.
+To learn more, see here: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Properties
+ Source
+Edit
+
+
+
ReadyState = enum
+ Connecting = 0 , Open = 1 , Closing = 2 , Closed = 3
+
Source
-Edit
+Edit
-
WebSocket = object of WebSocketObj
+
WebSocket = ref object of EventTarget
+ url * : cstring
+ protocol * : cstring
+ readyState * : ReadyState
+ onopen * : proc ( event : Event )
+ onclose * : proc ( event : CloseEvent )
+ onmessage * : proc ( event : MessageEvent )
+
Source
-Edit
+Edit
@@ -1342,50 +1363,98 @@
-proc openws ( url : cstring ) : WebSocket {. importcpp : "new WebSocket(#)"
.}
+proc openws ( url : cstring ) : WebSocket {. importcpp : "new WebSocket(#)" , deprecated
.}
Source
-Edit
+Edit
proc openws ( url : string ; protocols : seq [ string ] ) : WebSocket {.
+ importcpp : "new WebSocket(#,@)" , deprecated
.}
+
+
+ Source
+Edit
+
+
+proc newWebSocket ( url : cstring ) : WebSocket {. importcpp : "new WebSocket(#)"
.}
+
+
+ Source
+Edit
+
+
+proc newWebSocket ( url : cstring ; protocol : cstring ) : WebSocket {.
importcpp : "new WebSocket(#,@)"
.}
Source
+Edit
+
+
+proc newWebSocket ( url : cstring ; protocols : seq [ cstring ] ) : WebSocket {.
+ importcpp : "new WebSocket(#,@)"
.}
+
+
+ Source
+Edit
+
+
+proc addEventListener [ ] ( et : EventTarget ; ev : cstring ;
+ cb : proc ( ev : MessageEvent | CloseEvent ) )
+
+
+ Source
+Edit
+
+
+proc send ( socket : WebSocket ; data : cstring )
+
+
+ Source
-Edit
+Edit
-proc send ( ws : WebSocket ; data : cstring ) {. importcpp
.}
+proc close ( socket : WebSocket )
Source
-Edit
+Edit
-proc close ( ws : WebSocket ) {. importcpp
.}
+proc close [ ] ( socket : WebSocket ; code : StatusCode | Natural )
Source
-Edit
+Edit
-proc close [ ] ( ws : WebSocket ; code : StatusCode | Natural ; reason : cstring ) {. importcpp
.}
+proc close [ ] ( socket : WebSocket ; code : StatusCode | Natural ; reason : cstring )
Source
-Edit
+Edit
@@ -1398,7 +1467,7 @@
- Made with Nim. Generated: 2017-03-11 20:37:46 UTC
+ Made with Nim. Generated: 2017-03-25 22:02:17 UTC