rework needed

This commit is contained in:
TonyChyi
2022-09-27 10:21:06 +08:00
parent 821c0cffb8
commit 18f5d649d1
9 changed files with 141 additions and 104 deletions

View File

@@ -1,9 +1,11 @@
package webrtcconnection
import (
"git.sense-t.eu.org/ACE/ace/servers/qemuserver"
"github.com/pion/mediadevices"
"github.com/pion/mediadevices/pkg/codec/opus"
"github.com/pion/mediadevices/pkg/codec/x264"
"github.com/pion/mediadevices/pkg/driver"
"github.com/pion/webrtc/v3"
"github.com/sirupsen/logrus"
)
@@ -14,6 +16,7 @@ type Connection struct {
option *Options
api *webrtc.API
stream mediadevices.MediaStream
QEMU *qemuserver.Server
}
func New(o *Options) (*Connection, error) {
@@ -30,6 +33,17 @@ func New(o *Options) (*Connection, error) {
connection.api = webrtc.NewAPI(webrtc.WithMediaEngine(me))
logrus.Debug("list devices:")
logrus.Debug("------")
devices := driver.GetManager().Query(func(d driver.Driver) bool { return true })
for _, device := range devices {
logrus.Debug(device.ID())
logrus.Debug(device.Info())
logrus.Debug(device.Properties())
logrus.Debug(device.Status())
logrus.Debug("------")
}
s, err := mediadevices.GetUserMedia(mediadevices.MediaStreamConstraints{
Video: func(mtc *mediadevices.MediaTrackConstraints) {},
Audio: func(mtc *mediadevices.MediaTrackConstraints) {},
@@ -44,7 +58,7 @@ func New(o *Options) (*Connection, error) {
}
func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDescription, error) {
logrus.Debug("received offer ", offer.Type.String())
logrus.Debug("received offer ", offer)
rtc, err := c.api.NewPeerConnection(webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
@@ -80,7 +94,7 @@ func (c *Connection) Regist(offer *webrtc.SessionDescription) (*webrtc.SessionDe
}
}
rtc.OnDataChannel(dataChannel)
rtc.OnDataChannel(c.dataChannel)
if err := rtc.SetRemoteDescription(*offer); err != nil {
return nil, err

View File

@@ -4,15 +4,14 @@ import (
"encoding/json"
"time"
"git.sense-t.eu.org/ACE/ace/servers/qemuserver"
"github.com/pion/webrtc/v3"
"github.com/sirupsen/logrus"
)
func dataChannel(d *webrtc.DataChannel) {
func (c *Connection) dataChannel(d *webrtc.DataChannel) {
d.OnOpen(func() {
for {
status := qemuserver.GetStatus().String()
status := c.QEMU.GetStatus().String()
currentTime := time.Now().UnixMilli()
b, err := json.Marshal(map[string]any{
@@ -40,7 +39,7 @@ func dataChannel(d *webrtc.DataChannel) {
if !msg.IsString {
return
}
if err := qemuserver.SendEvent(msg.Data); err != nil {
if err := c.QEMU.SendEvent(msg.Data); err != nil {
logrus.Errorf(
"cannot parse message from '%s-%d' to qemu controll event: %v",
d.Label(), *d.ID(), err,