-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
453 additions
and
68 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,36 @@ | ||
import { AppIdentifier } from "@finos/fdc3"; | ||
import { AgentRequestMessage, AgentResponseMessage, BridgeRequestMessage } from "@finos/fdc3/dist/bridging/BridgingTypes"; | ||
|
||
export interface Messaging { | ||
|
||
post(message: any) : Promise<void> | ||
/** | ||
* Source for outgoing message | ||
*/ | ||
getSource(): AppIdentifier | ||
|
||
/** | ||
* UUID for outgoing message | ||
*/ | ||
createUUid(): string; | ||
|
||
/** | ||
* Post an outgoing message | ||
*/ | ||
post(message: AgentRequestMessage) : Promise<void> | ||
|
||
/** | ||
* Registers a listener for incoming messages. | ||
* | ||
* @param filter A filter to ignore certain messages | ||
* @param action Action to take on non-ignored messages. | ||
*/ | ||
register(filter: (m: AgentRequestMessage) => boolean, action: (m: AgentRequestMessage) => void ) : string | ||
|
||
/** | ||
* Unregisters a listener with the id given above | ||
* @param id | ||
*/ | ||
unregister(id: string) | ||
|
||
createMeta() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { AppIdentifier, AppMetadata, Context } from "@finos/fdc3"; | ||
|
||
|
||
export interface AppSupport { | ||
|
||
hasDesktopAgentBridging(): boolean; | ||
|
||
hasOriginatingAppMetadata(): boolean; | ||
|
||
findInstances(app: AppIdentifier): Promise<Array<AppIdentifier>> | ||
|
||
getAppMetadata(app: AppIdentifier): Promise<AppMetadata> | ||
|
||
open(app: AppIdentifier, context?: Context) : Promise<AppIdentifier> | ||
|
||
getThisAppMetadata(): Promise<AppMetadata> | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { AppSupport } from "./AppSupport"; | ||
|
||
|
||
export class DefaultAppSupport implements AppSupport { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Channel, Context, ContextHandler, DisplayMetadata, Listener } from "@finos/fdc3" | ||
import { Messaging } from "../Messaging" | ||
import { BroadcastAgentRequest } from "@finos/fdc3/dist/bridging/BridgingTypes" | ||
import { DefaultContextListener } from "./DefaultContextListener" | ||
|
||
export class DefaultChannel implements Channel { | ||
|
||
readonly messaging: Messaging | ||
readonly id: string | ||
readonly type: "user" | "app" | "private" | ||
readonly displayMetadata?: DisplayMetadata | undefined; | ||
|
||
readonly latestContextMap: Map<string, Context> = new Map() | ||
readonly latestContext: Context | null = null | ||
readonly listeners: Listener[] = [] | ||
|
||
constructor(messaging: Messaging, id: string, type: "user" | "app" | "private", displayMetadata? : DisplayMetadata) { | ||
this.messaging = messaging | ||
this.id = id | ||
this.type = type | ||
this.displayMetadata = displayMetadata | ||
} | ||
|
||
broadcast(context: Context): Promise<void> { | ||
const message : BroadcastAgentRequest = { | ||
meta: { | ||
requestUuid: this.messaging.createUUid(), | ||
timestamp: new Date(), | ||
source: this.messaging.getSource() | ||
}, | ||
payload: { | ||
channelId : this.id, | ||
context | ||
}, | ||
type: "broadcastRequest" | ||
} | ||
return this.messaging.post(message); | ||
} | ||
|
||
getCurrentContext(contextType?: string | undefined): Promise<Context | null> { | ||
if (contextType) { | ||
return Promise.resolve(this.latestContextMap.get(contextType) ?? null) | ||
} else { | ||
return Promise.resolve(this.latestContext); | ||
} | ||
} | ||
|
||
addContextListener(contextType: any, handler?: ContextHandler): Promise<Listener> { | ||
let theContextType : string | null | ||
let theHandler: ContextHandler | ||
|
||
if (contextType == null) { | ||
theContextType = null; | ||
theHandler = handler as ContextHandler; | ||
} else if (typeof contextType === 'string') { | ||
theContextType = contextType | ||
theHandler = handler as ContextHandler; | ||
} else { | ||
// deprecated one-arg version | ||
theContextType = null; | ||
theHandler = contextType as ContextHandler; | ||
} | ||
|
||
return this.addContextListenerInner(theContextType, theHandler); | ||
} | ||
|
||
addContextListenerInner(contextType: string | null, theHandler: ContextHandler): Promise<Listener> { | ||
const listener = new DefaultContextListener(this.messaging, "broadcastRequest", this.id, contextType, theHandler); | ||
this.listeners.push(listener) | ||
return Promise.resolve(listener) | ||
} | ||
} | ||
|
48 changes: 48 additions & 0 deletions
48
packages/desktop-agent/src/channels/DefaultChannelSupport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Channel, Context, ContextHandler, DisplayMetadata, Listener, PrivateChannel } from "@finos/fdc3"; | ||
import { Messaging } from "../Messaging"; | ||
import { ChannelSupport } from "./ChannelSupport"; | ||
import { BridgeRequestMessage, BroadcastAgentRequest } from "@finos/fdc3/dist/bridging/BridgingTypes"; | ||
import { DefaultPrivateChannel } from "./DefaultPrivateChannel"; | ||
|
||
export class DefaultChannelSupport implements ChannelSupport { | ||
|
||
readonly messaging: Messaging | ||
private userChannelId: string | ||
|
||
constructor(messaging: Messaging) { | ||
this.messaging = messaging; | ||
} | ||
|
||
hasUserChannelMembershipAPIs(): boolean { | ||
return true | ||
} | ||
|
||
getUserChannel() : Promise<Channel> { | ||
|
||
} | ||
|
||
getUserChannels() : Promise<Channel[]> { | ||
|
||
} | ||
|
||
getDisplayMetadata(id: string) : DisplayMetadata { | ||
return { | ||
|
||
} | ||
} | ||
|
||
getOrCreate(id: string) : Promise<Channel> { | ||
const out = new DefaultChannel(this.messaging, id, "app", this.getDisplayMetadata(id)) | ||
return Promise.resolve(out) | ||
} | ||
|
||
createPrivateChannel() : Promise<PrivateChannel> { | ||
const out = new DefaultPrivateChannel(this.messaging, this.messaging.createUUid()) | ||
return Promise.resolve(out); | ||
} | ||
|
||
leaveUserChannel() : Promise<void> | ||
|
||
joinUserChannel(id: string) | ||
|
||
} |
Oops, something went wrong.