23 lines
668 B
Go
23 lines
668 B
Go
package websocket
|
|
|
|
import (
|
|
"github.com/maddalax/htmgo/extensions/ws/internal/wsutil"
|
|
"github.com/maddalax/htmgo/extensions/ws/ws"
|
|
"github.com/maddalax/htmgo/framework/h"
|
|
"github.com/maddalax/htmgo/framework/service"
|
|
)
|
|
|
|
type WsExtensionOpts struct {
|
|
WsPath string
|
|
}
|
|
|
|
func EnableExtension(app *h.App, opts WsExtensionOpts) {
|
|
if app.Opts.ServiceLocator == nil {
|
|
app.Opts.ServiceLocator = service.NewLocator()
|
|
}
|
|
service.Set[wsutil.SocketManager](app.Opts.ServiceLocator, service.Singleton, func() *wsutil.SocketManager {
|
|
return wsutil.NewSocketManager()
|
|
})
|
|
ws.StartListener(app.Opts.ServiceLocator)
|
|
app.Router.Handle(opts.WsPath, wsutil.WsHttpHandler())
|
|
}
|