Hi,
There is no ready method to exchange custom data between clients and live_updates.js provides no extension points that would allow you to add this functionality without modifying live_updates.js itself.
However, since live_updates.js is not a part of the official package, and the file itself is not too big, it should be not too difficult to modify it according to your needs.
Firstly, please check the latest version of live_updates.js from my post here Live updates addEvent error
In order to send custom data, you’ll need to expose the Faye client (https://faye.jcoglan.com/) used in live_updates.js to the rest of your app so you could call it from code.
It can be done here:
live_updates.js, line:26
var client = new Faye.Client(url);
client.subscribe('/update', function (message) {
self.applyChanges(JSON.parse(message));
});
this.attachEvent("onLocalUpdate", function (data) {
client.publish('/broadcast', JSON.stringify(data));
});
You can add something following:
var client = new Faye.Client(url);
client.subscribe('/update', function (message) {
self.applyChanges(JSON.parse(message));
});
this.attachEvent("onLocalUpdate", function (data) {
client.publish('/broadcast', JSON.stringify(data));
});
// added two methods of the scheduler object:
scheduler.publish = function(channel, message){
client.publish(channel, message);
};
scheduler.subscribe = function(channel, callback){
client.subscribe(channel, callback);
};
Then in your app you could send the data to all connected clients:
scheduler.publish("/sections", JSON.stringify({
collection: "users",
value: [...]
}));
And receive it
scheduler.subscribe("/sections", function(message){
var action = JSON.parse(message);
scheduler.updateCollection(action.collection, action.value);
// or reload collections from the server
}));
I believe you won’t have to change anything on the server in order to make it work.
One thing to keep in mind is that the page that sends the message using ‘publish’ will also receive it’s own message in ‘subscribe’.