handleTerminalSession is Called by net/http for any new /api/sockjs connections
(session sockjs.Session)
| 189 | |
| 190 | // handleTerminalSession is Called by net/http for any new /api/sockjs connections |
| 191 | func handleTerminalSession(session sockjs.Session) { |
| 192 | var ( |
| 193 | buf string |
| 194 | err error |
| 195 | msg TerminalMessage |
| 196 | terminalSession TerminalSession |
| 197 | ) |
| 198 | |
| 199 | if buf, err = session.Recv(); err != nil { |
| 200 | log.Printf("handleTerminalSession: can't Recv: %v", err) |
| 201 | return |
| 202 | } |
| 203 | |
| 204 | if err = json.Unmarshal([]byte(buf), &msg); err != nil { |
| 205 | log.Printf("handleTerminalSession: can't UnMarshal (%v): %s", err, buf) |
| 206 | return |
| 207 | } |
| 208 | |
| 209 | if msg.Op != "bind" { |
| 210 | log.Printf("handleTerminalSession: expected 'bind' message, got: %s", buf) |
| 211 | return |
| 212 | } |
| 213 | |
| 214 | if terminalSession = TerminalSessions.Get(msg.SessionID); terminalSession.Id == "" { |
| 215 | log.Printf("handleTerminalSession: can't find session '%s'", msg.SessionID) |
| 216 | return |
| 217 | } |
| 218 | |
| 219 | terminalSession.sockJSSession = session |
| 220 | TerminalSessions.Set(msg.SessionID, terminalSession) |
| 221 | terminalSession.Bound <- nil |
| 222 | } |
| 223 | |
| 224 | // CreateAttachHandler is called from main for /api/sockjs |
| 225 | func CreateAttachHandler(path string) http.Handler { |