Compare commits

...

22 Commits

Author SHA1 Message Date
1c4bb29074 Fix tag for release-tag workflow
All checks were successful
release-nightly / release-image (push) Successful in 2m31s
2023-12-07 00:21:32 +01:00
567fb71ca7 Release as version v0.1.2
All checks were successful
Run go tests / test (push) Successful in 1m41s
release-nightly / release-image (push) Successful in 4m11s
release-tag / release-image (push) Successful in 2m57s
2023-12-07 00:08:33 +01:00
cb33bc3555 Change push secret for workflow
All checks were successful
release-nightly / release-image (push) Successful in 2m14s
2023-12-07 00:00:25 +01:00
94def554c3 Fix tags
Some checks failed
release-nightly / release-image (push) Failing after 2m4s
2023-12-06 23:46:59 +01:00
5d76154a25 Update image used for docker workflow
Some checks failed
release-nightly / release-image (push) Failing after 59s
2023-12-06 23:39:40 +01:00
381523a2be Update test to only run on changed go files
Some checks failed
release-nightly / release-image (push) Failing after 20s
2023-12-06 23:33:34 +01:00
5ec7086843 Update release workflow 2023-12-06 23:32:08 +01:00
504d7bc16c Use https for submodule
Some checks failed
release-nightly / release-image (push) Failing after 49s
Run go tests / test (push) Successful in 2m10s
2023-12-06 23:26:08 +01:00
836c5a3bbf Try removing host key
Some checks failed
Run go tests / test (push) Successful in 1m52s
release-nightly / release-image (push) Failing after 9s
2023-12-06 16:21:32 +01:00
6ac0efb057 Fix branch name in nightly workflow
Some checks failed
Run go tests / test (push) Waiting to run
release-nightly / release-image (push) Failing after 45s
2023-12-06 03:57:25 +01:00
565de48636 Add release-nightly workflow
Some checks are pending
Run go tests / test (push) Waiting to run
2023-12-06 03:54:46 +01:00
ea0f73b516 Update frontend
Some checks failed
Run go tests / test (push) Failing after 10m44s
2023-12-06 03:30:17 +01:00
c0a3cadda4 Update frontend
Some checks failed
Run go tests / test (push) Failing after 11m53s
2023-12-06 00:18:39 +01:00
634bad14d9 Add viewcount to stream list endpoint
Some checks are pending
Run go tests / test (push) Waiting to run
2023-12-06 00:08:14 +01:00
7fe24673ed Fix cache action
All checks were successful
Run go tests / test (push) Successful in 55s
2023-12-05 22:41:57 +01:00
cd209a3c74 Fix typo in workflow
All checks were successful
Run go tests / test (push) Successful in 52s
2023-12-05 22:38:21 +01:00
f33a81d1f4 Merge pull request 'Add go test workflow' (#4) from chore/workflow into master
Reviewed-on: #4
2023-12-05 21:32:49 +00:00
d346944e20 Publish coverage report
All checks were successful
Run go tests / test (pull_request) Successful in 50s
2023-12-05 22:30:12 +01:00
555ce22479 Go mod tidy
All checks were successful
Run go tests / test (pull_request) Successful in 1m21s
2023-12-05 21:58:28 +01:00
644edc33bd Add go test workflow
Some checks failed
Run go tests / test (pull_request) Failing after 1m22s
2023-12-05 21:51:15 +01:00
5cbfc14eab Fix env override for config 2023-12-05 21:32:31 +01:00
9fe5e68551 Update frontend 2023-12-05 03:24:40 +01:00
11 changed files with 225 additions and 13 deletions

View 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

View 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 }}

View 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
View File

@@ -1,3 +1,3 @@
[submodule "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
View File

@@ -4,6 +4,11 @@ go 1.21.3
require (
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
golang.org/x/crypto v0.15.0
)
@@ -11,25 +16,20 @@ require (
require (
github.com/cpuguy83/go-md2man/v2 v2.0.3 // 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/dtls/v2 v2.2.8 // 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/mdns v0.0.9 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.12 // indirect
github.com/pion/rtp v1.8.3 // 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/stun/v2 v2.0.0 // indirect
github.com/pion/transport/v2 v2.2.4 // indirect
github.com/pion/transport/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/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect

3
go.sum
View File

@@ -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/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
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/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/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
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/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
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/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=

View File

@@ -12,7 +12,7 @@ import (
"github.com/urfave/cli/v2"
)
const Version = "v0.1.1"
const Version = "v0.1.2"
type ctxKey string

View File

@@ -101,5 +101,7 @@ func ConfigFromDefault() (*Config, error) {
config = DefaultConfig()
}
config.OverrideFromEnv()
return config, nil
}

View File

@@ -136,9 +136,18 @@ func (s *Server) DeleteHandler(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.Encode(&streams)
enc.Encode(&infos)
}
func (s *Server) WhipHandler(w http.ResponseWriter, r *http.Request) {

View File

@@ -10,6 +10,7 @@ import (
"sync"
"time"
"github.com/google/uuid"
"github.com/pion/interceptor"
"github.com/pion/interceptor/pkg/nack"
"github.com/pion/interceptor/pkg/stats"
@@ -42,7 +43,7 @@ type Stream struct {
peerConnectionStatsMu sync.Mutex
lastUpdate time.Time
localTracks []*webrtc.TrackLocalStaticRTP
peers []*webrtc.PeerConnection
viewers map[string]*webrtc.PeerConnection
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) {
viewerID := uuid.New().String()
m := &webrtc.MediaEngine{}
if err := m.RegisterDefaultCodecs(); err != nil {
panic(err)
@@ -124,6 +126,10 @@ func (s *Stream) AddListener(sd *webrtc.SessionDescription) (*webrtc.SessionDesc
rtpSender, err := peerConnection.AddTrack(ltrack)
if err != nil {
// TODO, stop peerconn
peerConnection.Close()
s.mu.Lock()
delete(s.viewers, viewerID)
s.mu.Unlock()
return nil, err
}
go func() {
@@ -131,6 +137,9 @@ func (s *Stream) AddListener(sd *webrtc.SessionDescription) (*webrtc.SessionDesc
for {
if _, _, err := rtpSender.Read(rtcpBuf); err != nil {
peerConnection.Close()
s.mu.Lock()
delete(s.viewers, viewerID)
s.mu.Unlock()
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
<-gatherComplete
s.mu.Lock()
s.peers = append(s.peers, peerConnection)
s.viewers[viewerID] = peerConnection
defer s.mu.Unlock()
@@ -189,6 +198,7 @@ func (s *StreamStore) Add(streamKey string, sd *webrtc.SessionDescription) (*web
store: s,
lastUpdate: time.Now(),
peerConnectionStats: make(map[string]*stats.Stats),
viewers: make(map[string]*webrtc.PeerConnection),
}
m := &webrtc.MediaEngine{}
if err := m.RegisterDefaultCodecs(); err != nil {
@@ -391,7 +401,7 @@ func (s *StreamStore) Delete(streamKey string) error {
defer s.mu.Unlock()
delete(s.Streams, streamKey)
for _, peer := range stream.peers {
for _, peer := range stream.viewers {
if err := peer.Close(); err != nil {
slog.Warn("Error closing peer.", "error", err)
}