-
Notifications
You must be signed in to change notification settings - Fork 25
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
3 changed files
with
147 additions
and
21 deletions.
There are no files selected for viewing
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
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,119 @@ | ||
import { IntentHandler } from "fdc3-2.0"; | ||
import { ListenerItem, SailListener } from "../fdc3-1.2/listeners"; | ||
import { SendMessage } from "../message"; | ||
import { FDC3_2_0_TOPICS } from "/@main/handlers/fdc3/2.0/topics"; | ||
|
||
/** | ||
* Listeners for Private Channel methods. onDisconnect, onUnsubscribe, onAddContextListener | ||
*/ | ||
|
||
export class AddContextListener implements SailListener { | ||
private id: string; | ||
|
||
constructor(sendMessage: SendMessage, listenerId: string) { | ||
this.id = listenerId; | ||
|
||
this.unsubscribe = () => { | ||
addContextListeners.delete(this.id); | ||
|
||
sendMessage(FDC3_2_0_TOPICS.DROP_ONADDCONTEXT_LISTENER, { | ||
listenerId: this.id, | ||
}); | ||
}; | ||
} | ||
|
||
unsubscribe: () => void; | ||
} | ||
|
||
export class UnsubscribeListener implements SailListener { | ||
private id: string; | ||
|
||
constructor(sendMessage: SendMessage, listenerId: string) { | ||
this.id = listenerId; | ||
|
||
this.unsubscribe = () => { | ||
unsubscribeListeners.delete(this.id); | ||
|
||
sendMessage(FDC3_2_0_TOPICS.DROP_ONUNSUBSCRIBE_LISTENER, { | ||
listenerId: this.id, | ||
}); | ||
}; | ||
} | ||
|
||
unsubscribe: () => void; | ||
} | ||
|
||
export class DisconnectListener implements SailListener { | ||
private id: string; | ||
|
||
constructor(sendMessage: SendMessage, listenerId: string) { | ||
this.id = listenerId; | ||
|
||
this.unsubscribe = () => { | ||
disconnectListeners.delete(this.id); | ||
|
||
sendMessage(FDC3_2_0_TOPICS.DROP_ONDISCONNECT_LISTENER, { | ||
listenerId: this.id, | ||
}); | ||
}; | ||
} | ||
|
||
unsubscribe: () => void; | ||
} | ||
|
||
// listener for async intent handlers (2.0) | ||
export interface IntentListenerItem { | ||
id?: string; | ||
handler?: IntentHandler; | ||
contextType?: string; | ||
} | ||
|
||
//listener that takes handler with ContextType arg only | ||
export interface ContextTypeListenerItem { | ||
id?: string; | ||
handler?: (contextType: string) => void; | ||
contextType?: string; | ||
} | ||
|
||
//listener with handler that has no args | ||
export interface VoidListenerItem { | ||
id?: string; | ||
handler?: () => void; | ||
contextType?: string; | ||
} | ||
|
||
|
||
//map of listeners for when a contextListener is added to a private channel | ||
export const addContextListeners: Map<string, ContextTypeListenerItem> = new Map(); | ||
|
||
//map of listeners for unsubscribing on a private channel | ||
export const unsubscribeListeners: Map<string, ContextTypeListenerItem> = new Map(); | ||
|
||
//map of listeners for disconnecting on a private channel | ||
export const disconnectListeners: Map<string, ListenerItem> = new Map(); | ||
|
||
export const createContextTypeListenerItem = ( | ||
id: string, | ||
handler: (contextType: string) => void, | ||
contextType?: string, | ||
): ContextTypeListenerItem => { | ||
const listener = { | ||
id, | ||
handler, | ||
contextType | ||
}; | ||
return listener; | ||
}; | ||
|
||
export const createVoidListenerItem = ( | ||
id: string, | ||
handler: () => void, | ||
contextType?: string, | ||
): ListenerItem => { | ||
const listener: VoidListenerItem = { | ||
id, | ||
handler, | ||
contextType | ||
}; | ||
return listener; | ||
}; |