forked from mongolab/tractorpush-server
/
index.html
152 lines (133 loc) · 6.78 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
<!doctype html>
<!--
Copyright 2012 ObjectLabs Corp.
LICENSE
Code licensed under the Apache License, Version 2.0 (the "Apache
License"); you may not use this file except in compliance with
the Apache License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the Apache License is distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the Apache License for the specific language governing
permissions and limitations under the Apache License.
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/
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
-->
<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='http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js'
data-dojo-config='async: true'>
</script>
<script src='/socket.io/socket.io.js'></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>
<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 is a demonstration of a socket.io client that accepts two message streams from a server asynchronously. The left box updates on the arrival of the 'all messages' stream: simple, array, or complex. The right box updates from a message stream of only 'complex' type. The streams are independent but draw from the same source.
<p> The server is node.js running socket.io. It reads from a capped MongoDB database with a tailable cursor. A secondary set of servers (it happens to be in Ruby) originally wrote to the database.
<p> Note: Sequence numbers may not be unique.
<p> The node.js and Ruby components are running on Heroku's Celedon Cedar stack. The MongoDB database is hosted at MongoLab. https://github.com/mongolab/tractorpush-server for more information.
<p> Original Demo: 2012 March
<p> LICENSE Code licensed under the Apache License, Version 2.0 (the "Apache
License"); you may not use this file except in compliance with
the Apache License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
<p> Unless required by applicable law or agreed to in writing, software
distributed under the Apache License is distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the Apache License for the specific language governing
permissions and limitations under the Apache License.
<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>