debug needed
This commit is contained in:
parent
bd0812cc42
commit
821c0cffb8
@ -38,10 +38,16 @@ func (s *Server) Run() error {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
|
||||
qemuserver.Setup(s.options.Qemu)
|
||||
webserver.Setup(s.options.WEBServer)
|
||||
<-make(chan int)
|
||||
return nil
|
||||
if err := qemuserver.Setup(s.options.Qemu); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
webServer, err := webserver.NewServer(s.options.WEBServer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return webServer.Run()
|
||||
}
|
||||
|
||||
func runServer(c *cli.Context) error {
|
||||
|
@ -77,14 +77,10 @@ func makeControlCommand(t int) []qmp.Command {
|
||||
}
|
||||
|
||||
func makeHMCommand(cmdTemplate string, args ...any) qmp.Command {
|
||||
template := qmp.Command{
|
||||
return qmp.Command{
|
||||
Execute: "human-monitor-command",
|
||||
Args: CommandLine{
|
||||
Command: fmt.Sprintf(cmdTemplate, args...),
|
||||
},
|
||||
}
|
||||
command := CommandLine{
|
||||
Command: fmt.Sprintf(cmdTemplate, args...),
|
||||
}
|
||||
|
||||
template.Args = command
|
||||
|
||||
return template
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
package qemuconnection
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
func init() {
|
||||
logrus.Info("qemu client control events module loaded")
|
||||
}
|
@ -12,26 +12,41 @@ const DefaultStreamID = "ace-server"
|
||||
|
||||
type Connection struct {
|
||||
option *Options
|
||||
api *webrtc.API
|
||||
stream mediadevices.MediaStream
|
||||
}
|
||||
|
||||
func New(o *Options) *Connection {
|
||||
return &Connection{
|
||||
func New(o *Options) (*Connection, error) {
|
||||
connection := &Connection{
|
||||
option: o,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDescription, error) {
|
||||
logrus.Debug("received offer ", offer.Type.String())
|
||||
codecSelector, err := setupCodec(c.option.Video.BPS, c.option.Audio.BPS)
|
||||
codecSelector, err := setupCodec(o.Video.BPS, o.Audio.BPS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
me := &webrtc.MediaEngine{}
|
||||
codecSelector.Populate(me)
|
||||
api := webrtc.NewAPI(webrtc.WithMediaEngine(me))
|
||||
|
||||
rtc, err := api.NewPeerConnection(webrtc.Configuration{
|
||||
connection.api = webrtc.NewAPI(webrtc.WithMediaEngine(me))
|
||||
|
||||
s, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
|
||||
Video: func(mtc *mediadevices.MediaTrackConstraints) {},
|
||||
Audio: func(mtc *mediadevices.MediaTrackConstraints) {},
|
||||
Codec: codecSelector,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
connection.stream = s
|
||||
|
||||
return connection, nil
|
||||
}
|
||||
|
||||
func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDescription, error) {
|
||||
logrus.Debug("received offer ", offer.Type.String())
|
||||
|
||||
rtc, err := c.api.NewPeerConnection(webrtc.Configuration{
|
||||
ICEServers: []webrtc.ICEServer{
|
||||
{
|
||||
URLs: c.option.STUNServers,
|
||||
@ -53,21 +68,7 @@ func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDe
|
||||
}
|
||||
})
|
||||
|
||||
s, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
|
||||
Video: func(mtc *mediadevices.MediaTrackConstraints) {
|
||||
/*
|
||||
mtc.Height = prop.IntExact(c.option.Video.Height)
|
||||
mtc.Width = prop.IntExact(c.option.Video.Width)
|
||||
*/
|
||||
},
|
||||
Audio: func(mtc *mediadevices.MediaTrackConstraints) {},
|
||||
Codec: codecSelector,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, track := range s.GetTracks() {
|
||||
for _, track := range c.stream.GetTracks() {
|
||||
track.OnEnded(func(err error) {
|
||||
logrus.Errorf("Track (ID: %s) ended with error: %v", track.ID(), err)
|
||||
})
|
||||
|
@ -1,7 +0,0 @@
|
||||
package webrtcconnection
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
func init() {
|
||||
logrus.Info("webrtc connection module initialized")
|
||||
}
|
2
main.go
2
main.go
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
logrus.Info("Starting...")
|
||||
logrus.SetReportCaller(true)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -1,7 +0,0 @@
|
||||
package qemuserver
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
func init() {
|
||||
logrus.Info("qemu server loaded")
|
||||
}
|
@ -19,25 +19,25 @@ type Server struct {
|
||||
RX chan *qemuconnection.Event
|
||||
TX chan qemu.Status
|
||||
}
|
||||
qemu *qemu.Domain
|
||||
}
|
||||
|
||||
var DefaultServer *Server
|
||||
|
||||
func NewServer(o *Options) *Server {
|
||||
func NewServer(o *Options) (*Server, error) {
|
||||
if err := o.MakeFIFO(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
server := &Server{
|
||||
options: o,
|
||||
}
|
||||
server.QmpConnector.RX = make(chan *qemuconnection.Event)
|
||||
server.QmpConnector.TX = make(chan qemu.Status)
|
||||
return server
|
||||
}
|
||||
|
||||
func (s *Server) Run() error {
|
||||
logrus.Debug("qemu server running")
|
||||
defer logrus.Debug("qemu server exit")
|
||||
u, err := url.Parse(s.options.QmpAddress)
|
||||
u, err := url.Parse(o.QmpAddress)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
var address string
|
||||
if u.Scheme == "unix" {
|
||||
@ -46,29 +46,57 @@ func (s *Server) Run() error {
|
||||
address = u.Host
|
||||
}
|
||||
logrus.Debugf("trying to connect qmp with %s://%s", u.Scheme, address)
|
||||
qmpConnection, err := qmp.NewSocketMonitor(u.Scheme, address, s.options.Timeout)
|
||||
qmpConnection, err := qmp.NewSocketMonitor(u.Scheme, address, o.Timeout)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
defer qmpConnection.Disconnect()
|
||||
|
||||
if err := qmpConnection.Connect(); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
logrus.Debug("qmp connected")
|
||||
|
||||
qemu, err := qemu.NewDomain(qmpConnection, s.options.Name)
|
||||
qemu, err := qemu.NewDomain(qmpConnection, o.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
defer qemu.Close()
|
||||
server.qemu = qemu
|
||||
|
||||
go s.startCapture(qemu)
|
||||
if err := driver.GetManager().Register(
|
||||
audiodriver.New(o.AudioPipe),
|
||||
driver.Info{
|
||||
Label: "audioFifo",
|
||||
DeviceType: driver.Microphone,
|
||||
Priority: driver.PriorityNormal,
|
||||
},
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := driver.GetManager().Register(
|
||||
vncdriver.NewVnc(o.VNCAddress),
|
||||
driver.Info{
|
||||
Label: "vnc",
|
||||
DeviceType: driver.Camera,
|
||||
Priority: driver.PriorityNormal,
|
||||
},
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return server, nil
|
||||
}
|
||||
|
||||
func (s *Server) Run() error {
|
||||
logrus.Debug("qemu server running")
|
||||
defer logrus.Debug("qemu server exit")
|
||||
defer s.qemu.Close()
|
||||
|
||||
go s.startCapture()
|
||||
logrus.Debug("qemu capture start")
|
||||
|
||||
for ev := range s.QmpConnector.RX {
|
||||
if ev.Type == qemuconnection.QueryStatusEvent {
|
||||
status, err := qemu.Status()
|
||||
status, err := s.qemu.Status()
|
||||
if err != nil {
|
||||
logrus.Error("get qemu status error: ", err)
|
||||
continue
|
||||
@ -77,43 +105,17 @@ func (s *Server) Run() error {
|
||||
continue
|
||||
}
|
||||
for _, cmd := range ev.ToQemuCommand() {
|
||||
_, err := qemu.Run(cmd)
|
||||
_, err := s.qemu.Run(cmd)
|
||||
if err != nil {
|
||||
logrus.Error("run command error: ", err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) startCapture(qemu *qemu.Domain) {
|
||||
if err := s.options.MakeFIFO(); err != nil {
|
||||
logrus.Fatal("failed to make pipe file: ", err)
|
||||
}
|
||||
|
||||
if err := driver.GetManager().Register(
|
||||
audiodriver.New(s.options.AudioPipe),
|
||||
driver.Info{
|
||||
Label: "audioFifo",
|
||||
DeviceType: driver.Microphone,
|
||||
Priority: driver.PriorityNormal,
|
||||
},
|
||||
); err != nil {
|
||||
logrus.Fatal("audio initialize failed: ", err)
|
||||
}
|
||||
if err := driver.GetManager().Register(
|
||||
vncdriver.NewVnc(s.options.VNCAddress),
|
||||
driver.Info{
|
||||
Label: "vnc",
|
||||
DeviceType: driver.Camera,
|
||||
Priority: driver.PriorityNormal,
|
||||
},
|
||||
); err != nil {
|
||||
logrus.Fatal("video initialize failed: ", err)
|
||||
}
|
||||
|
||||
if _, err := qemu.Run(qmp.Command{
|
||||
func (s *Server) startCapture() {
|
||||
if _, err := s.qemu.Run(qmp.Command{
|
||||
Execute: "human-monitor-command",
|
||||
Args: map[string]string{
|
||||
"command-line": fmt.Sprintf(
|
||||
@ -128,13 +130,17 @@ func (s *Server) startCapture(qemu *qemu.Domain) {
|
||||
logrus.Debug("audio capture set")
|
||||
}
|
||||
|
||||
func Setup(o *Options) {
|
||||
DefaultServer = NewServer(o)
|
||||
func Setup(o *Options) error {
|
||||
DefaultServer, err := NewServer(o)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
if err := DefaultServer.Run(); err != nil {
|
||||
logrus.Fatal("cannot run qemuserver with error: ", err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
func SendEvent(b []byte) error {
|
||||
|
@ -1,7 +0,0 @@
|
||||
package webserver
|
||||
|
||||
import "github.com/sirupsen/logrus"
|
||||
|
||||
func init() {
|
||||
logrus.Info("web server loaded")
|
||||
}
|
@ -12,15 +12,18 @@ type Server struct {
|
||||
rtcConnector *webrtcconnection.Connection
|
||||
}
|
||||
|
||||
var DefaultServer *Server
|
||||
func NewServer(o *Options) (*Server, error) {
|
||||
rtc, err := webrtcconnection.New(o.WebRTC)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func NewServer(o *Options) *Server {
|
||||
s := &Server{
|
||||
options: o,
|
||||
webServer: gin.New(),
|
||||
rtcConnector: webrtcconnection.New(o.WebRTC),
|
||||
rtcConnector: rtc,
|
||||
}
|
||||
return s
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Server) Run() error {
|
||||
@ -29,12 +32,3 @@ func (s *Server) Run() error {
|
||||
s.setupRoute()
|
||||
return s.webServer.Run(s.options.Listen)
|
||||
}
|
||||
|
||||
func Setup(o *Options) {
|
||||
DefaultServer = NewServer(o)
|
||||
go func() {
|
||||
if err := DefaultServer.Run(); err != nil {
|
||||
logrus.Fatal("cannot run webserver with error: ", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -26,8 +26,6 @@ func staticFileHandler() gin.HandlerFunc {
|
||||
defer ctx.Abort()
|
||||
filename := strings.TrimLeft(ctx.Request.RequestURI, "/")
|
||||
|
||||
logrus.Debug("static file: ", filename)
|
||||
|
||||
if filename == "" {
|
||||
filename = "index.html"
|
||||
}
|
||||
|
@ -74,8 +74,9 @@ onMounted(() => {
|
||||
});
|
||||
pc.oniceconnectionstatechange = () => console.log(pc.iceConnectionState);
|
||||
pc.addTransceiver("video");
|
||||
//pc.addTransceiver('audio')
|
||||
dataChannel = pc.createDataChannel("control");
|
||||
pc.addTransceiver("audio");
|
||||
|
||||
const dataChannel = pc.createDataChannel("control");
|
||||
dataChannel.onmessage = (e) => {
|
||||
const d = JSON.parse(e.data);
|
||||
store.delay = +new Date() - d.server_time;
|
||||
@ -86,48 +87,51 @@ onMounted(() => {
|
||||
video.autoplay = true;
|
||||
video.controls = false;
|
||||
};
|
||||
video.onmousemove = (ev) => {
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("mouseMove", {
|
||||
dx: ev.clientX,
|
||||
dy: ev.clientY,
|
||||
dz: 0,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
video.onmousedown = (ev) => {
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("mouseButton", {
|
||||
button: ev.button << 1,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
//video.onmousewheel = (ev) => {};
|
||||
window.onkeydown = (ev) => {
|
||||
let key = "";
|
||||
if (ev.ctrlKey && ev.which !== 17) key = "ctrl-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.shiftKey && ev.which !== 16) key = "shift-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.altKey && ev.which !== 18) key = "alt-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.metaKey && ev.which !== 91 && ev.which !== 93)
|
||||
key = "meta-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (!ev.altKey && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey)
|
||||
key = "0x" + ev.which.toString(16);
|
||||
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("keyboard", {
|
||||
key: key,
|
||||
})
|
||||
)
|
||||
);
|
||||
dataChannel.onopen = () => {
|
||||
video.onmousemove = (ev) => {
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("mouseMove", {
|
||||
dx: ev.clientX,
|
||||
dy: ev.clientY,
|
||||
dz: 0,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
video.onmousedown = (ev) => {
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("mouseButton", {
|
||||
button: ev.button << 1,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
//video.onmousewheel = (ev) => {};
|
||||
window.onkeydown = (ev) => {
|
||||
let key = "";
|
||||
if (ev.ctrlKey && ev.which !== 17) key = "ctrl-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.shiftKey && ev.which !== 16) key = "shift-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.altKey && ev.which !== 18) key = "alt-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.metaKey && ev.which !== 91 && ev.which !== 93)
|
||||
key = "meta-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (!ev.altKey && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey)
|
||||
key = "0x" + ev.which.toString(16);
|
||||
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("keyboard", {
|
||||
key: key,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
pc.createOffer().then((offer) => {
|
||||
|
Loading…
Reference in New Issue
Block a user