potential fix for #25

This commit is contained in:
Craig 2020-02-10 07:13:40 +00:00
parent f422db4eb5
commit 3d1341cfe1
6 changed files with 74 additions and 23 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
# sudo docker run -p 80:8080 -p 59000-59100:59000-59100/udp --cap-add SYS_ADMIN nurdism/neko:chromium
# sudo docker run -p 80:8080 -p 59000-59100:59000-59100/udp --cap-add SYS_ADMIN --shm-size=1gb nurdism/neko:chromium
# sudo docker run -p 80:8080 -p 59000-59100:59000-59100/udp --shm-size=1gb nurdism/neko:firefox
# sudo docker run --network host --shm-size=1gb -it nurdism/neko:base /bin/bash

View File

@ -151,9 +151,7 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
return
}
this._peer = new RTCPeerConnection({
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
})
this._peer = new RTCPeerConnection()
this._peer.onicecandidate = event => {
if (event.candidate === null && this._peer!.localDescription) {
@ -167,9 +165,18 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
}
}
this._peer.onsignalingstatechange = event => {
this.emit('debug', `peer signal state chagned: ${this._peer!.signalingState}`)
}
this._peer.onconnectionstatechange = event => {
this.emit('debug', `peer connection state chagned: ${this._peer!.connectionState}`)
}
this._peer.oniceconnectionstatechange = event => {
this._state = this._peer!.iceConnectionState
this.emit('debug', `peer connection state chagned: ${this._state}`)
this.emit('debug', `peer ice connection state chagned: ${this._peer!.iceConnectionState}`)
switch (this._state) {
case 'checking':

View File

@ -1,6 +1,7 @@
const path = require('path')
module.exports = {
productionSourceMap: false,
css: {
loaderOptions: {
sass: {

View File

@ -7,17 +7,19 @@ import (
"github.com/pion/webrtc/v2"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"n.eko.moe/neko/internal/utils"
)
type WebRTC struct {
Device string
AudioCodec string
AudioParams string
Display string
VideoCodec string
VideoParams string
EphemeralStart uint16
EphemeralEnd uint16
Device string
AudioCodec string
AudioParams string
Display string
VideoCodec string
VideoParams string
EphemeralMin uint16
EphemeralMax uint16
NAT1To1IPs []string
}
func (WebRTC) Init(cmd *cobra.Command) error {
@ -83,6 +85,11 @@ func (WebRTC) Init(cmd *cobra.Command) error {
return err
}
cmd.PersistentFlags().StringSlice("ip", []string{}, "sets a list of external IP addresses of 1:1 (D)NAT and a candidate type for which the external IP address is used")
if err := viper.BindPFlag("ip", cmd.PersistentFlags().Lookup("ip")); err != nil {
return err
}
return nil
}
@ -113,19 +120,34 @@ func (s *WebRTC) Set() {
s.Display = viper.GetString("display")
s.VideoCodec = videoCodec
s.VideoParams = viper.GetString("vparams")
s.EphemeralStart = 59000
s.EphemeralEnd = 59100
s.NAT1To1IPs = viper.GetStringSlice("ip")
ip, err := utils.GetIP()
if err == nil {
s.NAT1To1IPs = append(s.NAT1To1IPs, ip)
}
min := uint16(59000)
max := uint16(59100)
epr := viper.GetString("epr")
ports := strings.SplitN(epr, "-", -1)
if len(ports[0]) > 1 {
start, err := strconv.ParseUint(ports[0], 16, 16)
if err == nil {
s.EphemeralStart = uint16(start)
min = uint16(start)
}
end, err := strconv.ParseUint(ports[1], 16, 16)
if err == nil {
s.EphemeralEnd = uint16(end)
max = uint16(end)
}
}
if min > max {
s.EphemeralMin = max
s.EphemeralMax = min
} else {
s.EphemeralMin = min
s.EphemeralMax = max
}
}

View File

@ -0,0 +1,24 @@
package utils
import (
"bytes"
"io/ioutil"
"net/http"
)
// dig @resolver1.opendns.com ANY myip.opendns.com +short -4
func GetIP() (string, error) {
rsp, err := http.Get("http://checkip.amazonaws.com")
if err != nil {
return "", err
}
defer rsp.Body.Close()
buf, err := ioutil.ReadAll(rsp.Body)
if err != nil {
return "", err
}
return string(bytes.TrimSpace(buf)), nil
}

View File

@ -22,8 +22,10 @@ func New(sessions types.SessionManager, config *config.WebRTC) *WebRTCManager {
},
}
settings.SetLite(true)
settings.SetNetworkTypes([]webrtc.NetworkType{webrtc.NetworkTypeUDP4})
settings.SetEphemeralUDPPortRange(config.EphemeralStart, config.EphemeralEnd)
settings.SetEphemeralUDPPortRange(config.EphemeralMin, config.EphemeralMax)
settings.SetNAT1To1IPs(config.NAT1To1IPs, webrtc.ICECandidateTypeHost)
return &WebRTCManager{
logger: logger,
@ -33,11 +35,6 @@ func New(sessions types.SessionManager, config *config.WebRTC) *WebRTCManager {
sessions: sessions,
config: config,
configuration: &webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
},
},
SDPSemantics: webrtc.SDPSemanticsUnifiedPlanWithFallback,
},
}