-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
348 lines (286 loc) · 8.27 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html>
<head>
<title>eureca.io</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
<link href="css/darkstrap-v0.9.0.css" rel="stylesheet" media="screen">
<link href="css/prettify.css" rel="stylesheet" />
<style>
#content {
margin-top: 50px; }
form.well,
.shift-up {
margin-top: -19px; }
.span6 > .well {
margin-top: -19px; }
.ds-margin-top, h2 {
margin-top: 50px; }
.popovers .popover {
display: block;
float: left;
margin: 20px;
position: relative;
width: 260px;
}
</style>
</head>
<body data-spy="scroll" data-target=".navbar">
<a id="anchor-prez"></a><br />
<div class="container" id="content">
<div class="hero-unit">
<h1>eureca.io</h1>
<p>Author <a href="https://github.com/alaa-eddine">Alaa-eddine K.</a></p>
<p>a nodejs bidirectional RPC using engine.io or sockjs as transport layer</p>
</div>
<div class='page-header'>
<h1>Usage</h1>
<h2>Base example</h2>
<p>
here we setup a server that expose hello() function.<br />
we can call this function from a browser client or nodejs client.
</p>
</div>
<div class="row">
<div class="span6">
<h3 class="well">Server side</h3>
<div class="well">
<h4 class="label label-success"> express server </h4>
<pre class="prettyprint linenums language-javascript">
var express = require('express')
, app = express(app)
, server = require('http').createServer(app);
var EurecaServer = require('eureca.io').EurecaServer;
var eurecaServer = new EurecaServer();
eurecaServer.attach(server);
//functions under "exports" namespace will be exposed to client side
eurecaServer.exports.hello = function () {
console.log('Hello from client');
}
//------------------------------------------
//see browser client side code for index.html content
app.get('/', function (req, res, next) {
res.sendfile('index.html');
});
server.listen(8000);
</pre>
</div>
</div>
<div class="span6">
<h3 class="well">Client side</h3>
<div class="well">
<ul class="nav nav-tabs">
<li class="active"><a href="#bclient1" data-toggle="tab">Browser client</a></li>
<li><a href="#nclient1" data-toggle="tab">Nodejs client</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="bclient1">
<pre class="prettyprint linenums language-html">
<!doctype html>
<html>
<head>
<title>Engine.io test</title>
<script src="/eureca.js"></script>
</head>
<body>
<script>
var client = new Eureca.EurecaClient();
client.ready(function (proxy) {
proxy.hello();
});
</script>
</body>
</html>
</pre>
</div>
<div class="tab-pane" id="nclient1">
<pre class="prettyprint linenums language-javascript">
var EurecaClient = require('../../').EurecaClient;
var client = new EurecaClient({ uri: 'http://localhost:8000/' });
client.ready(function (proxy) {
proxy.hello();
});
</pre>
</div>
</div>
</div>
</div>
</div>
<div class='page-header'>
<h2>Calling server side functions from client and getting back result</h2>
</div>
<div class="row">
<div class="span6">
<h3 class="well">Server side</h3>
<div class="well">
<pre class="prettyprint linenums language-javascript">
// ... server initialisation
eurecaServer.exports.add = function (a, b) {
return a+b
}
//... other stuff
</pre>
</div>
</div>
<div class="span6">
<h3 class="well">Client side</h3>
<div class="well">
<pre class="prettyprint linenums language-javascript">
client.ready(function (proxy) {
proxy.add(10, 5).onReady(function(result) {
console.log('got result from server, 10+5=', result);
});
});
</pre>
</div>
</div>
</div>
<div class='page-header'>
<h2>Calling client side functions from server and getting back result</h2>
<p>
in this example, client will call ping() function on the server, then the server
well call pong() function on the client side<br />
<span class="label label-warning">important</span>
<b> client side functions need to be allowed first in the server side when creating the server object</b>
</p>
</div>
<div class="row">
<div class="span6">
<h3 class="well">Server side</h3>
<div class="well">
<pre class="prettyprint linenums language-javascript">
//we need to allow bar() function first
var eurecaServer = new EurecaServer({allow:['bar']});
// ... server initialisation
eurecaServer.exports.foo = function () {
var conn = this.connection;
var client = eurecaServer.getClient(conn.id);
console.log('called foo()');
client.bar();
}
//... other stuff
</pre>
</div>
</div>
<div class="span6">
<h3 class="well">Client side</h3>
<div class="well">
<pre class="prettyprint linenums language-javascript">
client.exports.bar = function ()
{
console.log('called bar()');
}
client.ready(function (proxy) {
proxy.foo();
});
</pre>
</div>
</div>
</div>
<div class='page-header'>
<h2>Namespaces</h2>
<p>
we can expose functions under namespaces if we want to organise them for example
</p>
</div>
<div class="row">
<div class="span6">
<h3 class="well">Server side</h3>
<div class="well">
<pre class="prettyprint linenums language-javascript">
// ... server initialisation
eurecaServer.exports.math = {
add = function (a, b) {
return a+b
},
sub = function (a, b) {
return a-b
}
}
//... other stuff
</pre>
</div>
</div>
<div class="span6">
<h3 class="well">Client side</h3>
<div class="well">
<pre class="prettyprint linenums language-javascript">
client.ready(function (proxy) {
proxy.math.add(10, 5).onReady(function(result) {
console.log('got result from server, 10+5=', result);
});
proxy.math.sub(10, 5).onReady(function(result) {
console.log('got result from server, 10-5=', result);
});
});
</pre>
</div>
</div>
</div>
<div class='page-header'>
<h2>TODO</h2>
<p>This documentation is not complete, will be updated with more examples</p>
</div>
</div> <!-- /container -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/prettify.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
/*
$("pre.language-javascript").snippet("javascript", {style:"pablo"});
$("pre.language-html").snippet("html", {style:"pablo"});
$('pre.prettyprint').css({'overflow':'auto', 'padding':'0px', 'padding-top':'20px'});
$('.linenums li').each(function(i){
var text = $(this).html();
$(this).html(text.replace(/\s/g, ' '));
$(this).html(text.replace(/\t/g, ' '));
$(this).css({'white-space':'nowrap', 'padding-left':'0px'})
});
*/
/* syntax highlight */
prettyPrint();
$('.linenums li span').each(function(i){
var text = $(this).html();
text = text.replace(/\s/g, ' ');
text.replace(/\t/g, ' ');
$(this).html(text);
$(this).css({'white-space':'nowrap'});
});
/*************************/
/* tabs
$('.ctabs a').click(function (e) {
e.preventDefault();
$(this).tab('show');
})
/*************************/
$("#style-toggle").click(function (e) {
e.preventDefault();
// Toggle <link> url
$link = $("link#darkstrap-link");
var href = $link.attr("href")
var css_url =
href.length > 0 ? "" : "css/darkstrap.css"
$link.attr("href", css_url);
// Toggle button text
$this = $(this);
var text = $this.text() == "Toggle Darkstrap" ?
"Toggle Bootstrap" : "Toggle Darkstrap";
$this.text(text);
});
});
</script>
<script type="text/javascript">
$(function () {
$("#tooltip-example").tooltip();
});
</script>
<script type="text/javascript">
$(function () {
$("#myCarousel").carousel();
});
</script>
</body>
</html>