diff --git a/packages/sdk/src/actor/behaviors/buttonBehavior.ts b/packages/sdk/src/actor/behaviors/buttonBehavior.ts index 2a7a8a552..538a9ef50 100644 --- a/packages/sdk/src/actor/behaviors/buttonBehavior.ts +++ b/packages/sdk/src/actor/behaviors/buttonBehavior.ts @@ -8,9 +8,10 @@ import { ActionState, BehaviorType, DiscreteAction, - TargetBehavior, User } from '../..'; +// break import cycle +import { TargetBehavior } from './targetBehavior'; /** * Button behavior class containing the target behavior actions. diff --git a/packages/sdk/src/actor/behaviors/targetBehavior.ts b/packages/sdk/src/actor/behaviors/targetBehavior.ts index 724d5860b..bceb4bdaa 100644 --- a/packages/sdk/src/actor/behaviors/targetBehavior.ts +++ b/packages/sdk/src/actor/behaviors/targetBehavior.ts @@ -6,11 +6,12 @@ import { ActionHandler, ActionState, - Behavior, BehaviorType, DiscreteAction, User } from '../..'; +// break import cycle +import { Behavior } from './behavior'; /** * Target behavior class containing the target behavior actions. diff --git a/packages/sdk/src/asset/material.ts b/packages/sdk/src/asset/material.ts index 3b3788b89..b317145b8 100644 --- a/packages/sdk/src/asset/material.ts +++ b/packages/sdk/src/asset/material.ts @@ -5,7 +5,6 @@ import { Actor, - Asset, AssetContainer, AssetLike, Color3, @@ -22,6 +21,8 @@ import { readPath } from '../internal'; import { AssetInternal } from './assetInternal'; +// break import cycle +import { Asset } from './asset'; /** * Describes the properties of a Material. diff --git a/packages/sdk/src/asset/mesh.ts b/packages/sdk/src/asset/mesh.ts index 3ffaa0222..f1300b3c1 100644 --- a/packages/sdk/src/asset/mesh.ts +++ b/packages/sdk/src/asset/mesh.ts @@ -5,7 +5,6 @@ import { Actor, - Asset, AssetContainer, AssetLike, PrimitiveDefinition, @@ -14,6 +13,8 @@ import { } from '..'; import { Patchable } from '../internal'; import { AssetInternal } from './assetInternal'; +// break import cycle +import { Asset } from './asset'; /** Describes the properties of a mesh */ export interface MeshLike { diff --git a/packages/sdk/src/asset/prefab.ts b/packages/sdk/src/asset/prefab.ts index f3daa42ef..705c23840 100644 --- a/packages/sdk/src/asset/prefab.ts +++ b/packages/sdk/src/asset/prefab.ts @@ -3,9 +3,11 @@ * Licensed under the MIT License. */ -import { Actor, Asset, AssetContainer, AssetLike } from '..'; +import { Actor, AssetContainer, AssetLike } from '..'; import { Patchable } from '../internal'; import { AssetInternal } from './assetInternal'; +// break import cycle +import { Asset } from './asset'; export interface PrefabLike { /** The number of actors this prefab contains. */ diff --git a/packages/sdk/src/asset/sound.ts b/packages/sdk/src/asset/sound.ts index 10ea14d05..e4820e515 100644 --- a/packages/sdk/src/asset/sound.ts +++ b/packages/sdk/src/asset/sound.ts @@ -3,9 +3,11 @@ * Licensed under the MIT License. */ -import { Actor, Asset, AssetContainer, AssetLike } from '..'; +import { Actor, AssetContainer, AssetLike } from '..'; import { Patchable } from '../internal'; import { AssetInternal } from './assetInternal'; +// break import cycle +import { Asset } from './asset'; export interface SoundLike { uri: string; diff --git a/packages/sdk/src/asset/texture.ts b/packages/sdk/src/asset/texture.ts index a8c2cba7a..78ae617e5 100644 --- a/packages/sdk/src/asset/texture.ts +++ b/packages/sdk/src/asset/texture.ts @@ -3,9 +3,11 @@ * Licensed under the MIT License. */ -import { Actor, Asset, AssetContainer, AssetLike, Material, Vector2, Vector2Like } from '..'; +import { Actor, AssetContainer, AssetLike, Material, Vector2, Vector2Like } from '..'; import { Patchable, readPath } from '../internal'; import { AssetInternal } from './assetInternal'; +// break import cycle +import { Asset } from './asset'; export interface TextureLike { uri: string; diff --git a/packages/sdk/src/asset/videoStream.ts b/packages/sdk/src/asset/videoStream.ts index 6d71e9ae9..b29c8e0d1 100644 --- a/packages/sdk/src/asset/videoStream.ts +++ b/packages/sdk/src/asset/videoStream.ts @@ -3,9 +3,11 @@ * Licensed under the MIT License. */ -import { Actor, Asset, AssetContainer, AssetLike } from '..'; +import { Actor, AssetContainer, AssetLike } from '..'; import { Patchable } from '../internal'; import { AssetInternal } from './assetInternal'; +// break import cycle +import { Asset } from './asset'; export interface VideoStreamLike { uri: string; diff --git a/packages/sdk/src/internal/adapters/multipeer/protocols/clientExecution.ts b/packages/sdk/src/internal/adapters/multipeer/protocols/clientExecution.ts index 0c1d86518..6eed16996 100644 --- a/packages/sdk/src/internal/adapters/multipeer/protocols/clientExecution.ts +++ b/packages/sdk/src/internal/adapters/multipeer/protocols/clientExecution.ts @@ -9,16 +9,17 @@ import { ExportedPromise, Message, MissingRule, - Protocols, Rules } from '../../..'; +// break import cycle +import { Heartbeat, Middleware, Protocol, ServerPreprocessing } from '../../../protocols'; /** * @hidden * Class for routing messages between the client and the session */ -export class ClientExecution extends Protocols.Protocol implements Protocols.Middleware { - private heartbeat: Protocols.Heartbeat; +export class ClientExecution extends Protocol implements Middleware { + private heartbeat: Heartbeat; private heartbeatTimer: NodeJS.Timer; /** @override */ @@ -26,10 +27,10 @@ export class ClientExecution extends Protocols.Protocol implements Protocols.Mid constructor(private client: Client) { super(client.conn); - this.heartbeat = new Protocols.Heartbeat(this); + this.heartbeat = new Heartbeat(this); this.beforeRecv = this.beforeRecv.bind(this); // Behave like a server-side endpoint (send heartbeats, measure connection quality) - this.use(new Protocols.ServerPreprocessing()); + this.use(new ServerPreprocessing()); // Filter user-exclusive actors this.use(new ClientDesyncPreprocessor(client)); // Use middleware to pipe client messages to the session. diff --git a/packages/sdk/src/internal/adapters/multipeer/protocols/clientHandshake.ts b/packages/sdk/src/internal/adapters/multipeer/protocols/clientHandshake.ts index 368a48d5e..a32216541 100644 --- a/packages/sdk/src/internal/adapters/multipeer/protocols/clientHandshake.ts +++ b/packages/sdk/src/internal/adapters/multipeer/protocols/clientHandshake.ts @@ -9,14 +9,15 @@ import { Message, MissingRule, OperatingModel, - Protocols, Rules } from '../../..'; +// break import cycle +import { Handshake } from '../../../protocols'; /** * @hidden */ -export class ClientHandshake extends Protocols.Handshake { +export class ClientHandshake extends Handshake { /** @override */ public get name(): string { return `${this.constructor.name} client ${this.client.id.substr(0, 8)}`; } diff --git a/packages/sdk/src/internal/adapters/multipeer/protocols/clientStartup.ts b/packages/sdk/src/internal/adapters/multipeer/protocols/clientStartup.ts index 66e92f680..0136f3142 100644 --- a/packages/sdk/src/internal/adapters/multipeer/protocols/clientStartup.ts +++ b/packages/sdk/src/internal/adapters/multipeer/protocols/clientStartup.ts @@ -9,18 +9,19 @@ import { Message, MissingRule, Payloads, - Protocols, Rules } from '../../..'; +// break import cycle +import { Heartbeat, Protocol, ServerPreprocessing } from '../../../protocols'; -export class ClientStartup extends Protocols.Protocol { +export class ClientStartup extends Protocol { /** @override */ public get name(): string { return `${this.constructor.name} client ${this.client.id.substr(0, 8)}`; } constructor(private client: Client, syncRequest: Payloads.SyncRequest) { super(client.conn); // Behave like a server-side endpoint (send heartbeats, measure connection quality). - this.use(new Protocols.ServerPreprocessing()); + this.use(new ServerPreprocessing()); // If we've already received the 'sync-request' payload, process it now. if (syncRequest) { setImmediate(async () => { @@ -45,7 +46,7 @@ export class ClientStartup extends Protocols.Protocol { private async performStartup(payload: Payloads.SyncRequest) { // Do a quick measurement of connection latency. - const heartbeat = new Protocols.Heartbeat(this); + const heartbeat = new Heartbeat(this); await heartbeat.runIterations(10); // Allow exceptions to propagate out. this.resolve(); } diff --git a/packages/sdk/src/internal/adapters/multipeer/protocols/clientSync.ts b/packages/sdk/src/internal/adapters/multipeer/protocols/clientSync.ts index 2296ee707..c30aeb7b4 100644 --- a/packages/sdk/src/internal/adapters/multipeer/protocols/clientSync.ts +++ b/packages/sdk/src/internal/adapters/multipeer/protocols/clientSync.ts @@ -14,10 +14,11 @@ import { Message, MissingRule, Payloads, - Protocols, Rules, SyncActor } from '../../../../internal'; +// break import cycle +import { Protocol, ServerPreprocessing } from '../../../protocols'; /** * @hidden @@ -36,7 +37,7 @@ export type SynchronizationStage = * @hidden * Synchronizes application state with a client. */ -export class ClientSync extends Protocols.Protocol { +export class ClientSync extends Protocol { private inProgressStages: SynchronizationStage[] = []; private completedStages: SynchronizationStage[] = []; @@ -56,7 +57,7 @@ export class ClientSync extends Protocols.Protocol { constructor(private client: Client) { super(client.conn); // Behave like a server-side endpoint (send heartbeats, measure connection quality) - this.use(new Protocols.ServerPreprocessing()); + this.use(new ServerPreprocessing()); // Queue up user-exclusive messages until the user has joined this.use(new ClientDesyncPreprocessor(client)); } diff --git a/packages/sdk/src/internal/adapters/multipeer/protocols/sessionExecution.ts b/packages/sdk/src/internal/adapters/multipeer/protocols/sessionExecution.ts index fbf5cc86f..934c1aa51 100644 --- a/packages/sdk/src/internal/adapters/multipeer/protocols/sessionExecution.ts +++ b/packages/sdk/src/internal/adapters/multipeer/protocols/sessionExecution.ts @@ -3,18 +3,20 @@ * Licensed under the MIT License. */ -import { Message, Protocols, Session } from '../../../../internal'; +import { Message, Session } from '../../../../internal'; +// break import cycle +import { Middleware, Protocol, ClientPreprocessing } from '../../../protocols'; /** * @hidden * Class for routing messages from the app over to the session */ -export class SessionExecution extends Protocols.Protocol implements Protocols.Middleware { +export class SessionExecution extends Protocol implements Middleware { constructor(private session: Session) { super(session.conn); this.beforeRecv = this.beforeRecv.bind(this); // Behave like a client-side endpoint (record latency, respond to heartbeats). - this.use(new Protocols.ClientPreprocessing(this)); + this.use(new ClientPreprocessing(this)); // Use middleware to take incoming messages from the app and pipe them to the session. this.use(this); } diff --git a/packages/sdk/src/internal/adapters/multipeer/protocols/sessionHandshake.ts b/packages/sdk/src/internal/adapters/multipeer/protocols/sessionHandshake.ts index a541bfa84..e93256da0 100644 --- a/packages/sdk/src/internal/adapters/multipeer/protocols/sessionHandshake.ts +++ b/packages/sdk/src/internal/adapters/multipeer/protocols/sessionHandshake.ts @@ -3,17 +3,19 @@ * Licensed under the MIT License. */ -import { Payloads, Protocols, Session } from '../../../../internal'; +import { Payloads, Session } from '../../../../internal'; +// break import cycle +import { Protocol, ClientPreprocessing } from '../../../protocols'; /** * @hidden * Protocol for handling handshake with the app instance (Session is a client of App) */ -export class SessionHandshake extends Protocols.Protocol { +export class SessionHandshake extends Protocol { constructor(session: Session) { super(session.conn); // Behave like a client-side endpoint (record latency, respond to heartbeats). - this.use(new Protocols.ClientPreprocessing(this)); + this.use(new ClientPreprocessing(this)); } /** @override */ diff --git a/packages/sdk/src/internal/adapters/multipeer/protocols/sessionSync.ts b/packages/sdk/src/internal/adapters/multipeer/protocols/sessionSync.ts index 829a479e5..ab99fda9a 100644 --- a/packages/sdk/src/internal/adapters/multipeer/protocols/sessionSync.ts +++ b/packages/sdk/src/internal/adapters/multipeer/protocols/sessionSync.ts @@ -3,17 +3,19 @@ * Licensed under the MIT License. */ -import { Payloads, Protocols, Session } from '../../../../internal'; +import { Payloads, Session } from '../../../../internal'; +// break import cycle +import { Protocol, ClientPreprocessing } from '../../../protocols'; /** * @hidden * Class to manage the synchronization phase when connecting to the app. There should be no state to synchronize */ -export class SessionSync extends Protocols.Protocol { +export class SessionSync extends Protocol { constructor(session: Session) { super(session.conn); // Behave like a client-side endpoint (record latency, respond to heartbeats). - this.use(new Protocols.ClientPreprocessing(this)); + this.use(new ClientPreprocessing(this)); } /** @override */ diff --git a/packages/sdk/src/internal/connection/eventedConnection.ts b/packages/sdk/src/internal/connection/eventedConnection.ts index a42e0eb9d..64b30c9fc 100644 --- a/packages/sdk/src/internal/connection/eventedConnection.ts +++ b/packages/sdk/src/internal/connection/eventedConnection.ts @@ -6,13 +6,14 @@ import { EventEmitter } from 'events'; import { Guid } from '../..'; import { - Connection, ConnectionQuality, Message, NetworkStatsReport, NetworkStatsTracker, QueuedPromise } from '../../internal'; +// break import cycle +import { Connection } from './connection'; /** * @hidden diff --git a/packages/sdk/src/internal/connection/webSocket.ts b/packages/sdk/src/internal/connection/webSocket.ts index 01ac4e05d..66e5b1a0c 100644 --- a/packages/sdk/src/internal/connection/webSocket.ts +++ b/packages/sdk/src/internal/connection/webSocket.ts @@ -6,7 +6,9 @@ import * as WS from 'ws'; import { log } from '../..'; -import { EventedConnection, filterEmpty, Message, validateJsonFieldName } from '../../internal'; +import { filterEmpty, Message, validateJsonFieldName } from '../../internal'; +// break import cycle +import { EventedConnection } from './eventedConnection'; /** * An implementation of the Connection interface that wraps a WebSocket. diff --git a/packages/sdk/src/internal/protocols/execution.ts b/packages/sdk/src/internal/protocols/execution.ts index fe7946660..84169846d 100644 --- a/packages/sdk/src/internal/protocols/execution.ts +++ b/packages/sdk/src/internal/protocols/execution.ts @@ -4,17 +4,21 @@ */ import { ActionEvent, CollisionEvent, Context, log, TriggerEvent, } from '../..'; -import { Message, Payloads, Protocols, WebSocket } from '../../internal'; +import { Message, Payloads, WebSocket } from '../../internal'; +// break import cycle +import { Protocol } from './protocol'; +import { ServerPreprocessing } from './serverPreprocessing'; +import { Sync } from './sync'; /** * @hidden * Class to handle operational messages with a client. */ -export class Execution extends Protocols.Protocol { +export class Execution extends Protocol { constructor(private context: Context) { super(context.conn); // Behave like a server-side endpoint (send heartbeats, measure connection quality) - this.use(new Protocols.ServerPreprocessing()); + this.use(new ServerPreprocessing()); } /** @override */ @@ -94,7 +98,7 @@ export class Execution extends Protocols.Protocol { // Switch over to the Sync protocol to handle this request this.stopListening(); - const sync = new Protocols.Sync(this.conn); + const sync = new Sync(this.conn); await sync.run(); // Allow exception to propagate. this.startListening(); diff --git a/packages/sdk/src/internal/protocols/handshake.ts b/packages/sdk/src/internal/protocols/handshake.ts index acfee75b6..2d1fddb46 100644 --- a/packages/sdk/src/internal/protocols/handshake.ts +++ b/packages/sdk/src/internal/protocols/handshake.ts @@ -3,19 +3,22 @@ * Licensed under the MIT License. */ -import { Connection, OperatingModel, Payloads, Protocols } from '../../internal'; +import { Connection, OperatingModel, Payloads } from '../../internal'; +// break import cycle +import { Protocol } from './protocol'; +import { ServerPreprocessing } from './serverPreprocessing'; /** * @hidden * Class to manage the handshake process with a client. */ -export class Handshake extends Protocols.Protocol { +export class Handshake extends Protocol { public syncRequest: Payloads.SyncRequest; constructor(conn: Connection, private sessionId: string, private operatingModel: OperatingModel) { super(conn); // Behave like a server-side endpoint (send heartbeats, measure connection quality) - this.use(new Protocols.ServerPreprocessing()); + this.use(new ServerPreprocessing()); } /** @private */ diff --git a/packages/sdk/src/internal/protocols/sync.ts b/packages/sdk/src/internal/protocols/sync.ts index 2cc53e75c..204b829a2 100644 --- a/packages/sdk/src/internal/protocols/sync.ts +++ b/packages/sdk/src/internal/protocols/sync.ts @@ -3,17 +3,20 @@ * Licensed under the MIT License. */ -import { Connection, Payloads, Protocols } from '../../internal'; +import { Connection, Payloads } from '../../internal'; +// break import cycle +import { Protocol } from './protocol'; +import { ServerPreprocessing } from './serverPreprocessing'; /** * @hidden * Class to manage the join process with a client. */ -export class Sync extends Protocols.Protocol { +export class Sync extends Protocol { constructor(conn: Connection) { super(conn); // Behave like a server-side endpoint (send heartbeats, measure connection quality) - this.use(new Protocols.ServerPreprocessing()); + this.use(new ServerPreprocessing()); } /** @override */ diff --git a/packages/sdk/src/internal/util/verifyClient.ts b/packages/sdk/src/internal/util/verifyClient.ts index 878f0122e..60936d42f 100644 --- a/packages/sdk/src/internal/util/verifyClient.ts +++ b/packages/sdk/src/internal/util/verifyClient.ts @@ -10,7 +10,7 @@ import { log } from '../..'; /* * Current SDK Version - Read from package.json. */ -const CurrentSDKVersion = semver.coerce(require('../../package.json').version); +const CurrentSDKVersion = semver.coerce(require('../../../package.json').version); /* * Minimum Supported Client Library version diff --git a/packages/sdk/src/util/webHost.ts b/packages/sdk/src/util/webHost.ts index 3d9e058e0..e4541f2ff 100644 --- a/packages/sdk/src/util/webHost.ts +++ b/packages/sdk/src/util/webHost.ts @@ -30,7 +30,7 @@ export class WebHost { baseUrl?: string; port?: string | number; } = {}) { - const pjson = require('../package.json'); /* eslint-disable-line @typescript-eslint/no-var-requires */ + const pjson = require('../../package.json'); /* eslint-disable-line @typescript-eslint/no-var-requires */ log.info('app', `Node: ${process.version}`); log.info('app', `${pjson.name}: v${pjson.version}`);