Update frontend
This commit is contained in:
parent
11a6ad7704
commit
7b2370a8fc
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
**/node_modules/
|
||||||
|
**/dist/
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "ministream-frontend"]
|
||||||
|
path = ministream-frontend
|
||||||
|
url = ssh://git@git.t-juice.club:222/torjus/ministream-frontend.git
|
13
Dockerfile
13
Dockerfile
@ -1,9 +1,20 @@
|
|||||||
|
FROM node:latest as frontend-builder
|
||||||
|
WORKDIR /app
|
||||||
|
COPY ministream-frontend/package-lock.json /app/package-lock.json
|
||||||
|
COPY ministream-frontend/package.json /app/package.json
|
||||||
|
COPY ministream-frontend/tsconfig.json /app/tsconfig.json
|
||||||
|
RUN npm install
|
||||||
|
COPY ministream-frontend/src /app/src
|
||||||
|
RUN npm run-script build
|
||||||
|
|
||||||
FROM golang:alpine as builder
|
FROM golang:alpine as builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY go.mod /app/go.mod
|
COPY go.mod /app/go.mod
|
||||||
COPY go.sum /app/go.sum
|
COPY go.sum /app/go.sum
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . /app
|
COPY --from=frontend-builder /app/dist /app/server/static
|
||||||
|
COPY main.go /app
|
||||||
|
COPY server /app/server
|
||||||
RUN go build -o ministream main.go
|
RUN go build -o ministream main.go
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
1
ministream-frontend
Submodule
1
ministream-frontend
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit e26f5553007c43d87dd641149e1368e0360827c9
|
@ -31,6 +31,7 @@ func NewServer(store *UserStore) *Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
r.Use(corsMiddleware)
|
||||||
r.Get("/", srv.StaticHandler)
|
r.Get("/", srv.StaticHandler)
|
||||||
r.Get("/{name}", srv.StaticHandler)
|
r.Get("/{name}", srv.StaticHandler)
|
||||||
r.Post("/whip", http.HandlerFunc(srv.WhipHandler))
|
r.Post("/whip", http.HandlerFunc(srv.WhipHandler))
|
||||||
@ -45,6 +46,14 @@ func NewServer(store *UserStore) *Server {
|
|||||||
return srv
|
return srv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func corsMiddleware(next http.Handler) http.Handler {
|
||||||
|
fn := func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Add("Access-Control-Allow-Origin", "*")
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
return http.HandlerFunc(fn)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) OptionsHandler(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) OptionsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
slog.Info("Got OPTIONS")
|
slog.Info("Got OPTIONS")
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,12 @@
|
|||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
|
||||||
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>title</title>
|
<title>ministream</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
</head>
|
||||||
<script src="script.js"></script>
|
|
||||||
</head>
|
<body>
|
||||||
<body>
|
<h1>Frontend not bundled correctly!</h1>
|
||||||
<h1>HELLO!</h1>
|
</body>
|
||||||
<ol id="streamList">
|
|
||||||
</ol>
|
|
||||||
<video id="video1" width="1920" height="1080" autoplay muted></video>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
@ -1,73 +0,0 @@
|
|||||||
const startStream = function (streamKey) {
|
|
||||||
const pc = new RTCPeerConnection({
|
|
||||||
iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
|
|
||||||
})
|
|
||||||
|
|
||||||
pc.oniceconnectionstatechange = e => console.log(e)
|
|
||||||
pc.onicecandidate = e => {
|
|
||||||
console.log("Adding ice candidate: " + e.candidate);
|
|
||||||
if (!e.candidate) {
|
|
||||||
console.log("Done adding candidates. Creating offer.");
|
|
||||||
fetch("/whip/tjuice", {
|
|
||||||
method: "POST",
|
|
||||||
body: pc.localDescription.sdp
|
|
||||||
}).then(resp => {
|
|
||||||
resp.text().then(text => {
|
|
||||||
var answer = {
|
|
||||||
type: "answer",
|
|
||||||
sdp: text
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
console.log("Setting remote description.");
|
|
||||||
pc.setRemoteDescription(answer)
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Error setting remote description: " + e)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pc.createOffer().then(offer => {
|
|
||||||
console.log("Setting local description.");
|
|
||||||
pc.setLocalDescription(offer)
|
|
||||||
})
|
|
||||||
pc.addTransceiver('video')
|
|
||||||
pc.addTransceiver('audio')
|
|
||||||
|
|
||||||
pc.ontrack = function (event) {
|
|
||||||
console.log(event)
|
|
||||||
const el = document.getElementById('video1')
|
|
||||||
var ms = new MediaStream()
|
|
||||||
event.streams.forEach(s => {
|
|
||||||
const tracks = s.getTracks()
|
|
||||||
tracks.forEach(t => {
|
|
||||||
ms.addTrack(t)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
el.srcObject = ms
|
|
||||||
el.autoplay = true
|
|
||||||
el.controls = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
displayStreams = function () {
|
|
||||||
fetch("/whip").then(resp => {
|
|
||||||
resp.json().then(streamList => {
|
|
||||||
for (const element of streamList) {
|
|
||||||
const ol = document.getElementById("streamList")
|
|
||||||
var entry = document.createElement("li")
|
|
||||||
var a = document.createElement("a")
|
|
||||||
a.onclick = _ => startStream(element)
|
|
||||||
a.append(document.createTextNode(element))
|
|
||||||
entry.appendChild(a)
|
|
||||||
ol.appendChild(entry)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
window.onload = function (ev) {
|
|
||||||
console.log(ev)
|
|
||||||
displayStreams()
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
body {
|
|
||||||
color: #ff5722;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user