More refactoring stuff
- Add a waitForEventQueue promise, to get rid of the 5 second fudge from testBot.js - Async'ify testBot.js - Complete plumbing for Hint's ScriptDialog support (see changes to ScriptDialogEvent.ts and Comms.ts - Fix: The EventQueue was pausing for 5 seconds every 30 seconds
This commit is contained in:
@@ -2,13 +2,18 @@ import {Subject} from 'rxjs/Subject';
|
||||
import {
|
||||
ChatEvent,
|
||||
DisconnectEvent,
|
||||
FriendRequestEvent, FriendResponseEvent, GroupChatEvent, GroupChatSessionAgentListEvent, GroupChatSessionJoinEvent,
|
||||
FriendRequestEvent,
|
||||
FriendResponseEvent,
|
||||
GroupChatEvent,
|
||||
GroupChatSessionAgentListEvent,
|
||||
GroupChatSessionJoinEvent,
|
||||
GroupInviteEvent,
|
||||
InstantMessageEvent,
|
||||
InventoryOfferedEvent,
|
||||
LureEvent,
|
||||
TeleportEvent,
|
||||
ScriptDialogEvent
|
||||
ScriptDialogEvent,
|
||||
EventQueueStateChangeEvent
|
||||
} from '..';
|
||||
|
||||
|
||||
@@ -28,4 +33,5 @@ export class ClientEvents
|
||||
onGroupChatAgentListUpdate: Subject<GroupChatSessionAgentListEvent> = new Subject<GroupChatSessionAgentListEvent>();
|
||||
onFriendResponse: Subject<FriendResponseEvent> = new Subject<FriendResponseEvent>();
|
||||
onScriptDialog: Subject<ScriptDialogEvent> = new Subject<ScriptDialogEvent>();
|
||||
onEventQueueStateChange: Subject<EventQueueStateChangeEvent> = new Subject<EventQueueStateChangeEvent>();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,12 @@ import {
|
||||
GroupInviteEvent,
|
||||
InstantMessageEvent,
|
||||
InstantMessageEventFlags,
|
||||
InventoryOfferedEvent, LureEvent
|
||||
InventoryOfferedEvent,
|
||||
LureEvent,
|
||||
ScriptDialogEvent,
|
||||
UUID
|
||||
} from '..';
|
||||
import {ScriptDialogMessage} from './messages/ScriptDialog';
|
||||
|
||||
export class Comms
|
||||
{
|
||||
@@ -35,7 +39,8 @@ export class Comms
|
||||
this.circuit.subscribeToMessages([
|
||||
Message.ImprovedInstantMessage,
|
||||
Message.ChatFromSimulator,
|
||||
Message.AlertMessage
|
||||
Message.AlertMessage,
|
||||
Message.ScriptDialog
|
||||
], (packet: Packet) =>
|
||||
{
|
||||
switch (packet.message.id)
|
||||
@@ -243,7 +248,7 @@ export class Comms
|
||||
break;
|
||||
|
||||
case Message.ChatFromSimulator:
|
||||
|
||||
{
|
||||
const chat = packet.message as ChatFromSimulatorMessage;
|
||||
const event = new ChatEvent();
|
||||
event.fromName = Utils.BufferToStringSimple(chat.ChatData.FromName);
|
||||
@@ -256,8 +261,10 @@ export class Comms
|
||||
event.position = chat.ChatData.Position;
|
||||
this.clientEvents.onNearbyChat.next(event);
|
||||
break;
|
||||
|
||||
}
|
||||
case Message.AlertMessage:
|
||||
{
|
||||
// TODO: this isn't finished
|
||||
const alertm = packet.message as AlertMessageMessage;
|
||||
|
||||
const alertMessage = Utils.BufferToStringSimple(alertm.AlertData.Message);
|
||||
@@ -269,6 +276,31 @@ export class Comms
|
||||
console.log('Alert info message: ' + alertInfoMessage);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Message.ScriptDialog:
|
||||
{
|
||||
const scriptd = packet.message as ScriptDialogMessage;
|
||||
const event = new ScriptDialogEvent();
|
||||
event.ObjectID = scriptd.Data.ObjectID;
|
||||
event.FirstName = Utils.BufferToStringSimple(scriptd.Data.FirstName);
|
||||
event.LastName = Utils.BufferToStringSimple(scriptd.Data.LastName);
|
||||
event.ObjectName = Utils.BufferToStringSimple(scriptd.Data.ObjectName);
|
||||
event.Message = Utils.BufferToStringSimple(scriptd.Data.Message);
|
||||
event.ChatChannel = scriptd.Data.ChatChannel;
|
||||
event.ImageID = scriptd.Data.ImageID;
|
||||
event.Buttons = [];
|
||||
event.Owners = [];
|
||||
for (const button of scriptd.Buttons)
|
||||
{
|
||||
event.Buttons.push(Utils.BufferToStringSimple(button.ButtonLabel));
|
||||
}
|
||||
for (const owner of scriptd.OwnerData)
|
||||
{
|
||||
event.Owners.push(owner.OwnerID);
|
||||
}
|
||||
this.clientEvents.onScriptDialog.next(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,15 +3,17 @@ import * as LLSD from '@caspertech/llsd';
|
||||
import * as request from 'request';
|
||||
import * as Long from 'long';
|
||||
import {IPAddress} from './IPAddress';
|
||||
import {TeleportEvent} from '../events/TeleportEvent';
|
||||
import {ClientEvents} from './ClientEvents';
|
||||
import {TeleportEventType} from '../enums/TeleportEventType';
|
||||
import {GroupChatEvent} from '../events/GroupChatEvent';
|
||||
import {Utils} from './Utils';
|
||||
import {UUID} from './UUID';
|
||||
import {Agent} from './Agent';
|
||||
import {GroupChatSessionJoinEvent} from '../events/GroupChatSessionJoinEvent';
|
||||
import {GroupChatSessionAgentListEvent} from '../events/GroupChatSessionAgentListEvent';
|
||||
import {
|
||||
EventQueueStateChangeEvent,
|
||||
GroupChatEvent,
|
||||
GroupChatSessionAgentListEvent,
|
||||
GroupChatSessionJoinEvent,
|
||||
TeleportEvent
|
||||
} from '..';
|
||||
|
||||
export class EventQueueClient
|
||||
{
|
||||
@@ -28,9 +30,15 @@ export class EventQueueClient
|
||||
this.clientEvents = clientEvents;
|
||||
this.caps = caps;
|
||||
this.Get();
|
||||
const state = new EventQueueStateChangeEvent();
|
||||
state.active = true;
|
||||
this.clientEvents.onEventQueueStateChange.next(state);
|
||||
}
|
||||
shutdown()
|
||||
{
|
||||
const state = new EventQueueStateChangeEvent();
|
||||
state.active = false;
|
||||
this.clientEvents.onEventQueueStateChange.next(state);
|
||||
if (this.currentRequest !== null)
|
||||
{
|
||||
this.currentRequest.abort();
|
||||
@@ -43,6 +51,7 @@ export class EventQueueClient
|
||||
'ack': this.ack,
|
||||
'done': this.done
|
||||
};
|
||||
const startTime = new Date().getTime();
|
||||
this.capsRequestXML('EventQueueGet', req).then((data) =>
|
||||
{
|
||||
if (data['events'])
|
||||
@@ -293,7 +302,7 @@ export class EventQueueClient
|
||||
'method': 'accept invitation',
|
||||
'session-id': imSessionID
|
||||
};
|
||||
this.caps.capsRequestXML('ChatSessionRequest', requestedFolders).then((result: any) =>
|
||||
this.caps.capsRequestXML('ChatSessionRequest', requestedFolders).then((ignore: any) =>
|
||||
{
|
||||
this.agent.addChatSession(groupChatEvent.groupID);
|
||||
|
||||
@@ -393,14 +402,28 @@ export class EventQueueClient
|
||||
}
|
||||
}).catch((err) =>
|
||||
{
|
||||
// Wait 5 seconds before retrying
|
||||
setTimeout(() =>
|
||||
const time = (new Date().getTime()) - startTime;
|
||||
if (time > 30000)
|
||||
{
|
||||
// This is the normal request timeout, so reconnect immediately
|
||||
if (!this.done)
|
||||
{
|
||||
this.Get();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.error('Event queue aborted after ' + time + 'ms. Reconnecting in 5 seconds');
|
||||
|
||||
// Wait 5 seconds before retrying
|
||||
setTimeout(() =>
|
||||
{
|
||||
if (!this.done)
|
||||
{
|
||||
this.Get();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
}
|
||||
request(url: string, data: string, contentType: string): Promise<string>
|
||||
@@ -432,7 +455,7 @@ export class EventQueueClient
|
||||
});
|
||||
}
|
||||
|
||||
capsRequestXML(capability: string, data: any): Promise<any>
|
||||
capsRequestXML(capability: string, data: any, attempt: number = 0): Promise<any>
|
||||
{
|
||||
return new Promise<any>((resolve, reject) =>
|
||||
{
|
||||
@@ -450,7 +473,15 @@ export class EventQueueClient
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error('Not an LLSD response');
|
||||
// Retry caps request three times before giving up
|
||||
if (attempt < 3)
|
||||
{
|
||||
return this.capsRequestXML(capability, data, ++attempt);
|
||||
}
|
||||
else
|
||||
{
|
||||
reject(new Error('Not an LLSD response, capability: ' + capability));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error)
|
||||
@@ -467,4 +498,4 @@ export class EventQueueClient
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import {Comms} from './Comms';
|
||||
import {ClientEvents} from './ClientEvents';
|
||||
import {IObjectStore} from './interfaces/IObjectStore';
|
||||
import {ObjectStoreFull} from './ObjectStoreFull';
|
||||
import {BotOptionFlags} from '../enums/BotOptionFlags';
|
||||
import {ObjectStoreLite} from './ObjectStoreLite';
|
||||
import {BotOptionFlags} from '..';
|
||||
|
||||
export class Region
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user