install go2rtc on bob
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
# ngrok
|
||||
|
||||
With the ngrok integration, you can get external access to your streams when your Internet connection is behind a private IP address.
|
||||
|
||||
- you may need external access for two different things:
|
||||
- WebRTC streams (tunnel the WebRTC TCP port, e.g. 8555)
|
||||
- go2rtc web interface (tunnel the API HTTP port, e.g. 1984)
|
||||
- ngrok supports authorization for your web interface
|
||||
- ngrok automatically adds HTTPS to your web interface
|
||||
|
||||
The ngrok free subscription has the following limitations:
|
||||
|
||||
- You can reserve a free domain for serving the web interface, but the TCP address you get will always be random and will change with each restart of the ngrok agent (not a problem for WebRTC streams)
|
||||
- You can forward multiple ports from a single agent, but you can only run one ngrok agent on the free plan
|
||||
|
||||
go2rtc will automatically get your external TCP address (if you enable it in the ngrok config) and use it for WebRTC connections (if you enable it in the WebRTC config).
|
||||
|
||||
You need to manually download the [ngrok agent](https://ngrok.com/download) for your OS and register with the [ngrok service](https://ngrok.com/signup).
|
||||
|
||||
**Tunnel for only WebRTC Stream**
|
||||
|
||||
You need to add your [ngrok authtoken](https://dashboard.ngrok.com/get-started/your-authtoken) and WebRTC TCP port to YAML:
|
||||
|
||||
```yaml
|
||||
ngrok:
|
||||
command: ngrok tcp 8555 --authtoken eW91IHNoYWxsIG5vdCBwYXNzCnlvdSBzaGFsbCBub3QgcGFzcw
|
||||
```
|
||||
|
||||
**Tunnel for WebRTC and Web interface**
|
||||
|
||||
You need to create `ngrok.yaml` config file and add it to the go2rtc config:
|
||||
|
||||
```yaml
|
||||
ngrok:
|
||||
command: ngrok start --all --config ngrok.yaml
|
||||
```
|
||||
|
||||
ngrok config example:
|
||||
|
||||
```yaml
|
||||
version: "2"
|
||||
authtoken: eW91IHNoYWxsIG5vdCBwYXNzCnlvdSBzaGFsbCBub3QgcGFzcw
|
||||
tunnels:
|
||||
api:
|
||||
addr: 1984 # use the same port as in the go2rtc config
|
||||
proto: http
|
||||
basic_auth:
|
||||
- admin:password # you can set login/pass for your web interface
|
||||
webrtc:
|
||||
addr: 8555 # use the same port as in the go2rtc config
|
||||
proto: tcp
|
||||
```
|
||||
|
||||
See the [ngrok agent documentation](https://ngrok.com/docs/agent/config/) for more details on the ngrok configuration file.
|
||||
@@ -0,0 +1,84 @@
|
||||
package ngrok
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/internal/app"
|
||||
"github.com/AlexxIT/go2rtc/internal/webrtc"
|
||||
"github.com/AlexxIT/go2rtc/pkg/ngrok"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
var cfg struct {
|
||||
Mod struct {
|
||||
Cmd string `yaml:"command"`
|
||||
} `yaml:"ngrok"`
|
||||
}
|
||||
|
||||
app.LoadConfig(&cfg)
|
||||
|
||||
if cfg.Mod.Cmd == "" {
|
||||
return
|
||||
}
|
||||
|
||||
log = app.GetLogger("ngrok")
|
||||
|
||||
ngr, err := ngrok.NewNgrok(cfg.Mod.Cmd)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("[ngrok] start")
|
||||
}
|
||||
|
||||
ngr.Listen(func(msg any) {
|
||||
if msg := msg.(*ngrok.Message); msg != nil {
|
||||
if strings.HasPrefix(msg.Line, "ERROR:") {
|
||||
log.Warn().Msg("[ngrok] " + msg.Line)
|
||||
} else {
|
||||
log.Debug().Msg("[ngrok] " + msg.Line)
|
||||
}
|
||||
|
||||
// Addr: "//localhost:8555", URL: "tcp://1.tcp.eu.ngrok.io:12345"
|
||||
if strings.HasPrefix(msg.Addr, "//localhost:") && strings.HasPrefix(msg.URL, "tcp://") {
|
||||
// don't know if really necessary use IP
|
||||
address, err := ConvertHostToIP(msg.URL[6:])
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("[ngrok] add candidate")
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().Str("addr", address).Msg("[ngrok] add external candidate for WebRTC")
|
||||
|
||||
webrtc.AddCandidate("tcp", address)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
go func() {
|
||||
if err = ngr.Serve(); err != nil {
|
||||
log.Error().Err(err).Msg("[ngrok] run")
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
|
||||
var log zerolog.Logger
|
||||
|
||||
func ConvertHostToIP(address string) (string, error) {
|
||||
host, port, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
ip, err := net.LookupIP(host)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(ip) == 0 {
|
||||
return "", fmt.Errorf("can't resolve: %s", host)
|
||||
}
|
||||
|
||||
return ip[0].String() + ":" + port, nil
|
||||
}
|
||||
Reference in New Issue
Block a user