Expose websocket server to plugins
Same reasoning used when exposing Express.
This commit is contained in:
parent
b13db3124b
commit
5505959f7e
|
@ -7,7 +7,7 @@ import * as pluginapi from "../../typings/pluginapi"
|
||||||
import { version } from "./constants"
|
import { version } from "./constants"
|
||||||
import { proxy } from "./proxy"
|
import { proxy } from "./proxy"
|
||||||
import * as util from "./util"
|
import * as util from "./util"
|
||||||
import { Router as WsRouter, WebsocketRouter } from "./wsRouter"
|
import { Router as WsRouter, WebsocketRouter, wss } from "./wsRouter"
|
||||||
const fsp = fs.promises
|
const fsp = fs.promises
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +24,7 @@ require("module")._load = function (request: string, parent: object, isMain: boo
|
||||||
Level,
|
Level,
|
||||||
proxy,
|
proxy,
|
||||||
WsRouter,
|
WsRouter,
|
||||||
|
wss,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return originalLoad.apply(this, [request, parent, isMain])
|
return originalLoad.apply(this, [request, parent, isMain])
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
import * as cs from "code-server"
|
import * as cs from "code-server"
|
||||||
import * as fspath from "path"
|
import * as fspath from "path"
|
||||||
import Websocket from "ws"
|
|
||||||
|
|
||||||
const wss = new Websocket.Server({ noServer: true })
|
|
||||||
|
|
||||||
export const plugin: cs.Plugin = {
|
export const plugin: cs.Plugin = {
|
||||||
displayName: "Test Plugin",
|
displayName: "Test Plugin",
|
||||||
|
@ -28,7 +25,7 @@ export const plugin: cs.Plugin = {
|
||||||
wsRouter() {
|
wsRouter() {
|
||||||
const wr = cs.WsRouter()
|
const wr = cs.WsRouter()
|
||||||
wr.ws("/test-app", (req) => {
|
wr.ws("/test-app", (req) => {
|
||||||
wss.handleUpgrade(req, req.socket, req.head, (ws) => {
|
cs.wss.handleUpgrade(req, req.socket, req.head, (ws) => {
|
||||||
ws.send("hello")
|
ws.send("hello")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as express from "express"
|
||||||
import * as expressCore from "express-serve-static-core"
|
import * as expressCore from "express-serve-static-core"
|
||||||
import ProxyServer from "http-proxy"
|
import ProxyServer from "http-proxy"
|
||||||
import * as net from "net"
|
import * as net from "net"
|
||||||
|
import Websocket from "ws"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overlay
|
* Overlay
|
||||||
|
@ -102,6 +103,11 @@ export interface WebsocketRouter {
|
||||||
*/
|
*/
|
||||||
export function WsRouter(): WebsocketRouter
|
export function WsRouter(): WebsocketRouter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The websocket server used by code-server.
|
||||||
|
*/
|
||||||
|
export const wss: Websocket.Server
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Express import used by code-server.
|
* The Express import used by code-server.
|
||||||
*
|
*
|
||||||
|
@ -110,7 +116,6 @@ export function WsRouter(): WebsocketRouter
|
||||||
* instances.
|
* instances.
|
||||||
*/
|
*/
|
||||||
export { express }
|
export { express }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use to add a field to a log.
|
* Use to add a field to a log.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue