Compare commits
23 Commits
4b171b849f
...
master
Author | SHA1 | Date | |
---|---|---|---|
1c4bb29074 | |||
567fb71ca7 | |||
cb33bc3555 | |||
94def554c3 | |||
5d76154a25 | |||
381523a2be | |||
5ec7086843 | |||
504d7bc16c | |||
836c5a3bbf | |||
6ac0efb057 | |||
565de48636 | |||
ea0f73b516 | |||
c0a3cadda4 | |||
634bad14d9 | |||
7fe24673ed | |||
cd209a3c74 | |||
f33a81d1f4 | |||
d346944e20 | |||
555ce22479 | |||
644edc33bd | |||
5cbfc14eab | |||
9fe5e68551 | |||
912cbfe8dd |
74
.gitea/workflows/go-test.yml
Normal file
74
.gitea/workflows/go-test.yml
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
name: Run go tests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- '**.go'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '**.go'
|
||||||
|
|
||||||
|
env:
|
||||||
|
GOPATH: /go_path
|
||||||
|
GOCACHE: /go_cache
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 5
|
||||||
|
env:
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: https://github.com/actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: 1.21
|
||||||
|
use-latest: true
|
||||||
|
|
||||||
|
- name: Hash go.mod and go.sum
|
||||||
|
uses: https://gitea.com/actions/go-hashfiles@v0.0.1
|
||||||
|
id: hash-go
|
||||||
|
with:
|
||||||
|
patterns: |
|
||||||
|
go.mod
|
||||||
|
go.sum
|
||||||
|
|
||||||
|
- name: Cache go
|
||||||
|
uses: actions/cache@v3
|
||||||
|
id: cache-go
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
/go_path
|
||||||
|
/go_cache
|
||||||
|
key: cache-go-${{ steps.hash-go.outputs.hash }}
|
||||||
|
|
||||||
|
- name: Go mod download
|
||||||
|
run: go mod download
|
||||||
|
|
||||||
|
- name: Go mod verify
|
||||||
|
run: go mod verify
|
||||||
|
|
||||||
|
- name: Go mod tidy
|
||||||
|
run: go mod tidy && git diff --exit-code
|
||||||
|
|
||||||
|
- name: Check gofmt
|
||||||
|
run: gofmt -s -w . && git diff --exit-code
|
||||||
|
|
||||||
|
- name: Check go vet
|
||||||
|
run: go vet ./...
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -v ./...
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test -cover -coverprofile=/tmp/cov.out -v ./...
|
||||||
|
|
||||||
|
- name: Make coverage report
|
||||||
|
run: go tool cover -html=/tmp/cov.out -o /tmp/cov.html
|
||||||
|
|
||||||
|
- name: Publish coverage report
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: coverage-report
|
||||||
|
path: /tmp/cov.html
|
||||||
|
|
56
.gitea/workflows/release-nightly.yml
Normal file
56
.gitea/workflows/release-nightly.yml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
name: release-nightly
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: git.t-juice.club
|
||||||
|
IMAGE_NAME: ${{ gitea.repository }}
|
||||||
|
DOCKER_TAG: nightly
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ghcr.io/catthehacker/ubuntu:act-latest
|
||||||
|
env:
|
||||||
|
DOCKER_ORG: torjus
|
||||||
|
DOCKER_TAG: nightly
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # all history for all branches and tags
|
||||||
|
submodules: true
|
||||||
|
github-server-url: 'https://git.t-juice.club'
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker BuildX
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to git.t-juice.club registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.t-juice.club
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.DOCKER_PUSH }}
|
||||||
|
|
||||||
|
- name: Get Meta
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||||
|
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: |
|
||||||
|
linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ env.REGISTRY }}/${{ gitea.repository }}:${{ env.DOCKER_TAG }}
|
58
.gitea/workflows/release-tag.yml
Normal file
58
.gitea/workflows/release-tag.yml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
name: release-tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: git.t-juice.club
|
||||||
|
IMAGE_NAME: ${{ gitea.repository }}
|
||||||
|
DOCKER_TAG: latest
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ghcr.io/catthehacker/ubuntu:act-latest
|
||||||
|
env:
|
||||||
|
DOCKER_ORG: torjus
|
||||||
|
DOCKER_TAG: latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # all history for all branches and tags
|
||||||
|
submodules: true
|
||||||
|
github-server-url: 'https://git.t-juice.club'
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker BuildX
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to git.t-juice.club registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.t-juice.club
|
||||||
|
username: ${{ gitea.actor }}
|
||||||
|
password: ${{ secrets.DOCKER_PUSH }}
|
||||||
|
|
||||||
|
- name: Get Meta
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||||
|
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
platforms: |
|
||||||
|
linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ env.REGISTRY }}/${{ gitea.repository }}:${{ steps.meta.outputs.REPO_VERSION }}
|
||||||
|
${{ env.REGISTRY }}/${{ gitea.repository }}:${{ env.DOCKER_TAG }}
|
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[submodule "ministream-frontend"]
|
[submodule "ministream-frontend"]
|
||||||
path = ministream-frontend
|
path = ministream-frontend
|
||||||
url = ssh://git@git.t-juice.club:222/torjus/ministream-frontend.git
|
url = https://git.t-juice.club/torjus/ministream-frontend.git
|
||||||
|
10
go.mod
10
go.mod
@@ -4,6 +4,11 @@ go 1.21.3
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/go-chi/chi/v5 v5.0.10
|
github.com/go-chi/chi/v5 v5.0.10
|
||||||
|
github.com/google/uuid v1.4.0
|
||||||
|
github.com/pelletier/go-toml/v2 v2.1.0
|
||||||
|
github.com/pion/interceptor v0.1.25
|
||||||
|
github.com/pion/sdp/v3 v3.0.6
|
||||||
|
github.com/pion/webrtc/v4 v4.0.0-beta.7
|
||||||
github.com/urfave/cli/v2 v2.25.7
|
github.com/urfave/cli/v2 v2.25.7
|
||||||
golang.org/x/crypto v0.15.0
|
golang.org/x/crypto v0.15.0
|
||||||
)
|
)
|
||||||
@@ -11,25 +16,20 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/google/uuid v1.4.0 // indirect
|
|
||||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
|
||||||
github.com/pion/datachannel v1.5.5 // indirect
|
github.com/pion/datachannel v1.5.5 // indirect
|
||||||
github.com/pion/dtls/v2 v2.2.8 // indirect
|
github.com/pion/dtls/v2 v2.2.8 // indirect
|
||||||
github.com/pion/ice/v3 v3.0.2 // indirect
|
github.com/pion/ice/v3 v3.0.2 // indirect
|
||||||
github.com/pion/interceptor v0.1.25 // indirect
|
|
||||||
github.com/pion/logging v0.2.2 // indirect
|
github.com/pion/logging v0.2.2 // indirect
|
||||||
github.com/pion/mdns v0.0.9 // indirect
|
github.com/pion/mdns v0.0.9 // indirect
|
||||||
github.com/pion/randutil v0.1.0 // indirect
|
github.com/pion/randutil v0.1.0 // indirect
|
||||||
github.com/pion/rtcp v1.2.12 // indirect
|
github.com/pion/rtcp v1.2.12 // indirect
|
||||||
github.com/pion/rtp v1.8.3 // indirect
|
github.com/pion/rtp v1.8.3 // indirect
|
||||||
github.com/pion/sctp v1.8.9 // indirect
|
github.com/pion/sctp v1.8.9 // indirect
|
||||||
github.com/pion/sdp/v3 v3.0.6 // indirect
|
|
||||||
github.com/pion/srtp/v3 v3.0.1 // indirect
|
github.com/pion/srtp/v3 v3.0.1 // indirect
|
||||||
github.com/pion/stun/v2 v2.0.0 // indirect
|
github.com/pion/stun/v2 v2.0.0 // indirect
|
||||||
github.com/pion/transport/v2 v2.2.4 // indirect
|
github.com/pion/transport/v2 v2.2.4 // indirect
|
||||||
github.com/pion/transport/v3 v3.0.1 // indirect
|
github.com/pion/transport/v3 v3.0.1 // indirect
|
||||||
github.com/pion/turn/v3 v3.0.1 // indirect
|
github.com/pion/turn/v3 v3.0.1 // indirect
|
||||||
github.com/pion/webrtc/v4 v4.0.0-beta.7 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/stretchr/testify v1.8.4 // indirect
|
github.com/stretchr/testify v1.8.4 // indirect
|
||||||
|
3
go.sum
3
go.sum
@@ -25,8 +25,10 @@ github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
|||||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||||
@@ -196,6 +198,7 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
|
|||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
|
2
main.go
2
main.go
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Version = "v0.1.1"
|
const Version = "v0.1.2"
|
||||||
|
|
||||||
type ctxKey string
|
type ctxKey string
|
||||||
|
|
||||||
|
Submodule ministream-frontend updated: a267f9e0df...2e96de56e6
@@ -101,5 +101,7 @@ func ConfigFromDefault() (*Config, error) {
|
|||||||
config = DefaultConfig()
|
config = DefaultConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.OverrideFromEnv()
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
@@ -136,9 +136,18 @@ func (s *Server) DeleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ListHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ListHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
streams := s.streams.List()
|
type StreamInfo struct {
|
||||||
|
StreamKey string `json:"streamKey"`
|
||||||
|
ViewCount int `json:"viewCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
infos := []StreamInfo{}
|
||||||
|
for key, stream := range s.streams.Streams {
|
||||||
|
infos = append(infos, StreamInfo{StreamKey: key, ViewCount: len(stream.viewers)})
|
||||||
|
}
|
||||||
|
|
||||||
enc := json.NewEncoder(w)
|
enc := json.NewEncoder(w)
|
||||||
enc.Encode(&streams)
|
enc.Encode(&infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) WhipHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) WhipHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/pion/interceptor"
|
"github.com/pion/interceptor"
|
||||||
"github.com/pion/interceptor/pkg/nack"
|
"github.com/pion/interceptor/pkg/nack"
|
||||||
"github.com/pion/interceptor/pkg/stats"
|
"github.com/pion/interceptor/pkg/stats"
|
||||||
@@ -42,7 +43,7 @@ type Stream struct {
|
|||||||
peerConnectionStatsMu sync.Mutex
|
peerConnectionStatsMu sync.Mutex
|
||||||
lastUpdate time.Time
|
lastUpdate time.Time
|
||||||
localTracks []*webrtc.TrackLocalStaticRTP
|
localTracks []*webrtc.TrackLocalStaticRTP
|
||||||
peers []*webrtc.PeerConnection
|
viewers map[string]*webrtc.PeerConnection
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +73,7 @@ func (s *StreamStore) StatsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stream) AddListener(sd *webrtc.SessionDescription) (*webrtc.SessionDescription, error) {
|
func (s *Stream) AddListener(sd *webrtc.SessionDescription) (*webrtc.SessionDescription, error) {
|
||||||
|
viewerID := uuid.New().String()
|
||||||
m := &webrtc.MediaEngine{}
|
m := &webrtc.MediaEngine{}
|
||||||
if err := m.RegisterDefaultCodecs(); err != nil {
|
if err := m.RegisterDefaultCodecs(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -124,6 +126,10 @@ func (s *Stream) AddListener(sd *webrtc.SessionDescription) (*webrtc.SessionDesc
|
|||||||
rtpSender, err := peerConnection.AddTrack(ltrack)
|
rtpSender, err := peerConnection.AddTrack(ltrack)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO, stop peerconn
|
// TODO, stop peerconn
|
||||||
|
peerConnection.Close()
|
||||||
|
s.mu.Lock()
|
||||||
|
delete(s.viewers, viewerID)
|
||||||
|
s.mu.Unlock()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
@@ -131,6 +137,9 @@ func (s *Stream) AddListener(sd *webrtc.SessionDescription) (*webrtc.SessionDesc
|
|||||||
for {
|
for {
|
||||||
if _, _, err := rtpSender.Read(rtcpBuf); err != nil {
|
if _, _, err := rtpSender.Read(rtcpBuf); err != nil {
|
||||||
peerConnection.Close()
|
peerConnection.Close()
|
||||||
|
s.mu.Lock()
|
||||||
|
delete(s.viewers, viewerID)
|
||||||
|
s.mu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,7 +182,7 @@ func (s *Stream) AddListener(sd *webrtc.SessionDescription) (*webrtc.SessionDesc
|
|||||||
// in a production application you should exchange ICE Candidates via OnICECandidate
|
// in a production application you should exchange ICE Candidates via OnICECandidate
|
||||||
<-gatherComplete
|
<-gatherComplete
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
s.peers = append(s.peers, peerConnection)
|
s.viewers[viewerID] = peerConnection
|
||||||
|
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
@@ -189,6 +198,7 @@ func (s *StreamStore) Add(streamKey string, sd *webrtc.SessionDescription) (*web
|
|||||||
store: s,
|
store: s,
|
||||||
lastUpdate: time.Now(),
|
lastUpdate: time.Now(),
|
||||||
peerConnectionStats: make(map[string]*stats.Stats),
|
peerConnectionStats: make(map[string]*stats.Stats),
|
||||||
|
viewers: make(map[string]*webrtc.PeerConnection),
|
||||||
}
|
}
|
||||||
m := &webrtc.MediaEngine{}
|
m := &webrtc.MediaEngine{}
|
||||||
if err := m.RegisterDefaultCodecs(); err != nil {
|
if err := m.RegisterDefaultCodecs(); err != nil {
|
||||||
@@ -391,7 +401,7 @@ func (s *StreamStore) Delete(streamKey string) error {
|
|||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
delete(s.Streams, streamKey)
|
delete(s.Streams, streamKey)
|
||||||
|
|
||||||
for _, peer := range stream.peers {
|
for _, peer := range stream.viewers {
|
||||||
if err := peer.Close(); err != nil {
|
if err := peer.Close(); err != nil {
|
||||||
slog.Warn("Error closing peer.", "error", err)
|
slog.Warn("Error closing peer.", "error", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user