Compare commits
No commits in common. "bbd3adc4f77c29f900b23f574a891a1171e8ac4c" and "c6a6f46ff873689078e315a2b5546d40dd828408" have entirely different histories.
bbd3adc4f7
...
c6a6f46ff8
@ -4,7 +4,6 @@ import { createContext, useEffect, useState } from "react";
|
|||||||
import { MediaContainer } from "./media";
|
import { MediaContainer } from "./media";
|
||||||
import { MinistreamApiClient, StreamInfo } from "./api";
|
import { MinistreamApiClient, StreamInfo } from "./api";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Log } from "./log";
|
|
||||||
|
|
||||||
interface AppProps {
|
interface AppProps {
|
||||||
api: MinistreamApiClient
|
api: MinistreamApiClient
|
||||||
@ -34,10 +33,24 @@ export function App({ api }: AppProps) {
|
|||||||
setSelectedStream(item)
|
setSelectedStream(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateStreamList = () => {
|
||||||
|
api.listStreams().then((list) => {
|
||||||
|
setStreamList(list)
|
||||||
|
if (list.length != streamList.length) {
|
||||||
|
setStreamList(list)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!list.every((_, idx) => {
|
||||||
|
return list[idx].streamKey === streamList[idx].streamKey
|
||||||
|
})) {
|
||||||
|
setStreamList(list)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const updateTitle = () => {
|
const updateTitle = () => {
|
||||||
api.siteInfo().then((info) => {
|
api.siteInfo().then((info) => {
|
||||||
if (info.siteName != document.title) {
|
if (info.siteName != document.title) {
|
||||||
setTitle(info.siteName)
|
setTitle(info.siteName)
|
||||||
localStorage.setItem(titleKey, info.siteName)
|
localStorage.setItem(titleKey, info.siteName)
|
||||||
@ -46,32 +59,12 @@ export function App({ api }: AppProps) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
updateStreamList()
|
||||||
|
}, 10000)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateStreamList = () => {
|
|
||||||
api.listStreams().then((list) => {
|
|
||||||
setStreamList((current) => {
|
|
||||||
if (list.length != current.length) {
|
|
||||||
Log.Debug("Updated streamList!")
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
if (!list.every((_, idx) => {
|
|
||||||
return list[idx].streamKey === current[idx].streamKey
|
|
||||||
})) {
|
|
||||||
Log.Debug("Updated streamList..")
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
return current
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
updateStreamList()
|
updateStreamList()
|
||||||
const updateInterval = setInterval(() => {
|
|
||||||
updateStreamList()
|
|
||||||
}, 10000)
|
|
||||||
return () => clearInterval(updateInterval)
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
export namespace Log {
|
|
||||||
var currentLevel: Level = "INFO"
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
|
||||||
currentLevel = "DEBUG"
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Level = "ERROR" | "WARN" | "INFO" | "DEBUG"
|
|
||||||
|
|
||||||
export function setLevel(level: Level) {
|
|
||||||
currentLevel = level
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface LogArgs {
|
|
||||||
[key: string]: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Error(message: string, extras?: LogArgs) {
|
|
||||||
doLog("ERROR", message, extras)
|
|
||||||
}
|
|
||||||
export function Warn(message: string, extras?: LogArgs) {
|
|
||||||
doLog("WARN", message, extras)
|
|
||||||
}
|
|
||||||
export function Info(message: string, extras?: LogArgs) {
|
|
||||||
doLog("INFO", message, extras)
|
|
||||||
}
|
|
||||||
export function Debug(message: string, extras?: LogArgs) {
|
|
||||||
doLog("DEBUG", message, extras)
|
|
||||||
}
|
|
||||||
|
|
||||||
function doLog(level: Level, message: string, extras?: LogArgs) {
|
|
||||||
var logLine = `[${level}] ${message}`
|
|
||||||
|
|
||||||
if (extras) {
|
|
||||||
Object.keys(extras).forEach((key) => {
|
|
||||||
logLine = logLine + ` ${key}=${extras[key]}`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (levelToNumber(level) >= levelToNumber(currentLevel)) {
|
|
||||||
console.log(logLine)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function levelToNumber(level: Level): number {
|
|
||||||
switch (level) {
|
|
||||||
case "DEBUG":
|
|
||||||
return 0
|
|
||||||
case "INFO":
|
|
||||||
return 1
|
|
||||||
case "ERROR":
|
|
||||||
return 2
|
|
||||||
case "WARN":
|
|
||||||
return 3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,6 @@ import { ComponentProps, useRef, useEffect, useState } from "react"
|
|||||||
import { MinistreamApiClient } from "./api"
|
import { MinistreamApiClient } from "./api"
|
||||||
import { resolve } from "path"
|
import { resolve } from "path"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { Log } from "./log"
|
|
||||||
|
|
||||||
type MediaContainerProps = {
|
type MediaContainerProps = {
|
||||||
selectedStream: string | null
|
selectedStream: string | null
|
||||||
@ -17,7 +16,7 @@ export function MediaContainer({ selectedStream, api }: MediaContainerProps) {
|
|||||||
|
|
||||||
// if selected stream changed, recreate pc, and set all to not ready.
|
// if selected stream changed, recreate pc, and set all to not ready.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Log.Debug("Ran useEffect.", { "because_state": "selectedStream" })
|
console.log("effect: selectedStream")
|
||||||
setPC(new RTCPeerConnection({
|
setPC(new RTCPeerConnection({
|
||||||
iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
|
iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
|
||||||
}))
|
}))
|
||||||
@ -28,7 +27,7 @@ export function MediaContainer({ selectedStream, api }: MediaContainerProps) {
|
|||||||
}, [selectedStream])
|
}, [selectedStream])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Log.Debug("Ran useEffect.", { "because_state": "pc" })
|
console.log("effect: pc")
|
||||||
pc.addTransceiver("video")
|
pc.addTransceiver("video")
|
||||||
pc.addTransceiver("audio")
|
pc.addTransceiver("audio")
|
||||||
pc.ontrack = (event) => {
|
pc.ontrack = (event) => {
|
||||||
@ -39,30 +38,30 @@ export function MediaContainer({ selectedStream, api }: MediaContainerProps) {
|
|||||||
|
|
||||||
pc.onicecandidate = (event) => {
|
pc.onicecandidate = (event) => {
|
||||||
if (!event.candidate) {
|
if (!event.candidate) {
|
||||||
Log.Info("ICE gathering complete.")
|
console.log("ICE gathering complete.")
|
||||||
setICEReady(true)
|
setICEReady(true)
|
||||||
} else {
|
} else {
|
||||||
Log.Debug("Adding ICE candidate.", { "candidate": event.candidate.candidate })
|
console.log("Adding ICE candidate: " + event.candidate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pc.oniceconnectionstatechange = () => {
|
pc.oniceconnectionstatechange = () => {
|
||||||
Log.Info("ICE gathering complete.")
|
console.log("ICE state changed to " + pc.iceConnectionState)
|
||||||
}
|
}
|
||||||
|
|
||||||
pc.createOffer().then((offer) => {
|
pc.createOffer().then((offer) => {
|
||||||
pc.setLocalDescription(offer).then(() => { Log.Debug("Local description set.") })
|
pc.setLocalDescription(offer).then(() => { console.log("Local description set.") })
|
||||||
})
|
})
|
||||||
}, [pc])
|
}, [pc])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Log.Debug("Ran useEffect", { "because_state": "iceReady" })
|
console.log("effect: iceReady")
|
||||||
if (!iceReady || !selectedStream) {
|
if (!iceReady || !selectedStream) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const localOfferSdp = pc.localDescription?.sdp
|
const localOfferSdp = pc.localDescription?.sdp
|
||||||
if (!localOfferSdp) {
|
if (!localOfferSdp) {
|
||||||
Log.Error("Unable to get local description.")
|
console.log("Unable to get local description")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const localOffer = new RTCSessionDescription({ type: "offer", sdp: localOfferSdp })
|
const localOffer = new RTCSessionDescription({ type: "offer", sdp: localOfferSdp })
|
||||||
@ -74,7 +73,7 @@ export function MediaContainer({ selectedStream, api }: MediaContainerProps) {
|
|||||||
}, [iceReady])
|
}, [iceReady])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Log.Debug("Ran useEffect", { "because_state": "remoteReady" })
|
console.log("effect: remoteReady")
|
||||||
if (!iceReady || !selectedStream || !remoteReady) {
|
if (!iceReady || !selectedStream || !remoteReady) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user