Skip to content

Commit

Permalink
Expose the type of receiver against the session
Browse files Browse the repository at this point in the history
This is useful for diagnostics or logging when fallback mechanisms are in use
  • Loading branch information
dombenson committed Mar 4, 2020
1 parent cd6986d commit ad4c80a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sockjs/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ func (s *session) Send(msg string) error {
return s.sendMessage(msg)
}

func (s *session) ReceiverType() string {
if s.recv != nil {
switch s.recv.(type) {
case *wsReceiver:
return "Websocket"
case *rawWsReceiver:
return "Raw Websocket"
case *httpReceiver:
return "HTTP Fallback"
}
}
return "None"
}

func (s *session) ID() string { return s.id }

func (s *session) GetSessionState() SessionState {
Expand Down
2 changes: 2 additions & 0 deletions sockjs/sockjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "net/http"
type Session interface {
// Id returns a session id
ID() string
// ReceiverType returns the connection handler type
ReceiverType() string
// Request returns the first http request
Request() *http.Request
// Recv reads one text frame from session
Expand Down

0 comments on commit ad4c80a

Please sign in to comment.