Skip to content

Commit

Permalink
Finished app directory reload
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Sep 25, 2024
1 parent eb5037f commit f5263a4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/client/state/ServerState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DirectoryApp } from "@kite9/fdc3-web-impl";
import { getClientState } from "./ClientState";
import { DA_DIRECTORY_LISTING, DA_HELLO, DA_REGISTER_APP_LAUNCH, DesktopAgentDirectoryListingArgs, DesktopAgentHelloArgs, DesktopAgentRegisterAppLaunchArgs, SAIL_APP_OPEN, SAIL_APP_STATE, SAIL_CHANNEL_CHANGE, SAIL_CHANNEL_SETUP, SAIL_INTENT_RESOLVE, SailAppOpenArgs, SailAppStateArgs, SailChannelChangeArgs, SailIntentResolveArgs } from "../../server/da/message-types";
import { Directory, getClientState, TabDetail } from "./ClientState";
import { DA_DIRECTORY_LISTING, DA_HELLO, DA_REGISTER_APP_LAUNCH, DesktopAgentDirectoryListingArgs, DesktopAgentHelloArgs, DesktopAgentRegisterAppLaunchArgs, SAIL_APP_OPEN, SAIL_APP_STATE, SAIL_CHANNEL_CHANGE, SAIL_CHANNEL_SETUP, SAIL_CLIENT_STATE, SAIL_INTENT_RESOLVE, SailAppOpenArgs, SailAppStateArgs, SailChannelChangeArgs, SailClientStateArgs, SailIntentResolveArgs } from "../../server/da/message-types";
import { io, Socket } from "socket.io-client"
import { AppIdentifier, ResolveError } from "@kite9/fdc3";
import { getAppState } from "./AppState";
Expand All @@ -23,6 +23,8 @@ export interface ServerState {
setUserChannel(instanceId: string, channel: string): Promise<void>

intentChosen(ai: AppIdentifier | null, intent: string | null): Promise<void>

sendClientState(tabs: TabDetail[], directories: Directory[]): Promise<void>
}

class ServerStateImpl implements ServerState {
Expand Down Expand Up @@ -50,6 +52,16 @@ class ServerStateImpl implements ServerState {
return instanceId
}

async sendClientState(tabs: TabDetail[], directories: Directory[]): Promise<void> {
if (!this.socket) {
return
}
const userSessionId = getClientState().getUserSessionID()


await this.socket.emitWithAck(SAIL_CLIENT_STATE, { userSessionId, tabs, directories } as SailClientStateArgs)
}

async registerDesktopAgent(props: DesktopAgentHelloArgs): Promise<void> {
// the socket is used for messages returning from the desktop
// agent server to the client, such as requests to change
Expand Down
1 change: 1 addition & 0 deletions src/client/state/clientState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class LocalStorageClientState extends AbstractClientState {
const data = JSON.stringify({ tabs: this.tabs, panels: this.panels, activeTabId: this.activeTabId, userSessionId: this.userSessionId, directories: this.directories })
localStorage.setItem(STORAGE_KEY, data)
this.callbacks.forEach(cb => cb())
getServerState().sendClientState(this.tabs, this.directories)
}

}
Expand Down
5 changes: 5 additions & 0 deletions src/server/da/SailServerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppRegistration, DirectoryApp, InstanceID, ServerContext, State } from
import { AppIdentifier } from "@kite9/fdc3";
import { SailDirectory } from "../appd/SailDirectory";
import { AppIntent, Context, OpenError } from "@kite9/fdc3";
import { Directory } from "../../client/state/ClientState";

/**
* Represents the state of a Sail app.
Expand Down Expand Up @@ -168,5 +169,9 @@ export class SailServerContext implements ServerContext<SailData> {
this.socket.emit(SAIL_CHANNEL_CHANGE, app, channelId)
}

reloadAppDirectories(d: Directory[]) {
const toLoad = d.filter(d => d.active).map(d => d.url)
this.directory.replace(toLoad)
}

}
8 changes: 7 additions & 1 deletion src/server/da/initSocketService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DA_DIRECTORY_LISTING, APP_HELLO, DesktopAgentDirectoryListingArgs, AppHelloArgs, DA_HELLO, DesktopAgentHelloArgs, FDC3_APP_EVENT, DA_REGISTER_APP_LAUNCH, DesktopAgentRegisterAppLaunchArgs, SAIL_CHANNEL_CHANGE, SailChannelChangeArgs, SAIL_APP_STATE } from "./message-types";
import { DA_DIRECTORY_LISTING, APP_HELLO, DesktopAgentDirectoryListingArgs, AppHelloArgs, DA_HELLO, DesktopAgentHelloArgs, FDC3_APP_EVENT, DA_REGISTER_APP_LAUNCH, DesktopAgentRegisterAppLaunchArgs, SAIL_CHANNEL_CHANGE, SailChannelChangeArgs, SAIL_APP_STATE, SailAppStateArgs, SAIL_CLIENT_STATE, SailClientStateArgs } from "./message-types";
import { Socket, Server } from "socket.io";
import { SailFDC3Server } from "./SailFDC3Server";
import { SailServerContext } from "./SailServerContext";
Expand Down Expand Up @@ -74,6 +74,12 @@ export function initSocketService(httpServer: any, sessions: Map<string, SailFDC
}
})

socket.on(SAIL_CLIENT_STATE, async function (props: SailClientStateArgs) {
console.log("SAIL APP STATE: " + JSON.stringify(props))
const session = sessions.get(props.userSessionId)
session?.serverContext.reloadAppDirectories(props.directories)
})

socket.on(SAIL_CHANNEL_CHANGE, async function (props: SailChannelChangeArgs) {
console.log("SAIL CHANNEL CHANGE: " + JSON.stringify(props))
const session = sessions.get(props.userSessionId)
Expand Down
14 changes: 13 additions & 1 deletion src/server/da/message-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppRegistration, ChannelState, DirectoryApp, State } from "@kite9/fdc3-web-impl"
import { AppRegistration, ChannelState, DirectoryApp } from "@kite9/fdc3-web-impl"
import { AppIntent, Context } from "@kite9/fdc3"
import { Directory, TabDetail } from "../../client/state/ClientState"


/**
Expand Down Expand Up @@ -91,6 +92,17 @@ export const SAIL_APP_STATE = 'sail-app-state'

export type SailAppStateArgs = AppRegistration[]

/**
* Sent from the browser to the server to say that the client has updated state
*/
export const SAIL_CLIENT_STATE = 'sail-client-state'

export type SailClientStateArgs = {
userSessionId: string,
tabs: TabDetail[],
directories: Directory[]
}

/**
* These two messages carry FDC3 Communication Protocol messages.
*/
Expand Down

0 comments on commit f5263a4

Please sign in to comment.