Some code tidy and migrate simple promises to async/await
This commit is contained in:
@@ -5,7 +5,7 @@ import {CommandsBase} from './CommandsBase';
|
||||
|
||||
export class AgentCommands extends CommandsBase
|
||||
{
|
||||
private animate(anim: UUID[], run: boolean): Promise<void>
|
||||
private async animate(anim: UUID[], run: boolean): Promise<void>
|
||||
{
|
||||
|
||||
const circuit = this.currentRegion.circuit;
|
||||
@@ -24,16 +24,16 @@ export class AgentCommands extends CommandsBase
|
||||
});
|
||||
});
|
||||
|
||||
return circuit.waitForAck(circuit.sendMessage(animPacket, PacketFlags.Reliable), 10000);
|
||||
return await circuit.waitForAck(circuit.sendMessage(animPacket, PacketFlags.Reliable), 10000);
|
||||
}
|
||||
|
||||
startAnimations(anim: UUID[]): Promise<void>
|
||||
async startAnimations(anim: UUID[]): Promise<void>
|
||||
{
|
||||
return this.animate(anim, true);
|
||||
return await this.animate(anim, true);
|
||||
}
|
||||
|
||||
stopAnimations(anim: UUID[]): Promise<void>
|
||||
async stopAnimations(anim: UUID[]): Promise<void>
|
||||
{
|
||||
return this.animate(anim, false);
|
||||
return await this.animate(anim, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import {Utils} from '../Utils';
|
||||
|
||||
export class AssetCommands extends CommandsBase
|
||||
{
|
||||
downloadAsset(type: HTTPAssets, uuid: UUID)
|
||||
async downloadAsset(type: HTTPAssets, uuid: UUID): Promise<Buffer>
|
||||
{
|
||||
return this.currentRegion.caps.downloadAsset(uuid, type);
|
||||
return await this.currentRegion.caps.downloadAsset(uuid, type);
|
||||
}
|
||||
|
||||
uploadAsset(type: HTTPAssets, data: Buffer, name: string, description: string): Promise<UUID>
|
||||
|
||||
@@ -8,17 +8,14 @@ import {ChatFromViewerMessage} from '../messages/ChatFromViewer';
|
||||
import {ChatType} from '../../enums/ChatType';
|
||||
import {InstantMessageDialog} from '../../enums/InstantMessageDialog';
|
||||
import Timer = NodeJS.Timer;
|
||||
import {GroupChatSessionJoinEvent} from '../../events/GroupChatSessionJoinEvent';
|
||||
import {FriendRequestEvent} from '../../events/FriendRequestEvent';
|
||||
import {AcceptFriendshipMessage} from '../messages/AcceptFriendship';
|
||||
import {AssetType} from '../../enums/AssetType';
|
||||
import {DeclineFriendshipMessage} from '../messages/DeclineFriendship';
|
||||
import {InventoryOfferedEvent} from '../../events/InventoryOfferedEvent';
|
||||
import {ChatSourceType} from '../../enums/ChatSourceType';
|
||||
import {AssetType, ChatSourceType, FriendRequestEvent, GroupChatSessionJoinEvent} from '../..';
|
||||
|
||||
export class CommunicationsCommands extends CommandsBase
|
||||
{
|
||||
sendInstantMessage(to: UUID | string, message: string): Promise<void>
|
||||
async sendInstantMessage(to: UUID | string, message: string): Promise<void>
|
||||
{
|
||||
const circuit = this.circuit;
|
||||
if (typeof to === 'string')
|
||||
@@ -49,10 +46,10 @@ export class CommunicationsCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return circuit.waitForAck(sequenceNo, 10000);
|
||||
return await circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
nearbyChat(message: string, type: ChatType, channel?: number): Promise<void>
|
||||
async nearbyChat(message: string, type: ChatType, channel?: number): Promise<void>
|
||||
{
|
||||
if (channel === undefined)
|
||||
{
|
||||
@@ -69,25 +66,25 @@ export class CommunicationsCommands extends CommandsBase
|
||||
Channel: channel
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(cfv, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
say(message: string, channel?: number): Promise<void>
|
||||
async say(message: string, channel?: number): Promise<void>
|
||||
{
|
||||
return this.nearbyChat(message, ChatType.Normal, channel);
|
||||
return await this.nearbyChat(message, ChatType.Normal, channel);
|
||||
}
|
||||
|
||||
whisper(message: string, channel?: number): Promise<void>
|
||||
async whisper(message: string, channel?: number): Promise<void>
|
||||
{
|
||||
return this.nearbyChat(message, ChatType.Whisper, channel);
|
||||
return await this.nearbyChat(message, ChatType.Whisper, channel);
|
||||
}
|
||||
|
||||
shout(message: string, channel?: number): Promise<void>
|
||||
async shout(message: string, channel?: number): Promise<void>
|
||||
{
|
||||
return this.nearbyChat(message, ChatType.Shout, channel);
|
||||
return await this.nearbyChat(message, ChatType.Shout, channel);
|
||||
}
|
||||
|
||||
startTypingLocal(): Promise<void>
|
||||
async startTypingLocal(): Promise<void>
|
||||
{
|
||||
const cfv = new ChatFromViewerMessage();
|
||||
cfv.AgentData = {
|
||||
@@ -100,10 +97,10 @@ export class CommunicationsCommands extends CommandsBase
|
||||
Channel: 0
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(cfv, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
stopTypingLocal(): Promise<void>
|
||||
async stopTypingLocal(): Promise<void>
|
||||
{
|
||||
const cfv = new ChatFromViewerMessage();
|
||||
cfv.AgentData = {
|
||||
@@ -116,10 +113,10 @@ export class CommunicationsCommands extends CommandsBase
|
||||
Channel: 0
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(cfv, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
startTypingIM(to: UUID | string): Promise<void>
|
||||
async startTypingIM(to: UUID | string): Promise<void>
|
||||
{
|
||||
if (typeof to === 'string')
|
||||
{
|
||||
@@ -150,10 +147,10 @@ export class CommunicationsCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return circuit.waitForAck(sequenceNo, 10000);
|
||||
return await circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
stopTypingIM(to: UUID | string): Promise<void>
|
||||
async stopTypingIM(to: UUID | string): Promise<void>
|
||||
{
|
||||
if (typeof to === 'string')
|
||||
{
|
||||
@@ -184,7 +181,7 @@ export class CommunicationsCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return circuit.waitForAck(sequenceNo, 10000);
|
||||
return await circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
typeInstantMessage(to: UUID | string, message: string, thinkingTime?: number, charactersPerSecond?: number): Promise<void>
|
||||
@@ -364,7 +361,7 @@ export class CommunicationsCommands extends CommandsBase
|
||||
});
|
||||
}
|
||||
|
||||
acceptFriendRequest(event: FriendRequestEvent): Promise<void>
|
||||
async acceptFriendRequest(event: FriendRequestEvent): Promise<void>
|
||||
{
|
||||
const accept: AcceptFriendshipMessage = new AcceptFriendshipMessage();
|
||||
accept.AgentData = {
|
||||
@@ -381,10 +378,10 @@ export class CommunicationsCommands extends CommandsBase
|
||||
}
|
||||
);
|
||||
const sequenceNo = this.circuit.sendMessage(accept, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
sendFriendRequest(to: UUID | string, message: string)
|
||||
async sendFriendRequest(to: UUID | string, message: string): Promise<void>
|
||||
{
|
||||
if (typeof to === 'string')
|
||||
{
|
||||
@@ -415,10 +412,10 @@ export class CommunicationsCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
private respondToInventoryOffer(event: InventoryOfferedEvent, response: InstantMessageDialog): Promise<void>
|
||||
private async respondToInventoryOffer(event: InventoryOfferedEvent, response: InstantMessageDialog): Promise<void>
|
||||
{
|
||||
const agentName = this.agent.firstName + ' ' + this.agent.lastName;
|
||||
const im: ImprovedInstantMessageMessage = new ImprovedInstantMessageMessage();
|
||||
@@ -449,34 +446,34 @@ export class CommunicationsCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
acceptInventoryOffer(event: InventoryOfferedEvent): Promise<void>
|
||||
async acceptInventoryOffer(event: InventoryOfferedEvent): Promise<void>
|
||||
{
|
||||
if (event.source === ChatSourceType.Object)
|
||||
{
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog.TaskInventoryAccepted);
|
||||
return await this.respondToInventoryOffer(event, InstantMessageDialog.TaskInventoryAccepted);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog.InventoryAccepted);
|
||||
return await this.respondToInventoryOffer(event, InstantMessageDialog.InventoryAccepted);
|
||||
}
|
||||
}
|
||||
|
||||
rejectInventoryOffer(event: InventoryOfferedEvent): Promise<void>
|
||||
async rejectInventoryOffer(event: InventoryOfferedEvent): Promise<void>
|
||||
{
|
||||
if (event.source === ChatSourceType.Object)
|
||||
{
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog.TaskInventoryDeclined);
|
||||
return await this.respondToInventoryOffer(event, InstantMessageDialog.TaskInventoryDeclined);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.respondToInventoryOffer(event, InstantMessageDialog.InventoryDeclined);
|
||||
return await this.respondToInventoryOffer(event, InstantMessageDialog.InventoryDeclined);
|
||||
}
|
||||
}
|
||||
|
||||
rejectFriendRequest(event: FriendRequestEvent): Promise<void>
|
||||
async rejectFriendRequest(event: FriendRequestEvent): Promise<void>
|
||||
{
|
||||
const reject: DeclineFriendshipMessage = new DeclineFriendshipMessage();
|
||||
reject.AgentData = {
|
||||
@@ -487,7 +484,7 @@ export class CommunicationsCommands extends CommandsBase
|
||||
TransactionID: event.requestID
|
||||
};
|
||||
const sequenceNo = this.circuit.sendMessage(reject, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
sendGroupMessage(groupID: UUID | string, message: string): Promise<number>
|
||||
|
||||
@@ -6,23 +6,19 @@ import {PacketFlags} from '../../enums/PacketFlags';
|
||||
import {ImprovedInstantMessageMessage} from '../messages/ImprovedInstantMessage';
|
||||
import {Vector3} from '../Vector3';
|
||||
import {InviteGroupRequestMessage} from '../messages/InviteGroupRequest';
|
||||
import {GroupInviteEvent} from '../../events/GroupInviteEvent';
|
||||
import {GroupRole} from '../GroupRole';
|
||||
import {GroupRoleDataRequestMessage} from '../messages/GroupRoleDataRequest';
|
||||
import {Message} from '../../enums/Message';
|
||||
import {Packet} from '../Packet';
|
||||
import {GroupRoleDataReplyMessage} from '../messages/GroupRoleDataReply';
|
||||
import {GroupMember} from '../GroupMember';
|
||||
import {GroupMembersRequestMessage} from '../messages/GroupMembersRequest';
|
||||
import {GroupMembersReplyMessage} from '../messages/GroupMembersReply';
|
||||
import {FilterResponse} from '../../enums/FilterResponse';
|
||||
import * as Long from 'long';
|
||||
import {GroupChatSessionJoinEvent} from '../../events/GroupChatSessionJoinEvent';
|
||||
import * as LLSD from '@caspertech/llsd';
|
||||
import {GroupInviteEvent} from '../..';
|
||||
|
||||
export class GroupCommands extends CommandsBase
|
||||
{
|
||||
sendGroupNotice(groupID: UUID | string, subject: string, message: string)
|
||||
async sendGroupNotice(groupID: UUID | string, subject: string, message: string): Promise<void>
|
||||
{
|
||||
if (typeof groupID === 'string')
|
||||
{
|
||||
@@ -53,10 +49,10 @@ export class GroupCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return circuit.waitForAck(sequenceNo, 10000);
|
||||
return await circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
sendGroupInviteBulk(groupID: UUID | string, sendTo: {
|
||||
async sendGroupInviteBulk(groupID: UUID | string, sendTo: {
|
||||
avatarID: UUID | string,
|
||||
roleID: UUID | string | undefined
|
||||
}[]): Promise<void>
|
||||
@@ -95,7 +91,7 @@ export class GroupCommands extends CommandsBase
|
||||
});
|
||||
|
||||
const sequenceNo = this.circuit.sendMessage(igr, PacketFlags.Reliable);
|
||||
return this.circuit.waitForAck(sequenceNo, 10000);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
getSessionAgentCount(sessionID: UUID | string): number
|
||||
@@ -107,16 +103,16 @@ export class GroupCommands extends CommandsBase
|
||||
return this.agent.getSessionAgentCount(sessionID);
|
||||
}
|
||||
|
||||
sendGroupInvite(groupID: UUID | string, to: UUID | string, role: UUID | string | undefined): Promise<void>
|
||||
async sendGroupInvite(groupID: UUID | string, to: UUID | string, role: UUID | string | undefined): Promise<void>
|
||||
{
|
||||
const sendTo = [{
|
||||
avatarID: to,
|
||||
roleID: role
|
||||
}];
|
||||
return this.sendGroupInviteBulk(groupID, sendTo);
|
||||
return await this.sendGroupInviteBulk(groupID, sendTo);
|
||||
}
|
||||
|
||||
acceptGroupInvite(event: GroupInviteEvent): Promise<void>
|
||||
async acceptGroupInvite(event: GroupInviteEvent): Promise<void>
|
||||
{
|
||||
const circuit = this.circuit;
|
||||
const agentName = this.agent.firstName + ' ' + this.agent.lastName;
|
||||
@@ -143,10 +139,10 @@ export class GroupCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return circuit.waitForAck(sequenceNo, 10000);
|
||||
return await circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
rejectGroupInvite(event: GroupInviteEvent): Promise<void>
|
||||
async rejectGroupInvite(event: GroupInviteEvent): Promise<void>
|
||||
{
|
||||
const circuit = this.circuit;
|
||||
const agentName = this.agent.firstName + ' ' + this.agent.lastName;
|
||||
@@ -173,7 +169,7 @@ export class GroupCommands extends CommandsBase
|
||||
EstateID: 0
|
||||
};
|
||||
const sequenceNo = circuit.sendMessage(im, PacketFlags.Reliable);
|
||||
return circuit.waitForAck(sequenceNo, 10000);
|
||||
return await circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
|
||||
getMemberList(groupID: UUID | string): Promise<GroupMember[]>
|
||||
|
||||
@@ -6,7 +6,7 @@ export class NetworkCommands extends CommandsBase
|
||||
{
|
||||
private throttleGenCounter = 0;
|
||||
|
||||
setBandwidth(total: number)
|
||||
async setBandwidth(total: number): Promise<void>
|
||||
{
|
||||
const agentThrottle: AgentThrottleMessage = new AgentThrottleMessage();
|
||||
agentThrottle.AgentData = {
|
||||
@@ -45,6 +45,7 @@ export class NetworkCommands extends CommandsBase
|
||||
GenCounter: this.throttleGenCounter++,
|
||||
Throttles: throttleData
|
||||
};
|
||||
this.circuit.sendMessage(agentThrottle, PacketFlags.Reliable);
|
||||
const sequenceNo = this.circuit.sendMessage(agentThrottle, PacketFlags.Reliable);
|
||||
return await this.circuit.waitForAck(sequenceNo, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ export class TeleportCommands extends CommandsBase
|
||||
});
|
||||
}
|
||||
|
||||
teleportToHandle(handle: Long, position: Vector3, lookAt: Vector3)
|
||||
teleportToHandle(handle: Long, position: Vector3, lookAt: Vector3): Promise<TeleportEvent>
|
||||
{
|
||||
return new Promise<TeleportEvent>((resolve, reject) =>
|
||||
{
|
||||
@@ -127,7 +127,7 @@ export class TeleportCommands extends CommandsBase
|
||||
});
|
||||
}
|
||||
|
||||
teleportTo(regionName: string, position: Vector3, lookAt: Vector3)
|
||||
teleportTo(regionName: string, position: Vector3, lookAt: Vector3): Promise<TeleportEvent>
|
||||
{
|
||||
return new Promise<TeleportEvent>((resolve, reject) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user