New is a wrapper around the javascript WebSocket constructor.
(url string, protocols []string)
| 29 | |
| 30 | // New is a wrapper around the javascript WebSocket constructor. |
| 31 | func 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. |
| 51 | type WebSocket struct { |
no test coverage detected