Skip to content

Commit 54bdbf4

Browse files
committed
first commit
0 parents  commit 54bdbf4

File tree

16 files changed

+339
-0
lines changed

16 files changed

+339
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules
3+
dump.rdb
4+
npm-debug.log
5+
tmp
6+
client/static/assets

.nodemonignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore file for Nodemon: https://github.com/remy/nodemon
2+
# Install with 'npm install -g nodemon' then start your app with 'nodemon app.js'
3+
# From then on, all changes you make to /server will cause your app to automatically restart
4+
5+
/client/*
6+
./README.md
7+
.git

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Welcome to your new realtime app

app.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// My SocketStream 0.3 app
2+
3+
var http = require('http'),
4+
ss = require('socketstream');
5+
6+
// Define a single-page client called 'main'
7+
ss.client.define('main', {
8+
view: 'app.html',
9+
css: ['libs/reset.css', 'app.css'],
10+
code: ['libs/jquery.min.js', 'app'],
11+
tmpl: '*'
12+
});
13+
14+
// Serve this client on the root URL
15+
ss.http.route('/', function(req, res){
16+
res.serveClient('main');
17+
});
18+
19+
// Use server-side compiled Hogan (Mustache) templates. Others engines available
20+
ss.client.templateEngine.use(require('ss-hogan'));
21+
22+
// Minimize and pack assets if you type: SS_ENV=production node app.js
23+
if (ss.env === 'production') ss.client.packAssets();
24+
25+
// Start web server
26+
var server = http.Server(ss.http.middleware);
27+
server.listen(3000);
28+
29+
// Start SocketStream
30+
ss.start(server);

client/code/app/app.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* QUICK CHAT DEMO */
2+
3+
// Delete this file once you've seen how the demo works
4+
5+
// Listen out for newMessage events coming from the server
6+
ss.event.on('newMessage', function(message) {
7+
8+
// Example of using the Hogan Template in client/templates/chat/message.jade to generate HTML for each message
9+
var html = ss.tmpl['chat-message'].render({
10+
message: message,
11+
time: function() { return timestamp(); }
12+
});
13+
14+
// Append it to the #chatlog div and show effect
15+
return $(html).hide().appendTo('#chatlog').slideDown();
16+
});
17+
18+
// Show the chat form and bind to the submit action
19+
$('#demo').on('submit', function() {
20+
21+
// Grab the message from the text box
22+
var text = $('#myMessage').val();
23+
24+
// Call the 'send' funtion (below) to ensure it's valid before sending to the server
25+
return exports.send(text, function(success) {
26+
if (success) {
27+
return $('#myMessage').val('');
28+
} else {
29+
return alert('Oops! Unable to send message');
30+
}
31+
});
32+
});
33+
34+
// Demonstrates sharing code between modules by exporting function
35+
exports.send = function(text, cb) {
36+
if (valid(text)) {
37+
return ss.rpc('demo.sendMessage', text, cb);
38+
} else {
39+
return cb(false);
40+
}
41+
};
42+
43+
44+
// Private functions
45+
46+
var timestamp = function() {
47+
var d = new Date();
48+
return d.getHours() + ':' + pad2(d.getMinutes()) + ':' + pad2(d.getSeconds());
49+
};
50+
51+
var pad2 = function(number) {
52+
return (number < 10 ? '0' : '') + number;
53+
};
54+
55+
var valid = function(text) {
56+
return text && text.length > 0;
57+
};

client/code/app/entry.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This file automatically gets called first by SocketStream and must always exist
2+
3+
// Make 'ss' available to all modules and the browser console
4+
window.ss = require('socketstream');
5+
6+
ss.server.on('disconnect', function(){
7+
console.log('Connection down :-(');
8+
});
9+
10+
ss.server.on('reconnect', function(){
11+
console.log('Connection back up :-)');
12+
});
13+
14+
ss.server.on('ready', function(){
15+
16+
// Wait for the DOM to finish loading
17+
jQuery(function(){
18+
19+
// Load app
20+
require('/app');
21+
22+
});
23+
24+
});

client/code/libs/jquery.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/css/app.css

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* Example CSS file */
2+
3+
/* Main */
4+
5+
body,
6+
html {
7+
height: 100%;
8+
}
9+
body {
10+
font: normal 1em sans-serif;
11+
background: linear-gradient(top, #eeeeee, #ffffff);
12+
text-align: center;
13+
}
14+
p {
15+
margin-bottom: 1em;
16+
}
17+
a {
18+
color: #000a68;
19+
}
20+
h1 {
21+
font-size: 1.5em;
22+
font-weight: normal;
23+
margin: 1.5em;
24+
color: #333;
25+
text-shadow: 1px 1px 2px white;
26+
}
27+
#content {
28+
padding: 50px;
29+
}
30+
31+
/* Quick Chat Demo */
32+
33+
#demo {
34+
border: 1px solid #ccc;
35+
width: 700px;
36+
text-align: left;
37+
margin: 50px auto;
38+
padding: 15px;
39+
border-radius: 5px;
40+
}
41+
#demo h3 {
42+
font-size: 1.0em;
43+
font-weight: normal;
44+
}
45+
#demo h5 {
46+
padding: 5px 0;
47+
color: #666;
48+
font-weight: normal;
49+
font-size: 0.8em;
50+
}
51+
#demo #myMessage,
52+
#demo #chatlog {
53+
border: none;
54+
box-shadow: inset 0 0 2px #777;
55+
border-radius: 5px;
56+
}
57+
#demo #myMessage {
58+
width: 690px;
59+
padding: 5px;
60+
}
61+
#demo #chatlog {
62+
width: 700px;
63+
background-color: white;
64+
margin: 5px 0;
65+
}
66+
#demo #chatlog p {
67+
font-size: 0.9em;
68+
color: #000a68;
69+
padding: 3px 9px;
70+
margin: 0;
71+
}
72+
#demo #chatlog p:first-child {
73+
padding-top: 9px;
74+
}
75+
#demo #chatlog p:last-child {
76+
padding-bottom: 9px;
77+
}
78+
#demo #chatlog span.time {
79+
color: #666;
80+
float: right;
81+
width: 70px;
82+
text-align: right;
83+
font-size: 0.7em;
84+
}

client/css/libs/reset.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* http://meyerweb.com/eric/tools/css/reset/
2+
v2.0 | 20110126
3+
License: none (public domain)
4+
*/
5+
6+
html, body, div, span, applet, object, iframe,
7+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
8+
a, abbr, acronym, address, big, cite, code,
9+
del, dfn, em, img, ins, kbd, q, s, samp,
10+
small, strike, strong, sub, sup, tt, var,
11+
b, u, i, center,
12+
dl, dt, dd, ol, ul, li,
13+
fieldset, form, label, legend,
14+
table, caption, tbody, tfoot, thead, tr, th, td,
15+
article, aside, canvas, details, embed,
16+
figure, figcaption, footer, header, hgroup,
17+
menu, nav, output, ruby, section, summary,
18+
time, mark, audio, video {
19+
margin: 0;
20+
padding: 0;
21+
border: 0;
22+
font-size: 100%;
23+
font: inherit;
24+
vertical-align: baseline;
25+
}
26+
/* HTML5 display-role reset for older browsers */
27+
article, aside, details, figcaption, figure,
28+
footer, header, hgroup, menu, nav, section {
29+
display: block;
30+
}
31+
body {
32+
line-height: 1;
33+
}
34+
ol, ul {
35+
list-style: none;
36+
}
37+
blockquote, q {
38+
quotes: none;
39+
}
40+
blockquote:before, blockquote:after,
41+
q:before, q:after {
42+
content: '';
43+
content: none;
44+
}
45+
table {
46+
border-collapse: collapse;
47+
border-spacing: 0;
48+
}

client/static/favicon.ico

1.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)