Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 06aacc9e42
Fetching contributors…

Cannot retrieve contributors at this time

158 lines (138 sloc) 7.19 kB
<!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: #fff; 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>
<!-- Background -->
<div class="backimg">
<img class="fillscreen" alt='Tractor Engine, Copyright 2011 Ben Wen CC
BY-SA 3.0' src="http://jux-user-files-prod.s3.amazonaws.com/2012/01/27/18/27/18/956/IMG_2484.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 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>
Jump to Line
Something went wrong with that request. Please try again.