Skip to content

Commit c4478fa

Browse files
Added case for websocket command handling
1 parent ad8e979 commit c4478fa

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

internal/session/socket.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
/* handle websocket commands from clients */
12-
func (m *Manager) handleWebSocketCommands(conn *websocket.Conn, sessionID string, ctxVal context.Context, cancel context.CancelFunc) {
12+
func (m *Manager) handleWebSocketCommands(conn *websocket.Conn, username, sessionID string, ctxVal context.Context, cancel context.CancelFunc) {
1313
defer cancel()
1414

1515
/* infinite loop */
@@ -18,15 +18,15 @@ func (m *Manager) handleWebSocketCommands(conn *websocket.Conn, sessionID string
1818
err := conn.ReadJSON(&msg)
1919
if err != nil {
2020
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
21-
m.errCh<-fmt.Errorf("websocket error: %w", err)
21+
m.errCh <- fmt.Errorf("websocket error: %w", err)
2222
}
2323
break
24-
}
24+
}
2525

2626
/* handle commands from clients */
2727
if msgType, ok := msg["type"].(string); ok {
2828
switch msgType {
29-
29+
3030
/* ping echo test */
3131
case "ping":
3232
pongMsg := StreamMessage{
@@ -35,7 +35,7 @@ func (m *Manager) handleWebSocketCommands(conn *websocket.Conn, sessionID string
3535
Timestamp: time.Now(),
3636
}
3737
if err := conn.WriteJSON(pongMsg); err != nil {
38-
m.errCh<-fmt.Errorf("failed to send pong: %w", err)
38+
m.errCh <- fmt.Errorf("failed to send pong: %w", err)
3939
return
4040
}
4141

@@ -45,16 +45,19 @@ func (m *Manager) handleWebSocketCommands(conn *websocket.Conn, sessionID string
4545
val := ctxVal.Value("type")
4646

4747
switch val {
48-
case StreamUserSession:
48+
case CtxStreamUserSession:
4949
/* push user session */
5050
if err := m.sendCurrentSession(conn, sessionID); err != nil {
51-
m.errCh<-fmt.Errorf("failed to send current transaction on command: %w", err)
51+
m.errCh <- fmt.Errorf("failed to send current session on command: %w", err)
5252
}
53-
case StreamUserTransactions:
53+
case CtxStreamUserTransactions:
5454
/* push user transactions */
55-
case StreamAllSessions:
55+
if err := m.sendCurrentUserTransactions(conn, username, sessionID, 100); err != nil {
56+
m.errCh <- fmt.Errorf("failed to send current list of transactions on command: %w", err)
57+
}
58+
case CtxStreamAllSessions:
5659
/* push all sessions */
57-
case StreamAllTransactions:
60+
case CtxStreamAllTransactions:
5861
/* push all transactions */
5962
}
6063
}

0 commit comments

Comments
 (0)