var msgobj = {};
// DUMMY
easyrtc.sendMessageToRoom(req.params.roomid, msgobj, function(err){});});
var destRoom="training_room", msgType="monsterAttackDrill", msgData= { "color":"green", "height":12, "skin":"scaley"}; easyrtc.sendDataWS({"targetRoom":destRoom}, msgType, msgData, function(reply) { if (reply.msgType === "error") { easyrtc.showError(reply.msgData.errorCode, reply.msgData.errorText); } else { ... }});
/**
* Emits a msg object to all connections within the same room
*
* @memberof pub.appObj
* @param {string} roomName
* @param {msg {msgType: String, msgData: Object}
* @param {function(Error)} callback Callback with error
*/
appObj.emitMessage = function(roomName, msg, callback) {
if (!_.isFunction(callback)) {
callback = function(err) {};
}
if (!roomName || !appObj.getOption("roomNameRegExp").test(roomName)) {
pub.util.logWarning("Can not send message to room with improper name: '" + roomName +"'");
callback(new pub.util.ApplicationWarning("Can not send message to room with improper name: '" + roomName +"'"));
return;
}
if (!e.app[appName].room[roomName]) {
pub.util.logWarning("Can not send meesage to room which does not exists: '" + roomName +"'");
callback(new pub.util.ApplicationWarning("Can not send message to room which does not exists: '" + roomName +"'"));
return;
}
for (var currentEasyrtcid in e.app[appName].room[roomName].clientList) {
appObj.connection(currentEasyrtcid, function(err, emitToConnectionObj){
if (err) {
callback(new pub.util.ApplicationWarning("Attempt to send message to easyrtcid '" + currentEasyrtcid +"' failed"));
}
else if (!emitToConnectionObj) {
callback(new pub.util.ApplicationWarning("No emit connection object found for easyrtcid '" + currentEasyrtcid +"'"));
}
else {
pub.eventHandler.emit("emitEasyrtcMsg", emitToConnectionObj, msg.msgType, msg, null, function(){});
}
});
}
};