if (audioGroup == null) {
logger.info("audioGroup is null");
return;
}
VoiceChatLeaveMessage msg = (VoiceChatLeaveMessage) message;
Player player = vm.getPlayer(msg.getCallee().getCallID());
if (player == null) {
logger.warning("No player for " + msg.getCallee());
if (audioGroup.getNumberOfPlayers() == 0) {
endVoiceChat(vm, audioGroup); // cleanup
}
return;
}
setCOSSpeaking(player, msg.getCOSName(), true);
AudioGroupPlayerInfo info = audioGroup.getPlayerInfo(player);
if (info == null) {
return; // not in group
}
/*
* XXX If the player to be removed from the group is
* in range of another player which is in a public chat,
* then rather than removing the player, re-add it
* as a transient member.
*/
if (isInRangeOfPublicChat(audioGroup, player)) {
addPlayerToAudioGroup(audioGroup, player, msg.getCallee(),
ChatType.PUBLIC, true);
return;
}
removePlayerFromAudioGroup(audioGroup, player);
if (audioGroup.getNumberOfPlayers() <= 1) {
endVoiceChat(vm, audioGroup);
}
CallSetup callSetup = player.getCall().getSetup();
if (callSetup.incomingCall || callSetup.externalOutgoingCall) {
addPlayerToAudioGroup(
vm.getVoiceManagerParameters().livePlayerAudioGroup,
player, msg.getCallee(), ChatType.PUBLIC);
addPlayerToAudioGroup(
vm.getVoiceManagerParameters().stationaryPlayerAudioGroup,
player, msg.getCallee(), ChatType.PUBLIC);
}
return;
}
if (message instanceof VoiceChatEndMessage) {
if (audioGroup == null) {
logger.info("audioGroup is null");
return;
}
endVoiceChat(vm, audioGroup);
return;
}
if (message instanceof VoiceChatJoinAcceptedMessage) {
if (audioGroup == null) {
logger.warning("Join accepted: Audio group " + group + " no longer exists");
return;
}
VoiceChatJoinAcceptedMessage msg = (VoiceChatJoinAcceptedMessage) message;
Player player = vm.getPlayer(msg.getCallee().getCallID());
if (player == null) {
logger.warning("No player for " + msg.getCallee().getCallID());
return;
}
addPlayerToAudioGroup(audioGroup, player, msg.getCallee(), msg.getChatType());
sender.send(msg);
return;
}
if (message instanceof VoiceChatHoldMessage) {
VoiceChatHoldMessage msg = (VoiceChatHoldMessage) message;
if (audioGroup == null) {
logger.warning("Hold: Audio group " + group + " no longer exists");
return;
}
Player player = vm.getPlayer(msg.getCallee().getCallID());
if (player == null) {
logger.warning("No player for " + msg.getCallee().getCallID());
return;
}
setCOSSpeaking(player, msg.getCOSName(), msg.isOnHold());
AudioGroupPlayerInfo playerInfo = audioGroup.getPlayerInfo(player);
if (playerInfo == null) {
logger.warning("No player info for " + player);
return;
}
if (msg.isOnHold()) {
playerInfo.isSpeaking = false;
playerInfo.listenAttenuation = msg.getVolume();
} else {
playerInfo.isSpeaking = true;
playerInfo.speakingAttenuation = AudioGroup.DEFAULT_SPEAKING_ATTENUATION;
playerInfo.listenAttenuation = AudioGroup.DEFAULT_LISTEN_ATTENUATION;
}
updateAttenuation(player);
sender.send(clientID, msg);
return;
}
if (message instanceof VoiceChatDialOutMessage) {
VoiceChatPhoneMessageHandler.getInstance().dialOut(
sender, clientID, (VoiceChatDialOutMessage) message);
return;
}
if (message instanceof VoiceChatJoinMessage == false) {
logger.warning("Invalid message type " + message);
return;
}
VoiceChatJoinMessage msg = (VoiceChatJoinMessage) message;
if (audioGroup == null) {
AudioGroupSetup setup = new AudioGroupSetup();
setup.spatializer = new FullVolumeSpatializer();
setup.spatializer.setAttenuator(Spatializer.DEFAULT_MAXIMUM_VOLUME);
setup.virtualPlayerListener = this;
setup.audioGroupListener = this;
audioGroup = vm.createAudioGroup(group, setup);
}
PresenceInfo[] calleeList = msg.getCalleeList();
PresenceInfo caller = msg.getCaller();
if (msg.getChatType() != null) {
Player player = vm.getPlayer(caller.getCallID());
if (player == null) {
logger.warning("No Player for " + caller.getCallID());
return;
}
boolean added = addPlayerToAudioGroup(audioGroup, player, caller, msg.getChatType());
if (added) {
sender.send(new VoiceChatJoinAcceptedMessage(group, caller, msg.getChatType()));
}
if (added == false && (calleeList == null || calleeList.length == 0)) {
endVoiceChat(vm, audioGroup);
return;
}
}
logger.info("Request to join AudioGroup " + group + " caller " + caller);
if (calleeList == null || calleeList.length == 0) {
return;
}
for (int i = 0; i < calleeList.length; i++) {
PresenceInfo info = calleeList[i];
String callID = info.getCallID();
Player player = vm.getPlayer(callID);
if (player == null) {
logger.warning("No player for callID " + callID);
continue;
}
if (info.getClientID() == null) {
/*
* This is an outworlder. We automatically join them to the group
* The InCallDialog can be used to change the privacy setting
* and to remove the outworlder from the chat.
*/
addPlayerToAudioGroup(audioGroup, player, info, msg.getChatType());
sender.send(new VoiceChatJoinAcceptedMessage(group, info, msg.getChatType()));
continue;
}
AudioGroupPlayerInfo playerInfo = audioGroup.getPlayerInfo(player);
if (playerInfo != null && sameChatType(playerInfo.chatType, msg.getChatType())) {
logger.fine("Player " + info
+ " is already in audio group " + audioGroup);
if (playerInfo.isTransientMember == false) {
continue;
}
}
WonderlandClientID id =
CommsManagerFactory.getCommsManager().getWonderlandClientID(info.getClientID());
if (id == null) {
logger.warning("No WonderlandClientID for " + info);
continue;
}
Call call = player.getCall();
if (call != null) {
try {
call.playTreatment("audioGroupInvite.au");
} catch (IOException e) {
logger.warning("Unable to play audioGroupInvite.au: "
+ e.getMessage());
}
}
logger.warning("Asking " + info + " to join audio group "
+ group + " chatType " + msg.getChatType());
requestPlayerJoinAudioGroup(sender, id, group, caller,
calleeList, msg.getChatType());
}
}