--------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by-agent: Codex
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { createContext } from '@moeru/eventa/adapters/websocket/native'
|
|
|
|
/**
|
|
* Creates a control-plane Eventa context backed by a native `WebSocket`.
|
|
*
|
|
* Use when:
|
|
* - A remote plugin talks to the host over a WebSocket transport
|
|
*
|
|
* Expects:
|
|
* - `webSocket` is already connected and managed by the caller
|
|
*
|
|
* Returns:
|
|
* - An Eventa context that can be assigned to the active host channel
|
|
*/
|
|
export function createWebSocketHostChannel(webSocket: WebSocket) {
|
|
// TODO: make sure to setup proper event handling on the webSocket
|
|
return createContext(webSocket)
|
|
}
|
|
|
|
/**
|
|
* Creates an extension Eventa transport backed by a native `WebSocket`.
|
|
*
|
|
* Use when:
|
|
* - A peer transport carries extension protocol and invoke traffic over websocket
|
|
*
|
|
* Expects:
|
|
* - `webSocket` is already connected and managed by the caller
|
|
*
|
|
* Returns:
|
|
* - An Eventa context ready to pass into `createExtensionChannelScope`
|
|
*/
|
|
export function createWebSocketExtensionTransport(webSocket: WebSocket) {
|
|
return createContext(webSocket)
|
|
}
|
|
|
|
/**
|
|
* Creates a data-plane Eventa context backed by a native `WebSocket`.
|
|
*
|
|
* Use when:
|
|
* - A remote plugin needs a WebSocket-backed shared data channel
|
|
*
|
|
* Expects:
|
|
* - `webSocket` is already connected and managed by the caller
|
|
*
|
|
* Returns:
|
|
* - An Eventa context that can be assigned to the active data channel
|
|
*/
|
|
export function createWebSocketDataChannel(webSocket: WebSocket) {
|
|
// TODO: make sure to setup proper event handling on the webSocket
|
|
return createContext(webSocket)
|
|
}
|