MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / startWsServer

Function startWsServer

javascript/selenium-webdriver/test/bidi/index_test.js:30–48  ·  view source on GitHub ↗
(onMessage)

Source from the content-addressed store, hash-verified

28// plumbing and per-connection message parsing, so each server only has to supply how
29// it replies to a parsed `{id, method, params}` message.
30function startWsServer(onMessage) {
31 return new Promise((resolve) => {
32 const server = new WebSocketServer({ port: 0 }, () => {
33 const { port } = server.address()
34 resolve({
35 server,
36 url: `ws://127.0.0.1:${port}`,
37 emitEvent(method, params) {
38 for (const client of server.clients) {
39 client.send(JSON.stringify({ method, params }))
40 }
41 },
42 })
43 })
44 server.on('connection', (ws) => {
45 ws.on('message', (data) => onMessage(JSON.parse(data.toString()), ws))
46 })
47 })
48}
49
50function startEchoServer() {
51 return startWsServer(({ id }, ws) => ws.send(JSON.stringify({ id, result: {} })))

Callers 6

startEchoServerFunction · 0.85
startSubscribeServerFunction · 0.85
startEchoErrorServerFunction · 0.85
index_test.jsFile · 0.85

Calls 5

toStringMethod · 0.65
resolveFunction · 0.50
addressMethod · 0.45
onMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected