Compare commits
15 Commits
f33a81d1f4
...
v0.1.2
Author | SHA1 | Date | |
---|---|---|---|
567fb71ca7 | |||
cb33bc3555 | |||
94def554c3 | |||
5d76154a25 | |||
381523a2be | |||
5ec7086843 | |||
504d7bc16c | |||
836c5a3bbf | |||
6ac0efb057 | |||
565de48636 | |||
ea0f73b516 | |||
c0a3cadda4 | |||
634bad14d9 | |||
7fe24673ed | |||
cd209a3c74 |
@@ -1,7 +1,11 @@
|
|||||||
name: Run go tests
|
name: Run go tests
|
||||||
on:
|
on:
|
||||||
- test
|
push:
|
||||||
- pull_request
|
paths:
|
||||||
|
- '**.go'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '**.go'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GOPATH: /go_path
|
GOPATH: /go_path
|
||||||
@@ -31,6 +35,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Cache go
|
- name: Cache go
|
||||||
uses: actions/cache@v3
|
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
|
- name: Go mod download
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
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: 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 }}:${{ 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
|
||||||
|
2
go.mod
2
go.mod
@@ -4,6 +4,7 @@ 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/pelletier/go-toml/v2 v2.1.0
|
||||||
github.com/pion/interceptor v0.1.25
|
github.com/pion/interceptor v0.1.25
|
||||||
github.com/pion/sdp/v3 v3.0.6
|
github.com/pion/sdp/v3 v3.0.6
|
||||||
@@ -15,7 +16,6 @@ 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/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
|
||||||
|
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: 717790cb97...2e96de56e6
@@ -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