mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
allow to add password protected turn server
This commit is contained in:
parent
e27b98d509
commit
29b4881c08
11
README.md
11
README.md
@ -278,7 +278,16 @@ NEKO_CERT:
|
|||||||
NEKO_KEY:
|
NEKO_KEY:
|
||||||
- Path to the SSL-Certificate private key
|
- Path to the SSL-Certificate private key
|
||||||
- e.g. '/certs/key.pem'
|
- e.g. '/certs/key.pem'
|
||||||
|
NEKO_ICELITE:
|
||||||
|
- Use the ice lite protocol
|
||||||
|
- e.g. false
|
||||||
|
NEKO_ICESERVER:
|
||||||
|
- Describes a single STUN and TURN server that can be used by the ICEAgent to establish a connection with a peer (deprecated)
|
||||||
|
- e.g. 'stun:stun.l.google.com:19302'
|
||||||
|
NEKO_ICESERVERS:
|
||||||
|
- Describes multiple STUN and TURN server that can be used by the ICEAgent to establish a connection with a peer
|
||||||
|
- e.g. '[{"urls": ["turn:turn.example.com:19302", "stun:stun.example.com:19302"], "username": "name", "credential": "password"}, {"urls": ["stun:stun.example2.com:19302"]}]'
|
||||||
|
- [More information](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer)
|
||||||
```
|
```
|
||||||
|
|
||||||
# How to contribute?
|
# How to contribute?
|
||||||
|
@ -183,7 +183,7 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
this._ws!.send(JSON.stringify({ event, ...payload }))
|
this._ws!.send(JSON.stringify({ event, ...payload }))
|
||||||
}
|
}
|
||||||
|
|
||||||
public createPeer(sdp: string, lite: boolean, servers: string[]) {
|
public createPeer(sdp: string, lite: boolean, servers: string) {
|
||||||
this.emit('debug', `creating peer`)
|
this.emit('debug', `creating peer`)
|
||||||
if (!this.socketOpen) {
|
if (!this.socketOpen) {
|
||||||
this.emit(
|
this.emit(
|
||||||
@ -202,7 +202,7 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
|
|||||||
this._peer = new RTCPeerConnection()
|
this._peer = new RTCPeerConnection()
|
||||||
if (lite !== true) {
|
if (lite !== true) {
|
||||||
this._peer = new RTCPeerConnection({
|
this._peer = new RTCPeerConnection({
|
||||||
iceServers: [{ urls: servers }],
|
iceServers: JSON.parse(servers),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ export interface SignalProvideMessage extends WebSocketMessage, SignalProvidePay
|
|||||||
export interface SignalProvidePayload {
|
export interface SignalProvidePayload {
|
||||||
id: string
|
id: string
|
||||||
lite: boolean
|
lite: boolean
|
||||||
ice: string[]
|
ice: string
|
||||||
sdp: string
|
sdp: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,15 +3,18 @@ package config
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"n.eko.moe/neko/internal/utils"
|
"n.eko.moe/neko/internal/utils"
|
||||||
|
|
||||||
|
"github.com/pion/webrtc/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WebRTC struct {
|
type WebRTC struct {
|
||||||
ICELite bool
|
ICELite bool
|
||||||
ICEServers []string
|
ICEServers []webrtc.ICEServer
|
||||||
EphemeralMin uint16
|
EphemeralMin uint16
|
||||||
EphemeralMax uint16
|
EphemeralMax uint16
|
||||||
NAT1To1IPs []string
|
NAT1To1IPs []string
|
||||||
@ -38,12 +41,24 @@ func (WebRTC) Init(cmd *cobra.Command) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd.PersistentFlags().String("iceservers", "", "describes a single STUN and TURN server that can be used by the ICEAgent to establish a connection with a peer")
|
||||||
|
if err := viper.BindPFlag("iceservers", cmd.PersistentFlags().Lookup("iceservers")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WebRTC) Set() {
|
func (s *WebRTC) Set() {
|
||||||
s.ICELite = viper.GetBool("icelite")
|
s.ICELite = viper.GetBool("icelite")
|
||||||
s.ICEServers = viper.GetStringSlice("iceserver")
|
s.ICEServers = []webrtc.ICEServer{{URLs: viper.GetStringSlice("iceserver")}}
|
||||||
|
if (viper.GetString("iceservers") != "") {
|
||||||
|
errj := json.Unmarshal([]byte(viper.GetString("iceservers")), &s.ICEServers)
|
||||||
|
if (errj != nil) {
|
||||||
|
panic(errj)
|
||||||
|
}
|
||||||
|
}
|
||||||
s.NAT1To1IPs = viper.GetStringSlice("nat1to1")
|
s.NAT1To1IPs = viper.GetStringSlice("nat1to1")
|
||||||
|
|
||||||
if len(s.NAT1To1IPs) == 0 {
|
if len(s.NAT1To1IPs) == 0 {
|
||||||
|
@ -18,7 +18,7 @@ type SignalProvide struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
SDP string `json:"sdp"`
|
SDP string `json:"sdp"`
|
||||||
Lite bool `json:"lite"`
|
Lite bool `json:"lite"`
|
||||||
ICE []string `json:"ice"`
|
ICE string `json:"ice"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SignalAnswer struct {
|
type SignalAnswer struct {
|
||||||
|
@ -2,6 +2,8 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pion/webrtc/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Sample struct {
|
type Sample struct {
|
||||||
@ -13,7 +15,7 @@ type Sample struct {
|
|||||||
type WebRTCManager interface {
|
type WebRTCManager interface {
|
||||||
Start()
|
Start()
|
||||||
Shutdown() error
|
Shutdown() error
|
||||||
CreatePeer(id string, session Session) (string, bool, []string, error)
|
CreatePeer(id string, session Session) (string, bool, []webrtc.ICEServer, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Peer interface {
|
type Peer interface {
|
||||||
|
@ -63,7 +63,7 @@ func (manager *WebRTCManager) Start() {
|
|||||||
|
|
||||||
manager.logger.Info().
|
manager.logger.Info().
|
||||||
Str("ice_lite", fmt.Sprintf("%t", manager.config.ICELite)).
|
Str("ice_lite", fmt.Sprintf("%t", manager.config.ICELite)).
|
||||||
Str("ice_servers", strings.Join(manager.config.ICEServers, ",")).
|
Str("ice_servers", fmt.Sprintf("%+v", manager.config.ICEServers)).
|
||||||
Str("ephemeral_port_range", fmt.Sprintf("%d-%d", manager.config.EphemeralMin, manager.config.EphemeralMax)).
|
Str("ephemeral_port_range", fmt.Sprintf("%d-%d", manager.config.EphemeralMin, manager.config.EphemeralMax)).
|
||||||
Str("nat_ips", strings.Join(manager.config.NAT1To1IPs, ",")).
|
Str("nat_ips", strings.Join(manager.config.NAT1To1IPs, ",")).
|
||||||
Msgf("webrtc starting")
|
Msgf("webrtc starting")
|
||||||
@ -74,13 +74,9 @@ func (manager *WebRTCManager) Shutdown() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *WebRTCManager) CreatePeer(id string, session types.Session) (string, bool, []string, error) {
|
func (manager *WebRTCManager) CreatePeer(id string, session types.Session) (string, bool, []webrtc.ICEServer, error) {
|
||||||
configuration := &webrtc.Configuration{
|
configuration := &webrtc.Configuration{
|
||||||
ICEServers: []webrtc.ICEServer{
|
ICEServers: manager.config.ICEServers,
|
||||||
{
|
|
||||||
URLs: manager.config.ICEServers,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
SDPSemantics: webrtc.SDPSemanticsUnifiedPlanWithFallback,
|
SDPSemantics: webrtc.SDPSemanticsUnifiedPlanWithFallback,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
"n.eko.moe/neko/internal/types"
|
"n.eko.moe/neko/internal/types"
|
||||||
"n.eko.moe/neko/internal/types/event"
|
"n.eko.moe/neko/internal/types/event"
|
||||||
"n.eko.moe/neko/internal/types/message"
|
"n.eko.moe/neko/internal/types/message"
|
||||||
@ -12,12 +14,17 @@ func (h *MessageHandler) signalProvide(id string, session types.Session) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp, err := json.Marshal(ice)
|
||||||
|
if (err != nil) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := session.Send(message.SignalProvide{
|
if err := session.Send(message.SignalProvide{
|
||||||
Event: event.SIGNAL_PROVIDE,
|
Event: event.SIGNAL_PROVIDE,
|
||||||
ID: id,
|
ID: id,
|
||||||
SDP: sdp,
|
SDP: sdp,
|
||||||
Lite: lite,
|
Lite: lite,
|
||||||
ICE: ice,
|
ICE: string(tmp),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user