mirror of
https://github.com/amitbet/vncproxy.git
synced 2025-09-21 17:39:28 +00:00
created proxy and listeners to connect recorder and server-client cross writing
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user