Last active
August 30, 2023 21:28
-
-
Save patrickbrandt/1cd98a02c42e9e22a5a9 to your computer and use it in GitHub Desktop.
Revisions
-
patrickbrandt revised this gist
Dec 8, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,7 +57,7 @@ app.use('/', routes); server.listen('3000'); ``` You can now emit socket.io events from any route handler (```./routes/index``` in this example): ```javascript var express = require('express'); var router = express.Router(); -
patrickbrandt revised this gist
Dec 8, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,7 +57,7 @@ app.use('/', routes); server.listen('3000'); ``` You can now emit socket.io events from any route handler (./routes/index in this example): ```javascript var express = require('express'); var router = express.Router(); -
patrickbrandt revised this gist
Nov 9, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ Socket.io integration between an Express and Angular app is a breeze. I'll outline the Express implementation first, then outline Angular integration. # Express + socket.io ## Reference socket.io in layout.jade -
patrickbrandt revised this gist
Nov 9, 2015 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -76,19 +76,19 @@ Create a service that wraps the socket.io global object: angular.module('example') .factory('io', ['$window', '$rootScope', function($window, $rootScope) { var _socket = $window.io('//localhost:3000'); return { on: function(eventType, cb) { _socket.on(eventType, function() { cb(); //NOTE: calling $apply will ensure that any model changes are reflected in the view $rootScope.$apply(); }); }, emit: function(eventType, data) { _socket.emit(eventType, data); } }; }]); ``` Use the io service in a controller: ```javascript -
patrickbrandt revised this gist
Nov 9, 2015 . 1 changed file with 12 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,18 +77,18 @@ angular.module('example') .factory('io', ['$window', '$rootScope', function($window, $rootScope) { var _socket = $window.io('//localhost:3000'); return { on: function(eventType, cb) { _socket.on(eventType, function() { cb(); //NOTE: calling $apply will ensure that any model changes are reflected in the view $rootScope.$apply(); }); }, emit: function(eventType, data) { _socket.emit(eventType, data); } }; }]); ``` Use the io service in a controller: ```javascript -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 12 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -77,18 +77,18 @@ angular.module('example') .factory('io', ['$window', '$rootScope', function($window, $rootScope) { var _socket = $window.io('//localhost:3000'); return { on: function(eventType, cb) { _socket.on(eventType, function() { cb(); //NOTE: calling $apply will ensure that any model changes are reflected in the view $rootScope.$apply(); }); }, emit: function(eventType, data) { _socket.emit(eventType, data); } }; }]); ``` Use the io service in a controller: ```javascript -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -80,7 +80,7 @@ angular.module('example') on: function(eventType, cb) { _socket.on(eventType, function() { cb(); //NOTE: calling $apply will ensure that any model changes are reflected in the view $rootScope.$apply(); }); }, -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ Include the following code in your app.js module (other standard Express module var express = require('express'); var http = require('http'); var io = require('socket.io'); var routes = require('./routes/index'); var app = express(); -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,6 +28,7 @@ Include the following code in your app.js module (other standard Express module var express = require('express'); var http = require('http'); var io = require('socket.io'); var routes = require('../routes/index'); var app = express(); @@ -52,6 +53,8 @@ io.on('connection', function(socket) { console.log('socket.io connection made'); }); app.use('/', routes); server.listen('3000'); ``` You can now emit socket.io events from any route handler: -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,11 +56,16 @@ server.listen('3000'); ``` You can now emit socket.io events from any route handler: ```javascript var express = require('express'); var router = express.Router(); router.post('/', function(req, res, next) { req.io.emit('some_event'); //do some stuff req.io.emit("some_other_event"); //we did some stuff - emit a related event }); module.exports = router; ``` #Angular + socket.io Create a service that wraps the socket.io global object: -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,8 +19,8 @@ html(ng-app="example") script(type='text/javascript' src='/angular-resource/angular-resource.js') script(type='text/javascript' src='/angular-route/angular-route.js') script(type='text/javascript' src='/javascripts/app.js') script(type='text/javascript' src='/javascripts/services.js') script(type='text/javascript' src='/javascripts/controllers.js') ``` ## Create socket.io middleware Include the following code in your app.js module (other standard Express module dependancies and middleware left out for brevity): -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Socket.io integration between and Express and Angular app is a breeze. I'll outl # Express + socket.io ## Reference socket.io in layout.jade ```npm install socket.io --save``` and then reference socket.io in your layout.jade file: ```jade doctype html html(ng-app="example") -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Socket.io integration between and Express and Angular app is a breeze. I'll outl # Express + socket.io ## Reference socket.io in layout.jade ```npm install socket.io --save``` and then reference in your layout.jade file: ```jade doctype html html(ng-app="example") -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -82,7 +82,7 @@ angular.module('example') }; }]); ``` Use the io service in a controller: ```javascript angular.module('example') .controller('MainCtrl', ['io', function(io) { -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -67,20 +67,20 @@ Create a service that wraps the socket.io global object: ```javascript angular.module('example') .factory('io', ['$window', '$rootScope', function($window, $rootScope) { var _socket = $window.io('//localhost:3000'); return { on: function(eventType, cb) { _socket.on(eventType, function() { cb(); //NOTE: calling $apply will ensure that any model changes are reflected in the client view $rootScope.$apply(); }); }, emit: function(eventType, data) { _socket.emit(eventType, data); } }; }]); ``` Use the service in a controller: ```javascript -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -66,8 +66,8 @@ router.post('/', function(req, res, next) { Create a service that wraps the socket.io global object: ```javascript angular.module('example') .factory('io', ['$window', '$rootScope', function($window, $rootScope) { var _socket = $window.io('//localhost:3000'); return { on: function(eventType, cb) { _socket.on(eventType, function() { -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,7 +72,8 @@ angular.module('example') on: function(eventType, cb) { _socket.on(eventType, function() { cb(); //NOTE: calling $apply will ensure that any model changes are reflected in the client view $rootScope.$apply(); }); }, emit: function(eventType, data) { -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,7 +73,7 @@ angular.module('example') _socket.on(eventType, function() { cb(); $rootScope.$apply(); //NOTE: calling $apply will ensure that any model changes are reflected in the client view }); }, emit: function(eventType, data) { _socket.emit(eventType, data); -
patrickbrandt revised this gist
Nov 6, 2015 . No changes.There are no files selected for viewing
-
patrickbrandt revised this gist
Nov 6, 2015 . No changes.There are no files selected for viewing
-
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 12 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,9 +57,9 @@ server.listen('3000'); You can now emit socket.io events from any route handler: ```javascript router.post('/', function(req, res, next) { req.io.emit('some_event'); //do some stuff req.io.emit("some_other_event"); //we did some stuff - emit a related event }); ``` #Angular + socket.io @@ -80,4 +80,14 @@ angular.module('example') } }; }]); ``` Use the service in a controller: ```javascript angular.module('example') .controller('MainCtrl', ['io', function(io) { this.state = 'something'; io.on('some_event', function() { this.state = 'something else'; }.bind(this)); }]); ``` -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,7 +62,7 @@ router.post('/', function(req, res, next) { req.io.emit("some other event - now that we've done stuff"); }); ``` #Angular + socket.io Create a service that wraps the socket.io global object: ```javascript angular.module('example') -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 20 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Socket.io integration between and Express and Angular app is a breeze. I'll outl ```npm install socket.io``` and then reference in your layout.jade file: ```jade doctype html html(ng-app="example") head title= title link(rel='stylesheet', href='/bootstrap/dist/css/bootstrap.css') @@ -61,4 +61,23 @@ router.post('/', function(req, res, next) { //do some stuff req.io.emit("some other event - now that we've done stuff"); }); ``` #Angluar + socket.io Create a service that wraps the socket.io global object: ```javascript angular.module('example') .factory('io', ['$window', '$rootScope', function($window, $rootScope) { var _socket = $window.io('//localhost:3000'); return { on: function(eventType, cb) { _socket.on(eventType, function() { cb(); $rootScope.$apply(); //NOTE: calling $apply will ensure that any model changes are reflected in the client view }); }, emit: function(eventType, data) { _socket.emit(eventType, data); } }; }]); ``` -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -59,6 +59,6 @@ You can now emit socket.io events from any route handler: router.post('/', function(req, res, next) { req.io.emit('some event'); //do some stuff req.io.emit("some other event - now that we've done stuff"); }); ``` -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -58,5 +58,7 @@ You can now emit socket.io events from any route handler: ```javascript router.post('/', function(req, res, next) { req.io.emit('some event'); //do some stuff req.io.emit('some other event - now that we\'ve done stuff'); }); ``` -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,4 +53,10 @@ io.on('connection', function(socket) { }); server.listen('3000'); ``` You can now emit socket.io events from any route handler: ```javascript router.post('/', function(req, res, next) { req.io.emit('some event'); }); ``` -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,7 +48,8 @@ app.use(function(req, res, next) { next(); }); io.on('connection', function(socket) { //log.info('socket.io connection made'); console.log('socket.io connection made'); }); server.listen('3000'); -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,4 +50,6 @@ app.use(function(req, res, next) { io.on('connection', function(socket) { log.info('socket.io connection made'); }); server.listen('3000'); ``` -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ html(ng-app="angular_example") script(type='text/javascript' src='/javascripts/services.js') ``` ## Create socket.io middleware Include the following code in your app.js module (other standard Express module dependancies and middleware left out for brevity): ```javascript var express = require('express'); var http = require('http'); -
patrickbrandt revised this gist
Nov 6, 2015 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,4 +21,33 @@ html(ng-app="angular_example") script(type='text/javascript' src='/javascripts/app.js') script(type='text/javascript' src='/javascripts/controllers.js') script(type='text/javascript' src='/javascripts/services.js') ``` ## Create socket.io middleware Include the following code in your app.js module (other standard Express module dependancies left out for brevity): ```javascript var express = require('express'); var http = require('http'); var io = require('socket.io'); var app = express(); /** * Create HTTP server. */ var server = http.createServer(app); /** * Setup custom app middleware */ /* setup socket.io */ io = io(server); app.use(function(req, res, next) { req.io = io; next(); }); io.on('connection', function(socket) { log.info('socket.io connection made'); }); ```
NewerOlder