Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic node broadcast message updated

  • Loading branch information...
commit ddc56c840827912b65dd48f10b86a26caac5dce5 1 parent bfb7b79
@adamcbrewer authored
View
2  .gitignore
@@ -1,2 +1,2 @@
-node_modules/*
+node/node_modules/
.DS_Store
View
16 node/public/assets/js/script.js
@@ -0,0 +1,16 @@
+(function (App) {
+
+ App = App || {};
+
+ //
+ // Socket.io Listeners
+ //
+ // =========================================
+ //
+ App.socket.on('broadcast', function (data) {
+
+ console.log(data);
+
+ });
+
+}(App));
View
18 node/server.js
@@ -4,8 +4,8 @@ var http = require('http'),
express = require('express'),
handlebars = require('handlebars'),
- config = require('./config.js'),
- Client = require('./models/client.js'),
+ config = require(__dirname + '/config.js'),
+ Client = require(__dirname + '/models/client.js'),
server = express(),
serverInst = http.createServer(server),
@@ -36,6 +36,7 @@ var http = require('http'),
this.clients.push(client);
console.log('-- LOG: The connected clients are: ' + this.clients.length);
+ this.broadcast({ message: 'hello you!'} , client, true);
},
@@ -83,11 +84,11 @@ var http = require('http'),
// We can send the default 'all' data to eveybody if we don't
// specify anything specifically for the original client
var dataClient = data.client || data.all;
- client.socket.emit('update stats', { results: dataClient });
+ client.socket.emit('broadcast', { results: data });
}
// Send to everyone
- client.socket.broadcast.emit('update stats', { results: data.all });
+ client.socket.broadcast.emit('broadcast', { results: data });
}
},
@@ -101,7 +102,7 @@ var http = require('http'),
//
loadTemplate: function (templateFile) {
- var source = fs.readFileSync('./view/'+ templateFile, 'utf8', function (err, html) {
+ var source = fs.readFileSync(__dirname + '/view/'+ templateFile, 'utf8', function (err, html) {
if (err) throw err;
return html;
});
@@ -118,9 +119,11 @@ var http = require('http'),
// to retreive the account changeset.
serverInst.listen(config.serverPort);
-var publicDir = __dirname + 'public',
+var publicDir = __dirname + '/public',
assetsDir = publicDir + '/assets';
+console.log(assetsDir);
+
// Route all our requested assets to the public assets directory
server.use('/assets', express.static(assetsDir));
@@ -129,7 +132,8 @@ server.get('/*', function (req, res) {
var source = Server.loadTemplate('layout.tmpl'),
template = handlebars.compile(source),
view = template({
- basePath: config.basePath
+ basePath: config.basePath,
+ siteurl: config.basePath + ':' + config.serverPort
});
res.send(view);
View
17 node/view/layout.tmpl
@@ -7,7 +7,6 @@
<meta name="description" content="">
<meta name="keywords" content="">
-
</head>
<body>
@@ -19,19 +18,29 @@
</header> <!-- #header -->
+ <section role="main" id="content">
+
+ <div id="floor" class="cf">
+
+ </div>
+
+ </section> <!-- #content -->
+
+ <footer id="footer">
+
+ </footer> <!-- #footer -->
+
</div> <!-- #wrapper -->
<script src="/socket.io/socket.io.js"></script>
<script>
var App = {
socket: io.connect('{{ basePath }}'),
- channels: {
- stats: io.connect('{{ basePath }}/stats')
- },
basePath: '{{ basePath }}'
};
</script>
+ <script src="{{ siteurl }}/assets/js/script.js"></script>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.