Skip to content

Data Binding with WebSync 3.3

Anton Venema Nov 10, 2010 5:00:00 AM

Click me

One of the best new features of WebSync 3.3 is the ability to bind data to clients. By attaching client-specific details to the WebSync clients, developing a rich user experience is easier than ever.

Consider the case where a client receives a message published by another client. Previously, the receiving client would be able to see the ID of the publishing client, but nothing more. Now, if the publishing client binds a display name to itself before publishing, that display name is available to the receiving client with the message.

Publishing client:

.
fm.websync.client.init().connect().bind({
record: { key: 'displayName', value: 'John Doe' }
}).publish({
channel: '/test',
data: {
text: 'Good morning!'
}
});

Receiving client:

fm.websync.client.init().connect().subscribe({
channel: '/test',
onReceive: function(args) {
alert(args.publishingClient.boundRecords['displayName'] + ' says "' + args.data.text + '");
}
});

 

The same concept applies to the Subscribers extension. Previously, only the client IDs of a channel's subscribers were available to other subscribed clients. Now, any public bound data is also available, making it easy to build an informed user interface quickly and easily. Just access the boundRecords property on each of the client objects passed into subscribe.onSuccess and subscribe.onSubscribersChange.

Reimagine your live video platform