github.com/anycable/anycable-go@v1.5.1/ws/ws.go (about) 1 package ws 2 3 import "github.com/gorilla/websocket" 4 5 const ( 6 // CloseNormalClosure indicates normal closure 7 CloseNormalClosure = websocket.CloseNormalClosure 8 9 // CloseInternalServerErr indicates closure because of internal error 10 CloseInternalServerErr = websocket.CloseInternalServerErr 11 12 // CloseAbnormalClosure indicates abnormal close 13 CloseAbnormalClosure = websocket.CloseAbnormalClosure 14 15 // CloseGoingAway indicates closing because of server shuts down or client disconnects 16 CloseGoingAway = websocket.CloseGoingAway 17 ) 18 19 var ( 20 expectedCloseStatuses = []int{ 21 websocket.CloseNormalClosure, // Reserved in case ActionCable fixes its behaviour 22 websocket.CloseGoingAway, // Web browser page was closed 23 websocket.CloseNoStatusReceived, // ActionCable don't care about closing 24 } 25 ) 26 27 type FrameType int 28 29 const ( 30 TextFrame FrameType = 0 31 CloseFrame FrameType = 1 32 BinaryFrame FrameType = 2 33 ) 34 35 type SentFrame struct { 36 FrameType FrameType 37 Payload []byte 38 CloseCode int 39 CloseReason string 40 } 41 42 func IsCloseError(err error) bool { 43 return websocket.IsCloseError(err, expectedCloseStatuses...) 44 }