|
| 1 | +import { AppIntent, AppIdentifier } from "@kite9/fdc3-standard"; |
| 2 | +import { Context } from "@kite9/fdc3-context"; |
| 3 | + |
| 4 | + |
| 5 | +/** |
| 6 | + * This is a unique, long, unguessable string that identifies a particular instance of an app. |
| 7 | + * All messages arriving at the desktop agent will have this UUID attached to them. |
| 8 | + * It is important that this is unguessable as it is a "password" of sorts used to |
| 9 | + * identify the app between reconnections. |
| 10 | + */ |
| 11 | +export type InstanceID = string |
| 12 | + |
| 13 | +/** |
| 14 | + * Handles messaging to apps and opening apps |
| 15 | + */ |
| 16 | +export interface ServerContext<X extends AppIdentifier> { |
| 17 | + |
| 18 | + /** |
| 19 | + * UUID for outgoing message |
| 20 | + */ |
| 21 | + createUUID(): string; |
| 22 | + |
| 23 | + /** |
| 24 | + * Post an outgoing message to a particular app |
| 25 | + */ |
| 26 | + post(message: object, instanceId: InstanceID): Promise<void> |
| 27 | + |
| 28 | + /** |
| 29 | + * Post an outgoing message to a particular app |
| 30 | + */ |
| 31 | + post(message: object, instanceId: InstanceID): Promise<void> |
| 32 | + |
| 33 | + /** |
| 34 | + * Opens a new instance of an application. |
| 35 | + * Promise completes once the application window is opened |
| 36 | + */ |
| 37 | + open(appId: string): Promise<InstanceID> |
| 38 | + |
| 39 | + /** |
| 40 | + * Registers a particular instance id with a given app id |
| 41 | + */ |
| 42 | + setInstanceDetails(uuid: InstanceID, details: X): void |
| 43 | + |
| 44 | + /** |
| 45 | + * Returns the UUID for a particular instance of an app. |
| 46 | + * This is used in situations where an app is reconnecting to the same desktop agent. |
| 47 | + */ |
| 48 | + getInstanceDetails(uuid: InstanceID): X | undefined |
| 49 | + |
| 50 | + /** |
| 51 | + * Registers an app as connected to the desktop agent. |
| 52 | + */ |
| 53 | + setAppConnected(app: AppIdentifier): Promise<void> |
| 54 | + |
| 55 | + /** |
| 56 | + * Unregisters the app as connected to the desktop agent. |
| 57 | + */ |
| 58 | + setAppDisconnected(app: AppIdentifier): Promise<void> |
| 59 | + |
| 60 | + /** |
| 61 | + * Returns the list of apps open and connected to FDC3 at the current time. |
| 62 | + * Note, it is the implementor's job to ensure this list is |
| 63 | + * up-to-date in the event of app crashes or disconnections. |
| 64 | + */ |
| 65 | + getConnectedApps(): Promise<AppIdentifier[]> |
| 66 | + |
| 67 | + /** |
| 68 | + * Helper function for determining if an app is currently open and connected to the da |
| 69 | + */ |
| 70 | + isAppConnected(app: AppIdentifier): Promise<boolean> |
| 71 | + |
| 72 | + /** |
| 73 | + * Allows you to write a log message somewhere |
| 74 | + */ |
| 75 | + log(message: string): void |
| 76 | + |
| 77 | + /** |
| 78 | + * Name of the provider of this desktop agent server |
| 79 | + */ |
| 80 | + provider(): string |
| 81 | + |
| 82 | + /** |
| 83 | + * Version of the provider of this desktop agent server |
| 84 | + */ |
| 85 | + providerVersion(): string |
| 86 | + |
| 87 | + /** |
| 88 | + * Supported version of the FDC3 API of the desktop agent server. |
| 89 | + */ |
| 90 | + fdc3Version(): string |
| 91 | + |
| 92 | + /** |
| 93 | + * This is called prior to returning intents to the client. It is a |
| 94 | + * an opportunity for the server to either present an intent resolver |
| 95 | + * or otherwise mess with the availble intents, or do nothing. |
| 96 | + */ |
| 97 | + narrowIntents(appIntents: AppIntent[], context: Context): Promise<AppIntent[]> |
| 98 | +} |
0 commit comments