OnClose registers a function to be called when the WebSocket is closed.
(fn func(CloseEvent))
| 78 | |
| 79 | // OnClose registers a function to be called when the WebSocket is closed. |
| 80 | func (c WebSocket) OnClose(fn func(CloseEvent)) (remove func()) { |
| 81 | return c.addEventListener("close", func(e js.Value) { |
| 82 | ce := CloseEvent{ |
| 83 | Code: uint16(e.Get("code").Int()), |
| 84 | Reason: e.Get("reason").String(), |
| 85 | WasClean: e.Get("wasClean").Bool(), |
| 86 | } |
| 87 | fn(ce) |
| 88 | }) |
| 89 | } |
| 90 | |
| 91 | // OnError registers a function to be called when there is an error |
| 92 | // with the WebSocket. |
no test coverage detected