- add hook to send public chat message from JS

This commit is contained in:
Richard Alam 2012-10-18 20:17:51 +00:00
parent 2c60f8dab7
commit 87fe30e30b
10 changed files with 180 additions and 18 deletions

View File

@ -37,7 +37,8 @@ public class ChatService {
String meetingID = Red5.getConnectionLocal().getScope().getName();
ChatMessageVO chatObj = new ChatMessageVO();
chatObj.chatType = msg.get("chatType").toString();
chatObj.chatType = msg.get("chatType").toString();
chatObj.fromUserID = msg.get("fromUserID").toString();
chatObj.fromUsername = msg.get("fromUsername").toString();
chatObj.fromColor = msg.get("fromColor").toString();
chatObj.fromTime = Double.valueOf(msg.get("fromTime").toString());

View File

@ -39,6 +39,7 @@
<button type="button" onclick="unmuteAll()">Unmute All</button>
<button type="button" onclick="switchLayout('Video Chat')">Switch Video Layout</button>
<button type="button" onclick="switchLayout('Default')">Switch Default Layout</button>
<button type="button" onclick="echoPublicChat()">Echo Public Chat</button>
</div>
<div id="content" style="display: none">

View File

@ -39,3 +39,10 @@ var switchLayout = function(newLayout) {
BBB.switchLayout(newLayout);
}
var echoPublicChat = function () {
BBB.listen("NewPublicChatEvent", function(bbbEvent) {
console.log("Received NewPublicChatEvent event");
var message = "ECHO: " + bbbEvent.message;
BBB.sendPublicChatMessage(bbbEvent.fromUserID, bbbEvent.fromColor, bbbEvent.fromLang, message);
});
}

View File

@ -86,8 +86,36 @@
swfObj.switchLayout(newLayout);
}
}
/**
* Request to send a public chat
* fromUserID - the external user id for the sender
* fontColor - the color of the font to display the message
* localeLang - the 2-char locale code (e.g. en) for the sender
* message - the message to send
*/
BBB.sendPublicChatMessage = function(fromUserID, fontColor, localeLang, message) {
var swfObj = getSwfObj();
if (swfObj) {
swfObj.sendPublicChatRequest(fromUserID, fontColor, localeLang, message);
}
}
/**
* Request to send a private chat
* fromUserID - the external user id for the sender
* fontColor - the color of the font to display the message
* localeLang - the 2-char locale code (e.g. en) for the sender
* message - the message to send
* toUserID - the external user id of the receiver
*/
BBB.sendPrivateChatMessage = function(fromUserID, fontColor, localeLang, message, toUserID) {
var swfObj = getSwfObj();
if (swfObj) {
swfObj.sendPrivateChatRequest(fromUserID, fontColor, localeLang, message, toUserID);
}
}
/* ***********************************************************************************
* Broadcasting of events to 3rd-party apps.
*************************************************************************************/

View File

@ -11,7 +11,10 @@ package org.bigbluebutton.core
public static const MUTE_USER_REQ:String = 'MuteUserRequest';
public static const LOGOUT_REQ:String = 'LogoutRequest';
public static const SWITCH_LAYOUT_REQ:String = 'SwitchLayoutRequest';
public static const SWITCH_LAYOUT_REQ:String = 'SwitchLayoutRequest';
public static const SEND_PUBLIC_CHAT_REQ:String = 'SendPublicChatRequest';
public static const SEND_PRIVATE_CHAT_REQ:String = 'SendPrivateChatRequest';
/** Events to External JS **/
public static const GET_MY_ROLE_RESP:String = 'GetMyRoleResponse';

View File

@ -1,5 +1,6 @@
package org.bigbluebutton.core
{
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.core.managers.UserManager;
import org.bigbluebutton.main.model.users.BBBUser;
@ -21,16 +22,20 @@ package org.bigbluebutton.core
public static function internalUserIDToExternalUserID(userID:String):String {
var user:BBBUser = UserManager.getInstance().getConference().getUser(userID);
if (user != null) {
LogUtil.debug("Found externUserID [" + user.externUserID + "] for userID [" + userID + "]");
return user.externUserID;
}
LogUtil.warn("Could not find externUserID for userID [" + userID + "]");
return null;
}
public static function externalUserIDToInternalUserID(externUserID:String):String {
var user:BBBUser = UserManager.getInstance().getConference().getUserWithExternUserID(externUserID);
if (user != null) {
LogUtil.debug("Found userID [" + user.userID + "] for externUserID [" + externUserID + "]");
return user.userID;
}
LogUtil.warn("Could not find userID for externUserID [" + externUserID + "]");
return null;
}

View File

@ -8,6 +8,7 @@ package org.bigbluebutton.main.api
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.core.EventConstants;
import org.bigbluebutton.core.UsersUtil;
import org.bigbluebutton.core.events.CoreEvent;
import org.bigbluebutton.core.managers.UserManager;
import org.bigbluebutton.main.events.BBBEvent;
@ -36,13 +37,78 @@ package org.bigbluebutton.main.api
ExternalInterface.addCallback("unmuteAllUsersRequest", handleUnmuteAllUsersRequest);
ExternalInterface.addCallback("shareVideoCamera", onShareVideoCamera);
ExternalInterface.addCallback("switchLayout", handleSwitchLayoutRequest);
ExternalInterface.addCallback("unshareVideo", placeHolder);
ExternalInterface.addCallback("sendPublicChatRequest", handleSendPublicChatRequest);
ExternalInterface.addCallback("sendPrivateChatRequest", handleSendPrivateChatRequest);
}
}
private function placeHolder():void {
LogUtil.debug("Placeholder");
/**
* Request to send a public chat
* fromUserID - the external user id for the sender
* fontColor - the color of the font to display the message
* localeLang - the 2-char locale code (e.g. en) for the sender
* message - the message to send
*
*/
private function handleSendPublicChatRequest(fromUserID:String, fontColor:String, localeLang:String, message:String):void {
LogUtil.debug("handleSendPublicChatRequest");
var chatEvent:CoreEvent = new CoreEvent(EventConstants.SEND_PUBLIC_CHAT_REQ);
var payload:Object = new Object();
payload.fromColor = fontColor;
payload.fromLang = localeLang;
var now:Date = new Date();
payload.fromTime = now.getTime();
payload.fromTimezoneOffset = now.getTimezoneOffset();
payload.message = message;
// Need to convert the internal user id to external user id in case the 3rd-party app passed
// an external user id for it's own use.
payload.fromUserID = UsersUtil.externalUserIDToInternalUserID(fromUserID);
payload.fromUsername = UsersUtil.getUserName(payload.fromUserID);
chatEvent.message = payload;
_dispatcher.dispatchEvent(chatEvent);
}
/**
* Request to send a private chat
* fromUserID - the external user id for the sender
* fontColor - the color of the font to display the message
* localeLang - the 2-char locale code (e.g. en) for the sender
* message - the message to send
* toUserID - the external user id of the receiver
*/
private function handleSendPrivateChatRequest(fromUserID:String, fontColor:String, localeLang:String, message:String, toUserID:String):void {
var chatEvent:CoreEvent = new CoreEvent(EventConstants.SEND_PRIVATE_CHAT_REQ);
var payload:Object = new Object();
payload.fromColor = fontColor;
payload.fromLang = localeLang;
var now:Date = new Date();
payload.fromTime = now.getTime();
payload.fromTimezoneOffset = now.getTimezoneOffset();
payload.message = message;
// Need to convert the internal user id to external user id in case the 3rd-party app passed
// an external user id for it's own use.
payload.fromUserID = UsersUtil.externalUserIDToInternalUserID(fromUserID);
// Now get the user's name using the internal user id
payload.fromUsername = UsersUtil.getUserName(payload.fromUserID);
// Need to convert the internal user id to external user id in case the 3rd-party app passed
// an external user id for it's own use.
payload.toUserID = UsersUtil.externalUserIDToInternalUserID(toUserID);
// Now get the user's name using the internal user id
payload.toUsername = UsersUtil.getUserName(payload.toUserID);
chatEvent.message = payload;
_dispatcher.dispatchEvent(chatEvent);
}
private function handleSwitchLayoutRequest(newLayout:String):void {
var layoutEvent:CoreEvent = new CoreEvent(EventConstants.SWITCH_LAYOUT_REQ);

View File

@ -50,10 +50,12 @@ package org.bigbluebutton.main.api
payload.fromColor = event.message.fromColor;
payload.fromLang = event.message.fromLang;
payload.fromTime = event.message.fromTime;
payload.fromTimezoneOffset = event.message.fromTimezoneOffset;
payload.message = event.message.message;
// Need to convert the internal user id to external user id in case the 3rd-party app passed
// an external user id for it's own use.
LogUtil.debug("Looking externUserID for userID [" + event.message.fromUserID + "]");
payload.fromUserID = UsersUtil.internalUserIDToExternalUserID(event.message.fromUserID);
broadcastEvent(payload);
@ -67,7 +69,8 @@ package org.bigbluebutton.main.api
payload.fromUsername = event.message.fromUsername;
payload.fromColor = event.message.fromColor;
payload.fromLang = event.message.fromLang;
payload.fromTime = event.message.fromTime;
payload.fromTime = event.message.fromTime;
payload.fromTimezoneOffset = event.message.fromTimezoneOffset;
payload.toUsername = event.message.toUsername;
payload.message = event.message.message;
@ -78,8 +81,7 @@ package org.bigbluebutton.main.api
broadcastEvent(payload);
}
public function handleParticipantJoinEvent(event:ParticipantJoinEvent):void {
var payload:Object = new Object();
var user:BBBUser = UserManager.getInstance().getConference().getUser(event.userID);

View File

@ -24,9 +24,12 @@
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import com.asfusion.mate.events.Dispatcher;
import mx.events.FlexEvent;
import com.asfusion.mate.events.Dispatcher;
import mx.events.FlexEvent;
import org.bigbluebutton.common.events.OpenWindowEvent;
import org.bigbluebutton.core.EventConstants;
import org.bigbluebutton.main.events.ModuleStartedEvent;
import org.bigbluebutton.modules.chat.events.ChatEvent;
import org.bigbluebutton.modules.chat.events.ConnectionEvent;
@ -50,16 +53,24 @@
<EventHandlers type="{StartChatModuleEvent.START_CHAT_MODULE_EVENT}">
<MethodInvoker generator="{ChatEventMapDelegate}" method="setTranslationOptions" arguments="{event}" />
<ObjectBuilder generator="{ChatMessageService}"/>
</EventHandlers>
</EventHandlers>
<EventHandlers type="{StopChatModuleEvent.STOP_CHAT_MODULE_EVENT}">
<EventHandlers type="{StopChatModuleEvent.STOP_CHAT_MODULE_EVENT}">
<MethodInvoker generator="{ChatEventMapDelegate}" method="closeChatWindow" />
</EventHandlers>
</EventHandlers>
<EventHandlers type="{ConnectionEvent.CONNECT_EVENT}">
<EventHandlers type="{ConnectionEvent.CONNECT_EVENT}">
<MethodInvoker generator="{ChatEventMapDelegate}" method="openChatWindow"/>
</EventHandlers>
</EventHandlers>
<EventHandlers type="{EventConstants.SEND_PUBLIC_CHAT_REQ}">
<MethodInvoker generator="{ChatMessageService}" method="sendPublicMessageFromApi" arguments="{event.message}"/>
</EventHandlers>
<EventHandlers type="{EventConstants.SEND_PRIVATE_CHAT_REQ}">
<MethodInvoker generator="{ChatMessageService}" method="sendPrivateMessageFromApi" arguments="{event.message}"/>
</EventHandlers>
<EventHandlers type="{SendPublicChatMessageEvent.SEND_PUBLIC_CHAT_MESSAGE_EVENT}">
<MethodInvoker generator="{ChatMessageService}" method="sendPublicMessage" arguments="{event.chatMessage}"/>
</EventHandlers>

View File

@ -2,6 +2,7 @@ package org.bigbluebutton.modules.chat.services
{
import flash.events.IEventDispatcher;
import org.bigbluebutton.common.LogUtil;
import org.bigbluebutton.core.BBB;
import org.bigbluebutton.modules.chat.ChatConstants;
import org.bigbluebutton.modules.chat.events.PublicChatMessageEvent;
@ -13,6 +14,43 @@ package org.bigbluebutton.modules.chat.services
public var receiver:MessageReceiver;
public var dispatcher:IEventDispatcher;
public function sendPublicMessageFromApi(message:Object):void
{
LogUtil.debug("sendPublicMessageFromApi");
var msgVO:ChatMessageVO = new ChatMessageVO();
msgVO.chatType = ChatConstants.PUBLIC_CHAT;
msgVO.fromUserID = message.fromUserID;
msgVO.fromUsername = message.fromUsername;
msgVO.fromColor = message.fromColor;
msgVO.fromLang = message.fromLang;
msgVO.fromTime = message.fromTime;
msgVO.fromTimezoneOffset = message.fromTimezoneOffset;
msgVO.message = message.message;
sendPublicMessage(msgVO);
}
public function sendPrivateMessageFromApi(message:Object):void
{
var msgVO:ChatMessageVO = new ChatMessageVO();
msgVO.chatType = ChatConstants.PUBLIC_CHAT;
msgVO.fromUserID = message.fromUserID;
msgVO.fromUsername = message.fromUsername;
msgVO.fromColor = message.fromColor;
msgVO.fromLang = message.fromLang;
msgVO.fromTime = message.fromTime;
msgVO.fromTimezoneOffset = message.fromTimezoneOffset;
msgVO.toUserID = message.toUserID;
msgVO.toUsername = message.toUsername;
msgVO.message = message.message;
sendPrivateMessage(msgVO);
}
public function sendPublicMessage(message:ChatMessageVO):void
{
sender.sendPublicMessage(message);