8686func (m * Manager ) StreamUserSession (w http.ResponseWriter , r * http.Request ) {
8787
8888 /* username := r.Context().Value(middleware.ContextKeyUsername) */
89- sessionID := r .Context ().Value (middleware .ContextKeySessionID )
89+ sessionID := r .Context ().Value (middleware .ContextKeySessionID ).( string )
9090
9191 /* add a check for sessionID belongs to user */
9292 conn , err := m .upgrader .Upgrade (w , r , nil )
@@ -96,75 +96,79 @@ func (m *Manager) StreamUserSession(w http.ResponseWriter, r *http.Request) {
9696 }
9797 defer conn .Close ()
9898
99- /* context with cancel for web socket handlers */
99+ /*
100+ context with cancel for web socket handlers
101+ this is the official context for a websocket connection
102+ cancelling this means closing components of the websocket handler
103+ */
100104 ctx , cancel := context .WithCancel (context .Background ())
101105 defer cancel ()
102106
103107 /* sending initial session data */
104108 if err := m .sendCurrentSession (conn , sessionID ); err != nil {
105- // log.Printf("Error sending initial session: %v", err)
106109 m .errCh <- fmt .Errorf ("error sending initial session: %w" , err )
107110 return
108111 }
109112
110113 /* stream changes in session made in Redis */
111114 go m .listenForSessionChanges (ctx , conn , sessionID )
112115
116+ /* specify the handler context */
113117 ctxVal := context .WithValue (ctx , "type" , StreamUserSession )
114118
115119 /* handle web socket instructions from client */
116- m .handleWebSocketCommands (conn , ctxVal , cancel )
120+ m .handleWebSocketCommands (conn , sessionID , ctxVal , cancel )
117121}
118122
119123/*
120- get user transactions information
121- requires user authentication from middleware
122- user/
123- */
124- func (m * Manager ) StreamUserTransactions (w http.ResponseWriter , r * http.Request ) {
125- /* username := r.Context ().Value (middleware.ContextKeyUsername ) */
126- sessionID := r .Context ().Value (middleware .ContextKeySessionID )
127-
128- /* add a check for sessionID belongs to user */
129- conn , err := m .upgrader .Upgrade (w , r , nil )
130- if err != nil {
131- m .errCh <- fmt .Errorf ("websocket upgrade error: %w" , err )
132- return
133- }
134- defer conn .Close ()
135-
136- /* context with cancel for web socket handlers */
137- ctx , cancel := context .WithCancel (context .Background ())
138- defer cancel ()
139-
140- /* sending initial list of transactions data */
141- if err := m .sendCurrentTransactions (conn , sessionID ); err != nil {
142- // log.Printf("Error sending initial session: %v", err)
143- m .errCh <- fmt .Errorf ("error sending initial session: %w" , err )
144- return
145- }
146-
147- /* stream changes in transactions made in Redis */
148- go m .listenForTransactionsChanges (ctx , conn , sessionID )
149-
150- /* handle web socket instructions from client */
151- m .handleWebSocketCommands (conn , cancel )
152- }
153-
154- /*
155- get all sessions in the system
156- requires admin authentication from middleware
157- admin/
158- */
159- func (m * Manager ) StreamAllSessions (w http.ResponseWriter , r * http.Request ) {
160-
161- }
162-
163- /*
164- get all transaction in the system
165- requires admin authentication from middleware
166- admin/
167- */
168- func (m * Manager ) StreamAllTransactions (w http.ResponseWriter , r * http.Request ) {
169-
170- }
124+ // get user transactions information
125+ // requires user authentication from middleware
126+ // user/
127+ // */
128+ // func (m *manager) streamusertransactions (w http.responsewriter , r *http.request ) {
129+ // /* username := r.context ().value (middleware.contextkeyusername ) */
130+ // sessionid := r.context ().value (middleware.contextkeysessionid )
131+ //
132+ // /* add a check for sessionid belongs to user */
133+ // conn, err := m.upgrader.upgrade (w, r, nil)
134+ // if err != nil {
135+ // m.errch <- fmt.errorf ("websocket upgrade error: %w", err)
136+ // return
137+ // }
138+ // defer conn.close ()
139+ //
140+ // /* context with cancel for web socket handlers */
141+ // ctx, cancel := context.withcancel (context.background ())
142+ // defer cancel()
143+ //
144+ // /* sending initial list of transactions data */
145+ // if err := m.sendcurrenttransactions (conn, sessionid ); err != nil {
146+ // // log.printf("error sending initial session: %v", err)
147+ // m.errch <- fmt.errorf ("error sending initial session: %w", err)
148+ // return
149+ // }
150+ //
151+ // /* stream changes in transactions made in redis */
152+ // go m.listenfortransactionschanges (ctx, conn, sessionid )
153+ //
154+ // /* handle web socket instructions from client */
155+ // m.handlewebsocketcommands (conn, cancel)
156+ // }
157+ //
158+ // / *
159+ // get all sessions in the system
160+ // requires admin authentication from middleware
161+ // admin/
162+ // */
163+ // func (m *manager) streamallsessions (w http.responsewriter , r *http.request ) {
164+ //
165+ // }
166+ //
167+ // / *
168+ // get all transaction in the system
169+ // requires admin authentication from middleware
170+ // admin/
171+ // */
172+ // func (m *manager) streamalltransactions (w http.responsewriter , r *http.request ) {
173+ //
174+ // }
0 commit comments