interface NetworkObjectService {
    get: <T extends object>(
        id: string,
        createLocalObjectToProxy?: LocalObjectToProxyCreator<T>,
    ) => Promise<undefined | NetworkObject<T>>;
    hasKnown: (id: string) => boolean;
    initialize: () => Promise<void>;
    onDidCreateNetworkObject: PlatformEvent<NetworkObjectDetails>;
    set: <T extends NetworkableObject>(
        id: string,
        objectToShare: T,
        objectType?: string,
        objectAttributes?: { [property: string]: unknown },
        objectDocumentation?: NetworkObjectDocumentation,
    ) => Promise<DisposableNetworkObject<T>>;
}

Hierarchy (View Summary)

Properties

get: <T extends object>(
    id: string,
    createLocalObjectToProxy?: LocalObjectToProxyCreator<T>,
) => Promise<undefined | NetworkObject<T>>

Type declaration

    • <T extends object>(
          id: string,
          createLocalObjectToProxy?: LocalObjectToProxyCreator<T>,
      ): Promise<undefined | NetworkObject<T>>
    • Get a network object that has previously been set up to be shared on the network. A network object is a proxy to an object living somewhere else that local code can use.

      Running this function twice with the same inputs yields the same network object.

      Type Parameters

      • T extends object

      Parameters

      • id: string

        ID of the network object - all processes must use this ID to look up this network object

      • OptionalcreateLocalObjectToProxy: LocalObjectToProxyCreator<T>

        Function that creates an object that the network object proxy will be based upon. The object this function creates cannot have an onDidDispose property. This function is useful for setting up network events on a network object.

      Returns Promise<undefined | NetworkObject<T>>

      A promise for the network object with specified ID if one exists, undefined otherwise

hasKnown: (id: string) => boolean

Type declaration

    • (id: string): boolean
    • Search locally known network objects for the given ID. Don't look on the network for more objects.

      Parameters

      • id: string

      Returns boolean

      Whether we know of an existing network object with the provided ID already on the network

initialize: () => Promise<void>

Type declaration

    • (): Promise<void>
    • Sets up the service. Only runs once and always returns the same promise after that

      Returns Promise<void>

onDidCreateNetworkObject: PlatformEvent<NetworkObjectDetails>
set: <T extends NetworkableObject>(
    id: string,
    objectToShare: T,
    objectType?: string,
    objectAttributes?: { [property: string]: unknown },
    objectDocumentation?: NetworkObjectDocumentation,
) => Promise<DisposableNetworkObject<T>>

Type declaration

    • <T extends NetworkableObject>(
          id: string,
          objectToShare: T,
          objectType?: string,
          objectAttributes?: { [property: string]: unknown },
          objectDocumentation?: NetworkObjectDocumentation,
      ): Promise<DisposableNetworkObject<T>>
    • Set up an object to be shared on the network.

      Type Parameters

      Parameters

      • id: string

        ID of the object to share on the network. All processes must use this ID to look it up.

      • objectToShare: T

        The object to set up as a network object. It will have an event named onDidDispose added to its properties. An error will be thrown if the object already had an onDidDispose property on it. If the object already contained a dispose function, a new dispose function will be set that calls the existing function (amongst other things). If the object did not already define a dispose function, one will be added.

        WARNING: setting a network object mutates the provided object.

      • OptionalobjectType: string
      • OptionalobjectAttributes: { [property: string]: unknown }
      • OptionalobjectDocumentation: NetworkObjectDocumentation

      Returns Promise<DisposableNetworkObject<T>>

      objectToShare modified to be a network object