Files
moeka-project/packages/plugin-sdk/src/channels/remote/websocket/index.ts
T
Nekoandautofix-ci[bot] 668440a732 refactor(extension-*,stage-tamagotchi,stage-ui,server-*): rename to extension, improve DX (#1892)
---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by-agent: Codex
2026-06-12 02:03:42 +08:00

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)
}