debug needed

This commit is contained in:
TonyChyi 2022-09-26 16:07:25 +08:00
parent bd0812cc42
commit 821c0cffb8
12 changed files with 148 additions and 171 deletions

View File

@ -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 {

View File

@ -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",
}
command := CommandLine{
Args: CommandLine{
Command: fmt.Sprintf(cmdTemplate, args...),
},
}
template.Args = command
return template
}

View File

@ -1,7 +0,0 @@
package qemuconnection
import "github.com/sirupsen/logrus"
func init() {
logrus.Info("qemu client control events module loaded")
}

View File

@ -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)
})

View File

@ -1,7 +0,0 @@
package webrtcconnection
import "github.com/sirupsen/logrus"
func init() {
logrus.Info("webrtc connection module initialized")
}

View File

@ -10,7 +10,7 @@ import (
)
func init() {
logrus.Info("Starting...")
logrus.SetReportCaller(true)
}
func main() {

View File

@ -1,7 +0,0 @@
package qemuserver
import "github.com/sirupsen/logrus"
func init() {
logrus.Info("qemu server loaded")
}

View File

@ -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 {

View File

@ -1,7 +0,0 @@
package webserver
import "github.com/sirupsen/logrus"
func init() {
logrus.Info("web server loaded")
}

View File

@ -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)
}
}()
}

View File

@ -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"
}

View File

@ -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,6 +87,8 @@ onMounted(() => {
video.autoplay = true;
video.controls = false;
};
dataChannel.onopen = () => {
video.onmousemove = (ev) => {
dataChannel.send(
JSON.stringify(
@ -129,6 +132,7 @@ onMounted(() => {
)
);
};
};
pc.createOffer().then((offer) => {
pc.setLocalDescription(offer);