created proxy and listeners to connect recorder and server-client cross writing

This commit is contained in:
amit bezalel
2017-07-09 09:51:17 +03:00
parent d40b7670d5
commit 86938a8d76
18 changed files with 1224 additions and 950 deletions

View File

@@ -13,7 +13,15 @@ type WsServer struct {
cfg *ServerConfig
}
type WsHandler func(io.ReadWriter, *ServerConfig)
type WsHandler func(io.ReadWriter, *ServerConfig, string)
// func checkOrigin(config *websocket.Config, req *http.Request) (err error) {
// config.Origin, err = websocket.Origin(config, req)
// if err == nil && config.Origin == nil {
// return fmt.Errorf("null origin")
// }
// return err
// }
// This example demonstrates a trivial echo server.
func (wsServer *WsServer) Listen(urlStr string, handlerFunc WsHandler) {
@@ -26,15 +34,28 @@ func (wsServer *WsServer) Listen(urlStr string, handlerFunc WsHandler) {
fmt.Println("error while parsing url: ", err)
}
http.Handle(url.Path, websocket.Handler(func(ws *websocket.Conn) {
// header := ws.Request().Header
// url := ws.Request().URL
// //stam := header.Get("Origin")
// fmt.Printf("header: %v\nurl: %v\n", header, url)
// io.Copy(ws, ws)
ws.PayloadType = websocket.BinaryFrame
handlerFunc(ws, wsServer.cfg)
}))
// http.HandleFunc(url.Path,
// func(w http.ResponseWriter, req *http.Request) {
// sessionId := req.URL.Query().Get("sessionId")
// s := websocket.Server{Handshake: checkOrigin, Handler: websocket.Handler(
// func(ws *websocket.ServerConn) {
// ws.PayloadType = websocket.BinaryFrame
// handlerFunc(ws, wsServer.cfg, sessionId)
// })}
// s.ServeHTTP(w, req)
// })
http.Handle(url.Path, websocket.Handler(
func(ws *websocket.Conn) {
path := ws.Request().URL.Path
var sessionId string
if path != "" {
sessionId = path[1:]
}
ws.PayloadType = websocket.BinaryFrame
handlerFunc(ws, wsServer.cfg, sessionId)
}))
err = http.ListenAndServe(url.Host, nil)
if err != nil {