Account for active group members
This commit is contained in:
@@ -25,6 +25,7 @@ import {Utils} from './Utils';
|
||||
import {AgentAnimationMessage} from './messages/AgentAnimation';
|
||||
import {ClientEvents} from './ClientEvents';
|
||||
import {IGameObject} from './interfaces/IGameObject';
|
||||
import {GroupChatSessionAgentListEvent} from '../events/GroupChatSessionAgentListEvent';
|
||||
|
||||
export class Agent
|
||||
{
|
||||
@@ -36,7 +37,12 @@ export class Agent
|
||||
regionAccess: string;
|
||||
agentAccess: string;
|
||||
currentRegion: Region;
|
||||
chatSessions: string[] = [];
|
||||
chatSessions: {[key: string]: {
|
||||
[key: string]: {
|
||||
hasVoice: boolean,
|
||||
isModerator: boolean
|
||||
}
|
||||
}} = {};
|
||||
controlFlags: ControlFlags = 0;
|
||||
openID: {
|
||||
'token'?: string,
|
||||
@@ -79,21 +85,56 @@ export class Agent
|
||||
{
|
||||
this.inventory = new Inventory(clientEvents);
|
||||
this.clientEvents = clientEvents;
|
||||
this.clientEvents.onGroupChatAgentListUpdate.subscribe((event: GroupChatSessionAgentListEvent) =>
|
||||
{
|
||||
const str = event.groupID.toString();
|
||||
if (this.chatSessions[str] === undefined)
|
||||
{
|
||||
this.chatSessions[str] = {};
|
||||
}
|
||||
|
||||
const agent = event.agentID.toString();
|
||||
|
||||
if (event.entered)
|
||||
{
|
||||
this.chatSessions[str][agent] = {
|
||||
hasVoice: event.canVoiceChat,
|
||||
isModerator: event.isModerator
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete this.chatSessions[str][agent];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getSessionAgentCount(uuid: UUID): number
|
||||
{
|
||||
const str = uuid.toString();
|
||||
if (this.chatSessions[str] === undefined)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Object.keys(this.chatSessions[str]).length;
|
||||
}
|
||||
}
|
||||
|
||||
addChatSession(uuid: UUID)
|
||||
{
|
||||
const str = uuid.toString();
|
||||
if (this.chatSessions.indexOf(str) === -1)
|
||||
if (this.chatSessions[str] === undefined)
|
||||
{
|
||||
this.chatSessions.push(str);
|
||||
this.chatSessions[str] = {};
|
||||
}
|
||||
}
|
||||
|
||||
hasChatSession(uuid: UUID): boolean
|
||||
{
|
||||
const str = uuid.toString();
|
||||
if (this.chatSessions.indexOf(str) === -1)
|
||||
if (this.chatSessions[str] === undefined)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {FriendRequestEvent} from '../events/FriendRequestEvent';
|
||||
import {DisconnectEvent} from '../events/DisconnectEvent';
|
||||
import {GroupChatEvent} from '../events/GroupChatEvent';
|
||||
import {GroupChatSessionJoinEvent} from '../events/GroupChatSessionJoinEvent';
|
||||
import {GroupChatSessionAgentListEvent} from '../events/GroupChatSessionAgentListEvent';
|
||||
|
||||
export class ClientEvents
|
||||
{
|
||||
@@ -21,4 +22,5 @@ export class ClientEvents
|
||||
onCircuitLatency: Subject<number> = new Subject<number>();
|
||||
onGroupChat: Subject<GroupChatEvent> = new Subject<GroupChatEvent>();
|
||||
onGroupChatSessionJoin: Subject<GroupChatSessionJoinEvent> = new Subject<GroupChatSessionJoinEvent>();
|
||||
onGroupChatAgentListUpdate: Subject<GroupChatSessionAgentListEvent> = new Subject<GroupChatSessionAgentListEvent>();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import {Utils} from './Utils';
|
||||
import {UUID} from './UUID';
|
||||
import {Agent} from './Agent';
|
||||
import {GroupChatSessionJoinEvent} from '../events/GroupChatSessionJoinEvent';
|
||||
import {GroupChatSessionAgentListEvent} from '../events/GroupChatSessionAgentListEvent';
|
||||
|
||||
export class EventQueueClient
|
||||
{
|
||||
@@ -310,7 +311,32 @@ export class EventQueueClient
|
||||
}
|
||||
case 'ChatterBoxSessionAgentListUpdates':
|
||||
{
|
||||
// TODO
|
||||
if (event['body'])
|
||||
{
|
||||
if (event['body']['agent_updates'])
|
||||
{
|
||||
Object.keys(event['body']['agent_updates']).forEach((agentUpdate) =>
|
||||
{
|
||||
const updObj = event['body']['agent_updates'][agentUpdate];
|
||||
const gcsale = new GroupChatSessionAgentListEvent();
|
||||
gcsale.agentID = new UUID(agentUpdate);
|
||||
gcsale.groupID = new UUID(event['body']['session_id'].toString());
|
||||
gcsale.canVoiceChat = false;
|
||||
gcsale.isModerator = false;
|
||||
gcsale.entered = (updObj['transition'] === 'ENTER');
|
||||
|
||||
if (updObj['can_voice_chat'] === true)
|
||||
{
|
||||
gcsale.canVoiceChat = true;
|
||||
}
|
||||
if (updObj['is_moderator'] === true)
|
||||
{
|
||||
gcsale.isModerator = true;
|
||||
}
|
||||
this.clientEvents.onGroupChatAgentListUpdate.next(gcsale);
|
||||
});
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'TeleportFinish':
|
||||
|
||||
@@ -358,9 +358,9 @@ export class CommunicationsCommands extends CommandsBase
|
||||
});
|
||||
}
|
||||
|
||||
sendGroupMessage(groupID: UUID | string, message: string): Promise<void>
|
||||
sendGroupMessage(groupID: UUID | string, message: string): Promise<number>
|
||||
{
|
||||
return new Promise<void>((resolve, reject) =>
|
||||
return new Promise<number>((resolve, reject) =>
|
||||
{
|
||||
this.startGroupChatSession(groupID, message).then(() =>
|
||||
{
|
||||
@@ -393,7 +393,10 @@ export class CommunicationsCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return circuit.waitForAck(sequenceNo, 10000);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}).then(() =>
|
||||
{
|
||||
resolve(this.bot.clientCommands.group.getSessionAgentCount(groupID))
|
||||
}).catch((err) =>
|
||||
{
|
||||
reject(err);
|
||||
|
||||
@@ -98,6 +98,15 @@ export class GroupCommands extends CommandsBase
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
getSessionAgentCount(sessionID: UUID | string): number
|
||||
{
|
||||
if (typeof sessionID === 'string')
|
||||
{
|
||||
sessionID = new UUID(sessionID);
|
||||
}
|
||||
return this.agent.getSessionAgentCount(sessionID);
|
||||
}
|
||||
|
||||
sendGroupInvite(groupID: UUID | string, to: UUID | string, role: UUID | string | undefined): Promise<void>
|
||||
{
|
||||
const sendTo = [{
|
||||
|
||||
Reference in New Issue
Block a user