mirror of
https://github.com/yudai/gotty.git
synced 2026-03-03 20:30:16 +01:00
ws: enable factory to react to state of ws conn
This commit is contained in:
parent
29695481fa
commit
42d8a51a93
3 changed files with 7 additions and 3 deletions
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ghthor/gotty/v2/server"
|
"github.com/ghthor/gotty/v2/server"
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
|
|
@ -37,7 +38,7 @@ func (factory *Factory) Name() string {
|
||||||
return "local command"
|
return "local command"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (factory *Factory) New(params map[string][]string) (server.Slave, error) {
|
func (factory *Factory) New(params map[string][]string, conn *websocket.Conn) (server.Slave, error) {
|
||||||
argv := make([]string, len(factory.argv))
|
argv := make([]string, len(factory.argv))
|
||||||
copy(argv, factory.argv)
|
copy(argv, factory.argv)
|
||||||
if params["arg"] != nil && len(params["arg"]) > 0 {
|
if params["arg"] != nil && len(params["arg"]) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -115,8 +115,9 @@ func (server *Server) processWSConn(ctx context.Context, conn *websocket.Conn) e
|
||||||
return errors.Wrapf(err, "failed to parse arguments")
|
return errors.Wrapf(err, "failed to parse arguments")
|
||||||
}
|
}
|
||||||
params := query.Query()
|
params := query.Query()
|
||||||
|
|
||||||
var slave Slave
|
var slave Slave
|
||||||
slave, err = server.factory.New(params)
|
slave, err = server.factory.New(params, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to create backend")
|
return errors.Wrapf(err, "failed to create backend")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ghthor/gotty/v2/webtty"
|
"github.com/ghthor/gotty/v2/webtty"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Slave is webtty.Slave with some additional methods.
|
// Slave is webtty.Slave with some additional methods.
|
||||||
|
|
@ -13,5 +15,5 @@ type Slave interface {
|
||||||
|
|
||||||
type Factory interface {
|
type Factory interface {
|
||||||
Name() string
|
Name() string
|
||||||
New(params map[string][]string) (Slave, error)
|
New(params map[string][]string, conn *websocket.Conn) (Slave, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue