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 #!/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 -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 # 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 return
} }
this._peer = new RTCPeerConnection({ this._peer = new RTCPeerConnection()
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }],
})
this._peer.onicecandidate = event => { this._peer.onicecandidate = event => {
if (event.candidate === null && this._peer!.localDescription) { 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._peer.oniceconnectionstatechange = event => {
this._state = this._peer!.iceConnectionState 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) { switch (this._state) {
case 'checking': case 'checking':

View File

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

View File

@ -7,17 +7,19 @@ import (
"github.com/pion/webrtc/v2" "github.com/pion/webrtc/v2"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"n.eko.moe/neko/internal/utils"
) )
type WebRTC struct { type WebRTC struct {
Device string Device string
AudioCodec string AudioCodec string
AudioParams string AudioParams string
Display string Display string
VideoCodec string VideoCodec string
VideoParams string VideoParams string
EphemeralStart uint16 EphemeralMin uint16
EphemeralEnd uint16 EphemeralMax uint16
NAT1To1IPs []string
} }
func (WebRTC) Init(cmd *cobra.Command) error { func (WebRTC) Init(cmd *cobra.Command) error {
@ -83,6 +85,11 @@ func (WebRTC) Init(cmd *cobra.Command) error {
return err 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 return nil
} }
@ -113,19 +120,34 @@ func (s *WebRTC) Set() {
s.Display = viper.GetString("display") s.Display = viper.GetString("display")
s.VideoCodec = videoCodec s.VideoCodec = videoCodec
s.VideoParams = viper.GetString("vparams") s.VideoParams = viper.GetString("vparams")
s.EphemeralStart = 59000 s.NAT1To1IPs = viper.GetStringSlice("ip")
s.EphemeralEnd = 59100
ip, err := utils.GetIP()
if err == nil {
s.NAT1To1IPs = append(s.NAT1To1IPs, ip)
}
min := uint16(59000)
max := uint16(59100)
epr := viper.GetString("epr") epr := viper.GetString("epr")
ports := strings.SplitN(epr, "-", -1) ports := strings.SplitN(epr, "-", -1)
if len(ports[0]) > 1 { if len(ports[0]) > 1 {
start, err := strconv.ParseUint(ports[0], 16, 16) start, err := strconv.ParseUint(ports[0], 16, 16)
if err == nil { if err == nil {
s.EphemeralStart = uint16(start) min = uint16(start)
} }
end, err := strconv.ParseUint(ports[1], 16, 16) end, err := strconv.ParseUint(ports[1], 16, 16)
if err == nil { 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.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{ return &WebRTCManager{
logger: logger, logger: logger,
@ -33,11 +35,6 @@ func New(sessions types.SessionManager, config *config.WebRTC) *WebRTCManager {
sessions: sessions, sessions: sessions,
config: config, config: config,
configuration: &webrtc.Configuration{ configuration: &webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
URLs: []string{"stun:stun.l.google.com:19302"},
},
},
SDPSemantics: webrtc.SDPSemanticsUnifiedPlanWithFallback, SDPSemantics: webrtc.SDPSemanticsUnifiedPlanWithFallback,
}, },
} }