API Version: 6.5
/* Enable the chat subsystem */
IPCortex.PBX.enableChat(
/* Provide a callback for new rooms */
function (ourRoom) {
/* Add an update listener to each new room */
ourRoom.addListener('update', function (room) {
/* Inspect new messages and echo ... */
room.messages.forEach(function (message) {
console.log(message.cN + ' has decreed: ' + message.msg);
/* ... except my own messages */
if (!message.own)
room.post('Apparently you decreed: ' + message.msg);
});
});
}
);
IPCortex.PBX.enableChat()
is a function taking up to two callbacks; the first of which we have provided here and the second one we have omitted as it deals with chat presence data that does not apply to this sample.Room
object provided to our listener callback has an array of new messages as a property so we can use Array.forEach()
to iterate over these.