sipgo
sipgo copied to clipboard
sipgo ws integarted in webserver
Hello!
Is is possible to integrate sipgo ws on a http server? In particular I am using Labstack Echo and trying to understand how to go about having /ws
using SIPGO and the rest as a simple webserver.
I am asking because all transports on sipgo start their own listener and that would not fit this presuppose.
package main
import (
"fmt"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"golang.org/x/net/websocket"
)
func hello(c echo.Context) error {
websocket.Handler(func(ws *websocket.Conn) {
defer ws.Close()
// use sipgo here
for {
// Write
err := websocket.Message.Send(ws, "Hello, Client!")
if err != nil {
c.Logger().Error(err)
}
// Read
msg := ""
err = websocket.Message.Receive(ws, &msg)
if err != nil {
c.Logger().Error(err)
}
fmt.Printf("%s\n", msg)
}
}).ServeHTTP(c.Response(), c.Request())
return nil
}
func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Static("/", "../public")
e.GET("/ws", hello)
e.Logger.Fatal(e.Start(":1323"))
}