MCPcopy
hub / github.com/coder/websocket / New

Function New

internal/wsjs/wsjs_js.go:31–48  ·  view source on GitHub ↗

New is a wrapper around the javascript WebSocket constructor.

(url string, protocols []string)

Source from the content-addressed store, hash-verified

29
30// New is a wrapper around the javascript WebSocket constructor.
31func New(url string, protocols []string) (c WebSocket, err error) {
32 defer handleJSError(&err, func() {
33 c = WebSocket{}
34 })
35
36 jsProtocols := make([]any, len(protocols))
37 for i, p := range protocols {
38 jsProtocols[i] = p
39 }
40
41 c = WebSocket{
42 v: js.Global().Get("WebSocket").New(url, jsProtocols),
43 }
44
45 c.setBinaryType("arraybuffer")
46
47 return c, nil
48}
49
50// WebSocket is a wrapper around a javascript WebSocket object.
51type WebSocket struct {

Callers 1

dialFunction · 0.92

Calls 2

handleJSErrorFunction · 0.85
setBinaryTypeMethod · 0.80

Tested by

no test coverage detected