Synchronize AngularJS scope between clients
For interactive web applications that are to be run on multiple devices at the same time, synchroscope makes it very easy to share scope variables.
Function.prototype.bind which is unavailable in some older browsers (such as iOS5 Safari).
Please use es5-shim if you want to target those.
Symlink or copy
client/sync.js to your Angular project, and include it like this.
Then, declare a dependency on
ask for the
$ync service, and just call it:
angularmodule'myApp' 'synchroscope'controller'MyController'$scopehello = 'initial data'$scopeworld = 'for synchroscope demo'$scopefoo = 'TRY IT!'var keys = 'hello' 'world' // keys that you want to sharevar room = 'test' // room namevar sync = $ync$scope keys room
As soon as you call
$ync, the keys
world will be
synchronized across all browser clients.
Let's assume that
io is a Socket.IO server object obtained by something like this:
var io = require('socket.io').listen(server). Just add this line to your server: