Skip to content

Commit

Permalink
wsjs: Register OnError
Browse files Browse the repository at this point in the history
Closes #400
  • Loading branch information
nhooyr committed Oct 19, 2023
1 parent 10137fa commit e361137
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ws_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Conn struct {
closeWasClean bool

releaseOnClose func()
releaseOnError func()
releaseOnMessage func()

readSignal chan struct{}
Expand Down Expand Up @@ -92,9 +93,15 @@ func (c *Conn) init() {
c.close(err, e.WasClean)

c.releaseOnClose()
c.releaseOnError()
c.releaseOnMessage()
})

c.releaseOnError = c.ws.OnError(func(v js.Value) {
c.setCloseErr(errors.New(v.Get("message").String()))
c.closeWithInternal()
})

c.releaseOnMessage = c.ws.OnMessage(func(e wsjs.MessageEvent) {
c.readBufMu.Lock()
defer c.readBufMu.Unlock()
Expand Down

0 comments on commit e361137

Please sign in to comment.