AboutSupportDeveloper GuideVersion 1.1.0

Represents a connection to an Snap Server instance that can be used to control interactions with the server.

Constructors

  • Constructs a new instance of the Snap client object ready to connect to the given instance id

    This should match the id of the server instance that is running which is the default case when using the Snap Server API, SnapServer.start

    Parameters

    • server_id: string

      The instance of the server that will be started or connected to

    Returns SnapServer

    Example

    const server = new Snap.SnapServer('test');
    

Properties

client?: ChannelClient
emitter: EventEmitter<DefaultEventMap> = ...
need_to_reset_layout?: boolean
server_id: string

The instance of the server that will be started or connected to

snap_identity?: Identity_5

Methods

  • Adds an event handler for the given event

    Type Parameters

    • TEventName extends "all-events" | "client-registered" | "client-unregistered" | "move-size-completed" | "clients-attached" | "client-detached" | "groups-changed" | "client-activated" | "client-deactivated"

    Parameters

    Returns void

    void

    See

    SnapServerEventTypes

  • Given a snapshot, extracts the Snap layout, if any, and applies it to the current Snap Server

    Parameters

    Returns Promise<void>

    Example

    This example shows how to implement a snapshot override that decorates a snapshot with the current Snap layout

      fin.Platform.init({
    overrideCallback: async (PlatformProvider, ...overrideArgs) => {
    try {
    class WithSnap extends PlatformProvider {
    async getSnapshot(...args: [undefined, OpenFin.ClientIdentity]): Promise<OpenFin.Snapshot> {
    const snapshot = await super.getSnapshot(...args);
    const snapSnapshot = await SnapServer.decorateSnapshot(snapshot);
    return snapSnapshot;
    }
    async applySnapshot(...args: [OpenFin.ApplySnapshotPayload, OpenFin.ClientIdentity]): Promise<void> {
    await SnapServer.prepareToApplySnapshot();
    await super.applySnapshot(...args);
    await SnapServer.applySnapshot(args[0].snapshot);
    }
    }
    return new WithSnap(...overrideArgs);
    } catch (error) {
    return new PlatformProvider();
    }
    },
    });
  • Attaches two windows together on a specified side and at a specified offset

    Parameters

    • targetClientId: string

      The client id of the window to attach to

    • toAttachClientId: string

      The client id of the window to attach

    • targetSide: AttachSide

      The side of the target window to attach to

    • offset: number

      The offset from the target window side to attach to

    Returns Promise<void>

    Promise

    Example

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there are two windows with the client ids 'my-client-id-1' and 'my-client-id-2'
    await server.attachWindows('my-client-id-1', 'my-client-id-2', 'left', 0);
  • Parameters

    Returns Promise<string>

  • Connects to an already running Snap Server instance

    Use this if the Snap server has been manually started or when wanting to interact with Snap from another part of an application. For example the Snap server was started as part of a platform provider and a view would like to also interact with Snap.

    Returns Promise<void>

    Promise

    Example

    Shows how to connect to an already running Snap Server instance with the id 'test'

    const server = new Snap.SnapServer('test');
    await server.connect();
  • Given a snapshot, decorates it with the current Snap layout and returns it

    Parameters

    • snapshot: Snapshot

      The OpenFin.Snapshot to decorate

    Returns Promise<SnapSnapshot>

    A Promise resolving to an instance of SnapSnapshot which contains both the original snapshot and the Snap layout

    Example

    This example shows how to implement a snapshot override that decorates a snapshot with the current Snap layout

      fin.Platform.init({
    overrideCallback: async (PlatformProvider, ...overrideArgs) => {
    try {
    class WithSnap extends PlatformProvider {
    async getSnapshot(...args: [undefined, OpenFin.ClientIdentity]): Promise<OpenFin.Snapshot> {
    const snapshot = await super.getSnapshot(...args);
    const snapSnapshot = await SnapServer.decorateSnapshot(snapshot);
    return snapSnapshot;
    }
    async applySnapshot(...args: [OpenFin.ApplySnapshotPayload, OpenFin.ClientIdentity]): Promise<void> {
    await SnapServer.prepareToApplySnapshot();
    await super.applySnapshot(...args);
    await SnapServer.applySnapshot(args[0].snapshot);
    }
    }
    return new WithSnap(...overrideArgs);
    } catch (error) {
    return new PlatformProvider();
    }
    },
    });
  • Parameters

    • existingClientId: string

    Returns string

  • Detaches the given window from any other windows it is attached to

    Parameters

    • clientId: string

      The client id of the window to detach

    Returns Promise<void>

    Promise

    Example

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there is a window with the client id 'my-client-id'
    await server.detachFromGroup('my-client-id');
  • Type Parameters

    • TEventName extends "all-events" | "client-registered" | "client-unregistered" | "move-size-completed" | "clients-attached" | "client-detached" | "groups-changed" | "client-activated" | "client-deactivated"

    Parameters

    Returns void

  • Listens for new windows being created within the platform automatically registers them with the Snap Server

    Returns Promise<(() => Promise<void>)>

    A function that can be called to stop listening for new windows

    Example

    Setup for automatic registration of new windows and creates a new window

    const server = new Snap.SnapServer('test');
    await server.connect();
    server.enableAutoWindowRegistration();

    // The following new Window will automatically be registered with Snap
    const newView = await fin.Platform.wrapSync(fin.Platform.getCurrentSync().identity).createView({
    name: 'new-view',
    url: 'https://my-own-content.com',
    });
  • Get the executable path for an app asset.

    Parameters

    • appAssetInfo: {
          alias: string;
          target: string;
          version: string;
      }

      The app asset information.

      • alias: string

        The app asset alias information.

      • target: string

        The app asset target information.

      • version: string

        The app asset version information.

    Returns Promise<string>

    The native path for the asset.

  • Gets a list of windows that are attached to the given window

    Parameters

    • clientId: string

      The client id of the window to get the attached windows for

    Returns Promise<string[]>

    string[] - A promise resolving to a list of client ids of the attached windows

    Example

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there is a window with the client id 'my-client-id'
    const attachedWindows = await server.getAttached('my-client-id');
  • Retrieves the current layout

    Returns Promise<SnapLayout>

    The layout object

  • Parameters

    • event: NamedEvent

    Returns Promise<void>

  • Parameters

    • payload: any
    • identity: Identity_5

    Returns void

  • Checks if the given window has any attachments

    Parameters

    • clientId: string

      The client id of the window to check

    Returns Promise<boolean>

    Promise - True if the window has attachments, false otherwise

    Example

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there is a window with the client id 'my-client-id'
    const hasAttachments = await server.hasAttachments('my-client-id');
  • Launches a new process and registers it with the Snap Server

    Parameters

    Returns Promise<LaunchResult>

    Promise

    Example

    const server = new Snap.SnapServer('test');
    await server.connect();
    await server.launch({
    path: 'C:\\Windows\\System32\\notepad.exe',
    client_id: 'my-notepad-client-id',
    });
  • Adds an event handler for the given event that will only be called once

    Type Parameters

    • TEventName extends "all-events" | "client-registered" | "client-unregistered" | "move-size-completed" | "clients-attached" | "client-detached" | "groups-changed" | "client-activated" | "client-deactivated"

    Parameters

    • eventName: TEventName

      The name of the event to listen for

    • handler: ((...eventArg) => void)

      The handler to call when the event is fired

    Returns void

    void

    See

    SnapServerEventTypes

  • Prepares the Snap server to apply a new snapshot, potentially modifying the given payload

    Parameters

    • Optional snapshotPayload: ApplySnapshotPayload

      The payload for applySnapshot

    • Optional customClientIdMapper: ((id) => string)

      An optional mapper function for renaming any client IDs in the snapshot that are already in use in Snap. If not provided, then a default mapper function will be used when necessary, whose logic is as follows: For IDs containing three or more parts separated by a '/', the last part will be replaced with a new GUID. For other IDs, the the entire ID will be replaced with a new GUID. For example, <prefix>/<appId>/<instanceId> would be replaced with <prefix>/<appId>/<a new GUID>, and <another client ID> would be replaced with <a new GUID>. Client IDs referenced in the snapshot payload that are not already in use in Snap will be unchanged.

        • (id): string
        • Parameters

          • id: string

          Returns string

    Returns Promise<void>

    Promise

    Example

    This example shows how to implement a snapshot override that decorates a snapshot with the current Snap layout

      fin.Platform.init({
    overrideCallback: async (PlatformProvider, ...overrideArgs) => {
    try {
    class WithSnap extends PlatformProvider {
    async getSnapshot(...args: [undefined, OpenFin.ClientIdentity]): Promise<OpenFin.Snapshot> {
    const snapshot = await super.getSnapshot(...args);
    const snapSnapshot = await SnapServer.decorateSnapshot(snapshot);
    return snapSnapshot;
    }
    async applySnapshot(payload: OpenFin.ApplySnapshotPayload, identity?: OpenFin.Identity): Promise<void> {
    await snapServer.prepareToApplySnapshot(payload);
    await super.applySnapshot(payload, identity);
    await snapServer.applySnapshot(payload.snapshot);
    }
    }
    return new WithSnap(...overrideArgs);
    } catch (error) {
    return new PlatformProvider();
    }
    },
    });
  • Registers the given platform native window handle with the Snap Server

    Parameters

    • clientId: string

      The client id to register the window with

    • windowHandle: string

      The native window handle to register

    Returns Promise<void>

    Promise

    Example

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there is a window with the native id '0x0000000000001234'
    await server.registerWindow('my-client-id', '0x0000000000001234');
  • Removes an event handler for the given event

    Type Parameters

    • TEventName extends "all-events" | "client-registered" | "client-unregistered" | "move-size-completed" | "clients-attached" | "client-detached" | "groups-changed" | "client-activated" | "client-deactivated"

    Parameters

    • eventName: TEventName

      The name of the event to remove the handler for

    • handler: ((...eventArg) => void)

      The handler to remove

    Returns void

    void

    See

    SnapServerEventTypes

  • Parameters

    • input: any
    • oldClientId: string
    • newClientId: string

    Returns void

  • Restores the given layout

    Parameters

    • layout: SnapLayout

      The layout object to restore

    • reset: boolean = true

      Whether existing snap connections should be reset

    Returns Promise<void>

    Promise

    Example

    const server = new Snap.SnapServer('test');
    await server.connect();

    const myLayout = { ... }
    await server.setLayout(myLayout);
  • Starts a new instance of Snap Server and connects to it passing an optional set of parameters

    Parameters

    Returns Promise<void>

    Promise

    Example

    const server = new Snap.SnapServer('test');
    await server.start();
  • Shuts down the connected Snap Server instance

    Returns Promise<void>

    Promise