diff --git a/packages/core/src/transport/relay.ts b/packages/core/src/transport/relay.ts index 4a3f97b..d2dee2a 100644 --- a/packages/core/src/transport/relay.ts +++ b/packages/core/src/transport/relay.ts @@ -118,6 +118,9 @@ export interface RelayOptions { setup(r: Relay): void; debug?: boolean; trustPeer?: boolean; + initialOid?: IO.Oid; + initialRef?: Ref; + nextLocalOid?: IO.Oid; } export class Relay { @@ -130,6 +133,7 @@ export class Relay { readonly outboundAssertions = new IdentityMap>(); readonly exported = new Membrane(); readonly imported = new Membrane(); + readonly peer: Ref | null; nextLocalOid: IO.Oid = 0; pendingTurn: IO.Turn = []; debug: boolean; @@ -148,6 +152,18 @@ export class Relay { this.facet.preventInertCheck(); options.setup(this); + + if (options.initialRef !== void 0) { + this.rewriteRefOut(options.initialRef, false, []); + } + + this.peer = (options.initialOid !== void 0) + ? this.rewriteRefIn(WireRef.mine(options.initialOid), []) + : null; + + if (options.nextLocalOid !== void 0) { + this.nextLocalOid = (options.nextLocalOid === 0) ? 1 : options.nextLocalOid; + } } rewriteOut(assertion: Assertion, transient: boolean): [Value, Array] @@ -301,31 +317,3 @@ export class Relay { } } } - -export interface RelayActorOptions extends RelayOptions { - initialOid?: IO.Oid; - initialRef?: Ref; - nextLocalOid?: IO.Oid; -} - -export function spawnRelay(options: RelayActorOptions & {initialOid: IO.Oid}): Promise; -export function spawnRelay(options: Omit): Promise; -export function spawnRelay(options: RelayActorOptions): Promise -{ - return new Promise(resolve => { - Turn.active.spawn(() => { - const relay = new Relay(options); - if (options.initialRef !== void 0) { - relay.rewriteRefOut(options.initialRef, false, []); - } - if (options.initialOid !== void 0) { - resolve(relay.rewriteRefIn(WireRef.mine(options.initialOid), [])); - } else { - resolve(null); - } - if (options.nextLocalOid !== void 0) { - relay.nextLocalOid = (options.nextLocalOid === 0) ? 1 : options.nextLocalOid; - } - }); - }); -}