Description
Hello Bran,
I am trying to integrate your solution here to the Rails integrated realtime-rails solution from Mike Atlas
http://mikeatlas.github.io/realtime-rails/
the challenge i am running into is that the socket interface is already being created outside of the angular code:
<script type='text/javascript'>
window.realtime = {};
window.realtime.messageQueue = [];
window.realtime.enabled = false;
I have tried to point. the socket in your service declaration to window.realtime.socketIo (my appis called headcount)
https://github.com/dreadstar/headcount_app5/blob/master/app/assets/javascripts/angular/services.js.coffee (although this is a coffescript file i am actually forcing javascript)
headcount.factory('socket', function ($rootScope) {
// var socket = io.connect();
// var socket = io.connect("http://localhost:5001");
var socket = window.realtime.socketIo;
return {
on: function (eventName, callback) {
socket.on(eventName, function () {
var args = arguments;
$rootScope.$apply(function () {
callback.apply(socket, args);
});
});
},
emit: function (eventName, data, callback) {
socket.emit(eventName, data, function () {
var args = arguments;
$rootScope.$apply(function () {
if (callback) {
callback.apply(socket, args);
}
});
})
}
};
});
My controller has the following additions to replicate your your example. it is written in coffescript:
https://github.com/dreadstar/headcount_app5/blob/master/app/assets/javascripts/angular/controllers/LocationIndexCtrl.js.coffee
@headcount.controller 'LocationIndexCtrl', ['$scope', '$location', '$http','socket', ($scope, $location, $http, socket) ->
$scope.locs[data.msg.obj.id].current_state= data.msg.obj.current_state
$scope.locs[data.msg.obj.id].fanscnt= data.msg.obj.fanscnt
console.log data
When i switch the EventName to 'realtime_msg' on the server, i can see that my messages are getting to the browser.
you can see the latest version of my code
https://github.com/dreadstar/headcount_app5
Any help would be appreciated.
Thanks,
Tyrone