Skip to content

Commit

Permalink
Pushed up app state into fdc3-web-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Sep 24, 2024
1 parent e28a63a commit 3b8a021
Show file tree
Hide file tree
Showing 25 changed files with 687 additions and 1,166 deletions.
1,489 changes: 490 additions & 999 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3",
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand Down Expand Up @@ -55,4 +55,4 @@
"concurrently": "^8.2.2",
"istanbul-merge": "^2.0.0"
}
}
}
8 changes: 4 additions & 4 deletions packages/fdc3-agent-proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3-agent-proxy",
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand All @@ -22,13 +22,13 @@
"clean": "rimraf dist && rimraf cucumber-report.html && rimraf coverage && rimraf .nyc_output && rimraf node_modules"
},
"dependencies": {
"@kite9/fdc3-standard": "2.2.0-beta.25"
"@kite9/fdc3-standard": "2.2.0-beta.26"
},
"devDependencies": {
"@cucumber/cucumber": "10.3.1",
"@cucumber/html-formatter": "11.0.4",
"@cucumber/pretty-formatter": "1.0.1",
"@kite9/testing": "2.2.0-beta.25",
"@kite9/testing": "2.2.0-beta.26",
"@types/expect": "24.3.0",
"@types/lodash": "4.14.167",
"@types/node": "^20.14.11",
Expand All @@ -51,4 +51,4 @@
"typescript": "^5.3.2",
"uuid": "^9.0.1"
}
}
}
2 changes: 1 addition & 1 deletion packages/fdc3-context/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3-context",
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand Down
14 changes: 7 additions & 7 deletions packages/fdc3-get-agent/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3-get-agent",
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand All @@ -22,17 +22,17 @@
"clean": "rimraf dist && rimraf cucumber-report.html && rimraf coverage && rimraf .nyc_output && rimraf node_modules"
},
"dependencies": {
"@kite9/fdc3-standard": "2.2.0-beta.25",
"@kite9/fdc3-agent-proxy": "2.2.0-beta.25",
"@kite9/fdc3-schema": "2.2.0-beta.25",
"@kite9/fdc3-context": "2.2.0-beta.25",
"@kite9/fdc3-standard": "2.2.0-beta.26",
"@kite9/fdc3-agent-proxy": "2.2.0-beta.26",
"@kite9/fdc3-schema": "2.2.0-beta.26",
"@kite9/fdc3-context": "2.2.0-beta.26",
"@types/uuid": "^10.0.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@cucumber/cucumber": "10.3.1",
"@kite9/fdc3-web-impl": "2.2.0-beta.25",
"@kite9/testing": "2.2.0-beta.25",
"@kite9/fdc3-web-impl": "2.2.0-beta.26",
"@kite9/testing": "2.2.0-beta.26",
"@types/node": "^20.14.11",
"@types/wtfnode": "^0.7.3",
"expect": "^29.7.0",
Expand Down
40 changes: 22 additions & 18 deletions packages/fdc3-get-agent/test/support/TestServerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { ServerContext, InstanceID } from '@kite9/fdc3-web-impl'
import { CustomWorld } from '../world'
import { Context } from '@kite9/fdc3-context'
import { OpenError, AppIdentifier, AppIntent } from '@kite9/fdc3-standard'
import { AppRegistration, State } from '@kite9/fdc3-web-impl'

type ConnectionDetails = AppIdentifier & {
type ConnectionDetails = AppRegistration & {
msg?: object
connected: boolean,
connectionId: string,
externalPort: MessagePort,
internalPort: MessagePort,
Expand Down Expand Up @@ -50,10 +50,6 @@ export class TestServerContext implements ServerContext<ConnectionDetails> {
return this.instances.find(ca => ca.url === url)
}

async setAppDisconnected(app: AppIdentifier): Promise<void> {
this.instances = this.instances.filter(ca => ca.instanceId !== app.instanceId)
}

async shutdown(): Promise<void> {
await Promise.all(this.instances.map(i => i.internalPort.close()))
await Promise.all(this.instances.map(i => i.externalPort.close()))
Expand All @@ -80,7 +76,8 @@ export class TestServerContext implements ServerContext<ConnectionDetails> {
connectionId: "uuid-" + ni,
externalPort,
internalPort,
url: "https://dummyOrigin.test/path"
url: "https://dummyOrigin.test/path",
state: State.Pending
}

this.instances.push(connectionDetails)
Expand All @@ -93,24 +90,31 @@ export class TestServerContext implements ServerContext<ConnectionDetails> {
}
}

async setAppConnected(app: AppIdentifier): Promise<void> {
this.instances.find(ca => (ca.instanceId == app.instanceId))!!.connected = true
async getConnectedApps(): Promise<AppRegistration[]> {
return (await this.getAllApps()).filter(ca => ca.state == State.Connected)
}

async isAppConnected(app: InstanceID): Promise<boolean> {
const found = this.instances.find(a => (a.instanceId == app) && (a.state == State.Connected))
return found != null
}

async getConnectedApps(): Promise<AppIdentifier[]> {
return this.instances.filter(ca => ca.connected).map(x => {
async setAppState(app: InstanceID, state: State): Promise<void> {
const found = this.instances.find(a => (a.instanceId == app))
if (found) {
found.state = state
}
}
async getAllApps(): Promise<AppRegistration[]> {
return this.instances.map(x => {
return {
appId: x.appId,
instanceId: x.instanceId
instanceId: x.instanceId,
state: x.state
}
})
}

async isAppConnected(app: AppIdentifier): Promise<boolean> {
const found = this.instances.find(a => (a.appId == app.appId) && (a.instanceId == app.instanceId) && (a.connected))
return found != null
}

provider(): string {
return "cucumber-provider"
}
Expand All @@ -129,7 +133,7 @@ export class TestServerContext implements ServerContext<ConnectionDetails> {
* USED FOR TESTING
*/
getInstanceUUID(appId: AppIdentifier): InstanceID | undefined {
return this.instances.find(ca => (ca.appId == appId.appId) && (ca.instanceId == appId.instanceId) && (ca.connected))?.instanceId
return this.instances.find(ca => (ca.appId == appId.appId) && (ca.instanceId == appId.instanceId) && (ca.state == State.Connected))?.instanceId
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/fdc3-schema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3-schema",
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions packages/fdc3-standard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3-standard",
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand Down Expand Up @@ -31,8 +31,8 @@
"printWidth": 120
},
"dependencies": {
"@kite9/fdc3-schema": "2.2.0-beta.25",
"@kite9/fdc3-context": "2.2.0-beta.25"
"@kite9/fdc3-schema": "2.2.0-beta.26",
"@kite9/fdc3-context": "2.2.0-beta.26"
},
"devDependencies": {
"@types/jest": "29.5.12",
Expand Down
10 changes: 5 additions & 5 deletions packages/fdc3/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3",
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand All @@ -22,9 +22,9 @@
"test": "tsc"
},
"dependencies": {
"@kite9/fdc3-standard": "2.2.0-beta.25",
"@kite9/fdc3-schema": "2.2.0-beta.25",
"@kite9/fdc3-get-agent": "2.2.0-beta.25",
"@kite9/fdc3-context": "2.2.0-beta.25"
"@kite9/fdc3-standard": "2.2.0-beta.26",
"@kite9/fdc3-schema": "2.2.0-beta.26",
"@kite9/fdc3-get-agent": "2.2.0-beta.26",
"@kite9/fdc3-context": "2.2.0-beta.26"
}
}
4 changes: 2 additions & 2 deletions packages/testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/testing",
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand All @@ -26,7 +26,7 @@
"@cucumber/cucumber": "10.3.1",
"@cucumber/html-formatter": "11.0.4",
"@cucumber/pretty-formatter": "1.0.1",
"@kite9/fdc3-standard": "2.2.0-beta.25",
"@kite9/fdc3-standard": "2.2.0-beta.26",
"@types/expect": "24.3.0",
"@types/lodash": "4.14.167",
"@types/node": "^20.14.11",
Expand Down
4 changes: 2 additions & 2 deletions toolbox/fdc3-for-web/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kite9/demo",
"private": true,
"version": "2.2.0-beta.25",
"version": "2.2.0-beta.26",
"scripts": {
"dev": "nodemon -w src/server src/server/main.ts"
},
Expand All @@ -13,7 +13,7 @@
"vite": "^5.2.0"
},
"dependencies": {
"@kite9/fdc3": "2.2.0-beta.25",
"@kite9/fdc3": "2.2.0-beta.26",
"@types/uuid": "^10.0.0",
"@types/ws": "^8.5.10",
"express": "^4.18.3",
Expand Down
73 changes: 30 additions & 43 deletions toolbox/fdc3-for-web/demo/src/client/da/DemoServerContext.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import { Directory, DirectoryApp, InstanceID, ServerContext } from '@kite9/fdc3-web-impl'
import { AppRegistration, Directory, DirectoryApp, InstanceID, ServerContext, State } from '@kite9/fdc3-web-impl'
import { Socket } from 'socket.io-client';
import { v4 as uuid } from 'uuid'
import { FDC3_DA_EVENT } from '../../message-types';
import { AppIdentifier, AppIntent, Context, OpenError } from '@kite9/fdc3';
import { AppIntent, Context, OpenError } from '@kite9/fdc3';

enum Opener { Tab, Frame, Nested }

enum State { Pending, Connected }

type AppRegistration = AppIdentifier & {
type SailRegistration = AppRegistration & {
window: Window,
url: string,
state: State
}


export class DemoServerContext implements ServerContext<AppRegistration> {
export class DemoServerContext implements ServerContext<SailRegistration> {

private readonly socket: Socket
private readonly directory: Directory
private connections: AppRegistration[] = []
private connections: SailRegistration[] = []

constructor(socket: Socket, directory: Directory) {
this.socket = socket
Expand All @@ -34,42 +32,18 @@ export class DemoServerContext implements ServerContext<AppRegistration> {
/**
* Sets the appId and instanceId for a given connection UUID
*/
setInstanceDetails(uuid: InstanceID, meta: AppRegistration): void {
setInstanceDetails(uuid: InstanceID, meta: SailRegistration): void {
console.log(`Setting ${uuid} to ${meta.appId}`)
this.connections.push({
...meta,
instanceId: uuid
})
}

getInstanceForWindow(window: Window): AppRegistration | undefined {
getInstanceForWindow(window: Window): SailRegistration | undefined {
return this.connections.find(i => i.window == window)
}

/**
* Returns the UUID for a particular instance of an app.
* This is used in situations where an app is reconnecting to the same desktop agent.
*/
getInstanceDetails(uuid: InstanceID): AppRegistration | undefined {
return this.connections.find(i => i.instanceId == uuid)
}

async setAppConnected(app: AppIdentifier): Promise<void> {
const theApp = this.connections.find(i => i.instanceId == app.instanceId)
if (theApp) {
theApp.state = State.Connected
} else {
throw new Error("No app found with id " + app.instanceId)
}
}

async setAppDisconnected(app: AppIdentifier): Promise<void> {
const idx = this.connections.findIndex(i => i.instanceId == app.instanceId)
if (idx != -1) {
this.connections.splice(idx, 1)
}
}

getOpener(): Opener {
const cb = document.getElementById("opener") as HTMLInputElement;
const val = cb.value
Expand Down Expand Up @@ -150,21 +124,34 @@ export class DemoServerContext implements ServerContext<AppRegistration> {
throw new Error(OpenError.AppNotFound)
}

async getConnectedApps(): Promise<AppIdentifier[]> {
return this.connections.map(c => {
async getConnectedApps(): Promise<AppRegistration[]> {
return (await this.getAllApps()).filter(ca => ca.state == State.Connected)
}

async isAppConnected(app: InstanceID): Promise<boolean> {
const found = this.connections.find(a => (a.instanceId == app) && (a.state == State.Connected))
return found != null
}

async setAppState(app: InstanceID, state: State): Promise<void> {
const found = this.connections.find(a => (a.instanceId == app))
if (found) {
found.state = state
}
}

async getAllApps(): Promise<AppRegistration[]> {
return this.connections.map(x => {
return {
appId: c.appId,
instanceId: c.instanceId
appId: x.appId,
instanceId: x.instanceId,
state: x.state
}
})
}

async isAppConnected(app: AppIdentifier): Promise<boolean> {
const out = (await this.getConnectedApps()).filter(ai =>
(ai.appId == app.appId) && (ai.instanceId == app.instanceId)).length > 0

console.log(`Checking ${app.instanceId} = ${out}`)
return out
getInstanceDetails(uuid: InstanceID): SailRegistration | undefined {
return this.connections.find(i => i.instanceId == uuid)
}

log(message: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ window.addEventListener("load", () => {
const fdc3Server = new DefaultFDC3Server(sc, directory, channelDetails, false, 20000, 10000)

socket.on(FDC3_APP_EVENT, (msg, from) => {
console.log(`App Event ${JSON.stringify(msg, null, 2)} from ${from}`)
fdc3Server.receive(msg, from)
})

Expand Down
Loading

0 comments on commit 3b8a021

Please sign in to comment.