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

Method OnClose

internal/wsjs/wsjs_js.go:80–89  ·  view source on GitHub ↗

OnClose registers a function to be called when the WebSocket is closed.

(fn func(CloseEvent))

Source from the content-addressed store, hash-verified

78
79// OnClose registers a function to be called when the WebSocket is closed.
80func (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.

Callers 1

initMethod · 0.80

Calls 2

addEventListenerMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected