-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
191 lines (159 loc) · 8.39 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
<!doctype html>
<!--
Copyright 2014 ObjectLabs Corp.
MIT License
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
TITLE
Tractor Push: Node.js, socket.io, Ruby, MongoDB tailed cursor
demo
index.html - main client code. Opens up a socket.io connection
to server and displays returned data dynamically.
by Ben Wen, ObjectLabs
ObjectLabs is the maker of MongoLab.com a cloud MongoDb-as-a-Service
provider.
-->
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta content='text/html;charset=utf-8'/>
<link href='http://fonts.googleapis.com/css?family=Arimo:400,700' rel='stylesheet' type='text/css' />
<style>
body { background-color: #ddd; font-family: 'Arimo', helvetica neue, arial, sans-serif; margin-left: 15px; color: #000}
h1 { font-size: 50px; margin: 5px; float: right; text-align: right; color: #d33 }
h2 { font-size: 40px; margin: 5px; float: right; text-align: right }
h3 { font-size: 35px; margin-top: 20px; margin-left: 10px; text-align: center}
li { font-size: 20px; margin-top: 0px; margin-left: 5px }
pre { font-family: arimo, helvetica neue, arial, sans-serif }
.container { position: relative; padding: 10px; height: 525px; width: 450px; }
.content { background-color: white; position: absolute; width: 350px; border: solid 1px #99c; margin: 5px; height: 525px; -moz-box-shadow: 10px 10px 5px #322; -webkit-box-shadow: 2px 3px 5px #322; box-shadow: 10px 10px 5px #322; }
.innercontent { margin: 1%; padding: 2px; background-color: white; }
.titlebox { width: 400px; float: right; padding: 5px; border: solid 1px #99c; background-color: #fff; }
.descript { width: 700px; position: relative; padding: 25px; margin: 5px; border: solid 1px #99c; background-color: white; -moz-box-shadow: 10px 10px 5px #322; -webkit-box-shadow: 2px 3px 5px #322; box-shadow: 10px 10px 5px #322; }
.backimg { width: 100%; position: fixed; left: 0px; top: 0px; z-index: -1; }
.fillscreen { width: 100%; }
</style>
<title>Tractor Push: MongoDB Tailable Cursor + Socket.IO demo</title>
<script src='/socket.io/socket.io.js'></script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js"
data-dojo-config='async: true'>
</script>
<script>
// require the dom resource
require(['dojo/dom', 'dojo/date/locale', 'dojo/domReady!'], function(dom) {
function dateFormat(date, format) { return dojo.date.locale.format( date, {selector: 'date', datePattern:format });}
function strip_id(key, value) { return key == '_id' ? undefined : value; }
var socket = io.connect('/');
socket.on('all', function (data) {
oneone = dom.byId('oneone');
oneone.innerHTML = 'Message type: ' + data.messagetype;
onetwo = dom.byId('onetwo');
onetwo.innerHTML = 'Sequence number: ' + data.ordinal;
onethree = dom.byId('onethree');
thisDate = new Date (data.time);
onethree.innerHTML = 'Timestamp: ' + dateFormat(thisDate, 'MMMM d yyyy, h:mm:ss a z');
onefour = dom.byId('onefour');
onefour.innerHTML = '<pre> Entire message: ' + JSON.stringify(data, strip_id, 2) + '</pre>';
});
socket.on('complex', function (data) {
twoone = dom.byId('twoone');
twoone.innerHTML = 'Message type: ' + data.messagetype;
twotwo = dom.byId('twotwo');
twotwo.innerHTML = 'Sequence number: ' + data.ordinal;
twothree = dom.byId('twothree');
thisDate = new Date (data.time);
twothree.innerHTML = 'Timestamp: ' + dateFormat(thisDate, 'MMMM d yyyy, h:mm:ss a z');
twofour = dom.byId('twofour');
twofour.innerHTML = '<pre> Entire message: ' + JSON.stringify(data, strip_id, 2) + '</pre>';
});
});
</script>
</head>
<body>
<!-- Background -->
<div class="backimg">
<img class="fillscreen" alt='Tractor Engine, Copyright 2011 Ben Wen CC
BY-SA 3.0' src="http://blog.mongolab.com/wp-content/uploads/2012/03/tractor_engine_1600_Web.jpg"/>
</div>
<div class="titlebox">
<h1>Tractor Push</h1>
<h2>
MongoDB <br/>
Tailable <br/>
Cursor and <br/>
Socket.IO Demo <br/>
from MongoLab
</h2>
</div>
<div class='container'>
<div class='content' style='top: 0; left: 0'>
<div class='innercontent'>
<h3>All messages </h3>
<ul>
<li id='oneone'>--</li>
<li id='onetwo'>--</li>
<li id='onethree'>--</li>
<li id='onefour'>--</li>
</ul>
</div>
</div>
<div class='content' style='top: 0; left: 400px'>
<div class='innercontent'>
<h3>Complex only</h3>
<ul>
<li id='twoone'>--</li>
<li id='twotwo'>--</li>
<li id='twothree'>--</li>
<li id='twofour'>--</li>
</ul>
</div>
</div>
</div>
<div class='descript'>
This demonstration of a Socket.IO client accepts two message streams from a server asynchronously. The left box is updated on the arrival of the 'all messages' stream. Messages can be one of three types: simple, array, or complex. The right box is updated from a message stream of only the 'complex' type. The streams are independent but draw from the same source.
<p> The server is running Node.js and uses Socket.IO. It reads from a MongoDB capped collection using a tailable cursor. The tailable cursor allows the server to pick up changes to the database dynamically. A separate writer process writes to the database.
<p> The server components have been tested on Heroku's Celedon Cedar stack and Joyent's Cloud. The MongoDB database is hosted at MongoLab. Code at<br/>
<a href="https://github.com/mongolab/tractorpush-server">https://github.com/mongolab/tractorpush-server</a>,<br/>
<a href="https://github.com/mongolab/tractorpush-writer-ruby">https://github.com/mongolab/tractorpush-writer-ruby</a>, and<br/>
<a href="https://github.com/mongolab/tractorpush-writer-node">https://github.com/mongolab/tractorpush-writer-node</a>.<br/>
<p> Original Demo: 2012 March. Updated 2013 March. Updated 2014 September.
<p>
Copyright 2012, 2013, 2014 ObjectLabs Corp.
<p> MIT License
<p> Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
<p> The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
<p> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<p> Non-code content licensed under Creative Commons
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) at
http://creativecommons.org/licenses/by-sa/3.0/
</div>
</body>
</html>