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
The instance of the server that will be started or connected to
Optional
clientOptional
needThe instance of the server that will be started or connected to
Optional
snap_Adds an event handler for the given event
The name of the event to listen for SnapServerEventTypes
The handler to call when the event is fired
Rest
...eventArg: SnapServerEventTypes[TEventName]void
Given a snapshot, extracts the Snap layout, if any, and applies it to the current Snap Server
The OpenFin.Snapshot to apply
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
The client id of the window to attach to
The client id of the window to attach
The side of the target window to attach to
The offset from the target window side to attach to
Promise
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.
Promise
Given a snapshot, decorates it with the current Snap layout and returns it
The OpenFin.Snapshot to decorate
A Promise resolving to an instance of SnapSnapshot which contains both the original snapshot and the Snap layout
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();
}
},
});
Listens for new windows being created within the platform automatically registers them with the Snap Server
A function that can be called to stop listening for new windows
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',
});
Retrieves the current layout
The layout object
Launches a new process and registers it with the Snap Server
a set of options specifying the process to launch LaunchOptions
Promise
Adds an event handler for the given event that will only be called once
The name of the event to listen for
The handler to call when the event is fired
Rest
...eventArg: SnapServerEventTypes[TEventName]void
Prepares the Snap server to apply a new snapshot, potentially modifying the given payload
Optional
snapshotPayload: ApplySnapshotPayloadThe payload for applySnapshot
Optional
customClientIdMapper: ((id: string) => 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.
Promise
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
The client id to register the window with
The native window handle to register
Optional
resizingBehavior: ResizingBehaviorPromise
Removes an event handler for the given event
The name of the event to remove the handler for
The handler to remove
Rest
...eventArg: SnapServerEventTypes[TEventName]void
Restores the given layout
The layout object to restore
Whether existing snap connections should be reset
Promise
Starts a new instance of Snap Server and connects to it passing an optional set of parameters
Optional
options: ServerOptionsOptions for the started server ServerOptions
Promise
Represents a connection to an Snap Server instance that can be used to control interactions with the server.