I have a node.js server application with the following setup :
var express = require('express');
var io = require('socket.io');
var http = require('http');
var app = express();
app.use(express.static('public'));
var server = http.createServer(app);
io = io.listen(server);
io.on('connection', function(socket){
console.log('a user is connected');
});
device.on('disconnect', function() {
console.log('we got disconnected! :( ');
io.emit('deviceDisconnection');
});
Device here is a Bluetooth connected device. And, client side, I have a AngularJS application with the following event subscription declared in the controller of the application:
var appFront = angular.module(appFront , [])
.controller('mainController', ['$scope', '$http', function($scope,$http) {
var socket = io();
socket.on('deviceDisconnection', function(){
$scope.connected = 'TRUE';
});
}]);
And sure in the view, I have the following binding:
<div class="row">
<p>{{connected}}</p>
</div>
The issue is that the change is not really "real time". I mean, the connected value is probably changed in the scope but there is a need to do an action on the page (button clic) to make the view update with the right value. If I'm not doing anything on the page the value is not refreshed.
I probably forgot something.. But I have no clue about what..