Skip to content
This repository was archived by the owner on Oct 5, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/templates/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"tinymce-dist": "4.3.12",
"vkbeautify": "*",
"ml-highcharts-ng": "~0.0.11",
"view-file-ng": "^0.1.1"
"view-file-ng": "^0.1.1",
"socket.io-client": "^1.7.2",
"angular-socket-io": "^0.7.0"
},
"overrides": {
"angular-highlightjs": {
Expand All @@ -46,6 +48,11 @@
"main": [
"vkbeautify.js"
]
},
"socket.io-client": {
"main": [
"dist/socket.io.js"
]
}
},
"devDependencies": {
Expand Down
16 changes: 16 additions & 0 deletions app/templates/node-server/node-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ if (options.nodeJsCertificate) {
server = http.createServer(app);
}

var io = require('socket.io')(server);
io.on('connection', function(socket){
// console.log('a user connected');

// io.emit() sends a message to client on the 'server' channel
// io.emit('server', 'hi client');
socket.on('disconnect', function(){
// console.log('user disconnected');
});
socket.on('client', function(val){
// listening for message from client
// console.log('client', val);
});
});


server.listen(port, function() {
console.log('Express server listening on port ' + port);
console.log('env = ' + app.get('env') +
Expand Down
1 change: 1 addition & 0 deletions app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"passport": "^0.3.2",
"passport-local": "^1.0.0",
"q": "^1.4.1",
"socket.io": "^1.7.3",
"underscore": "^1.8.3",
"www-authenticate": "^0.6.2"
},
Expand Down
3 changes: 3 additions & 0 deletions app/templates/ui/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

// top-level state
'app.root'

//socket io
, 'btford.socket-io'
]);

}());
25 changes: 22 additions & 3 deletions app/templates/ui/app/root/root.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
.controller('RootCtrl', RootCtrl);

RootCtrl.$inject = ['messageBoardService', 'userService', '$scope',
'$state', 'appConfig'];
'$state'
, 'appConfig'
, 'socket'
];

function RootCtrl(messageBoardService, userService, $scope,
$state, appConfig) {
function RootCtrl(messageBoardService, userService, $scope
, $state
, appConfig
, socket
) {

var rootCtrl = this;
rootCtrl.currentYear = new Date().getUTCFullYear();
Expand All @@ -17,12 +23,25 @@

$scope.$watch(userService.currentUser, function(newValue) {
rootCtrl.currentUser = newValue;
// sample code to send message to server
if (newValue) {
socket.emit('client', newValue);
}
});

$scope.$watch(function() {
return $state.current.name;
}, function(newValue) {
rootCtrl.currentState = newValue;
});


$scope.$on('socket:server', function (event, data) {
// event: just contains description of the event
// data: contains the message
console.log('event', event);
console.log('data', data);
});

}
}());
12 changes: 12 additions & 0 deletions app/templates/ui/app/socket/socket.factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function () {
'use strict';

angular.module('app')
.factory('socket', ['socketFactory', function (socketFactory) {
var mySocket = socketFactory();
mySocket.forward('server');
return mySocket;
}])
;

}());