Skip to content

Commit

Permalink
update readme and docs following pr
Browse files Browse the repository at this point in the history
  • Loading branch information
stisa committed Mar 25, 2017
1 parent c4f4c9b commit 7104cf7
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 170 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

22 changes: 10 additions & 12 deletions docs/examples/ex1.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="description" content="Examples for websockets">
<meta name="description" content="Examples for jswebsockets">
<meta name="author" content="stisa">
<link rel="stylesheet" href="http://stisa.space/css/main.css">
<link rel="stylesheet" href="http://stisa.space/css/prism.css">
Expand All @@ -27,7 +27,7 @@ <h3>Menu</h3>
<a href="/projects/">Projects</a>
<a href="/about/">About Me</a>
<br/>
<a href="/websockets/">websockets</a>
<a href="/jswebsockets/">jswebsockets</a>
</div>
</header>
<section class="content">
Expand All @@ -40,19 +40,17 @@ <h2>Example: ex1</h2>
<h2>Code</h2>
<pre><code class="language-nim">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)
</code></pre>
</section>
</section>
Expand Down
89 changes: 13 additions & 76 deletions docs/examples/ex1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
8 changes: 4 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>websockets</title>
<meta name="description" content="websockets">
<title>jswebsockets</title>
<meta name="description" content="jswebsockets">
<meta name="author" content="stisa">
<link rel="stylesheet" href="http://stisa.space/css/main.css">
<link rel="apple-touch-icon-precomposed" href="http://stisa.space/favicon-152.png">
Expand All @@ -30,14 +30,14 @@ <h3>Menu</h3>

</header>
<section class="content">
<h2>Examples for websockets</h2>
<h2>Examples for jswebsockets</h2>
<ul>
<li>
<a href="examples/ex1.html">Example: ex1</a>
</li>

</ul>
<h2><a href="jswebsockets.html">Docs for websockets</a></h2>
<h2><a href="jswebsockets.html">Docs for jswebsockets</a></h2>
</section>
</body>

Expand Down
Loading

0 comments on commit 7104cf7

Please sign in to comment.