Universal Messaging 10.5 | Developer Guide | Web Client APIs | Web Developer's Guide for Javascript | Web Client Development in JavaScript | Publish/Subscribe Tasks | Publishing Events to a Channel
 
Publishing Events to a Channel
Once the session has been established with the Universal Messaging realm server, and a Universal Messaging Channel object has been created, a new Universal Messaging Event object must be constructed to use in the publish call being made on the channel.
Note that in this example code, we also create a Universal Messaging Event Dictionary object for our Universal Messaging Event before publishing it:

var mySession = Nirvana.createSession();
var myChannel = mySession.getChannel("/tutorial/sandbox");
var myEvent = Nirvana.createEvent();
var myDict = myEvent.getDictionary();
myDict.putString("demoMessage", "Hello World");
myChannel.publish(myEvent);
Note that the publish call is asynchronous; it returns immediately, allowing single-threaded JavaScript clients to continue processing.
To enable the developer to know when a publish call has completed, any user function assigned as a callback for the channel's observable event Nirvana.Observe.PUBLISH will be invoked, with the a string value of "OK" (which indicates the publish was successful):

function publishCB(responseString) {
console.log("Publish attempt: " + responseString);
}
myChannel.on(Nirvana.PUBLISH, publishCB);
myChannel.publish(myEvent);