-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for the internal release (#36)
* update readme and examples * bump webrtc plugin * prevent CLI from ignoring duplicated switches * example html fix * README and examples improvements * temporairly remove RTSP example * update deps
- Loading branch information
Showing
19 changed files
with
476 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#/bin/sh | ||
elixir -e 'Logger.configure(level: :info);Mix.install([{:boombox, github: "membraneframework-labs/boombox"}]);Boombox.run_cli()' $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" style="font-family: arial; color: white; background-color: black; margin: 0;"> | ||
|
||
<body> | ||
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script> | ||
<script> | ||
function play() { | ||
var video = document.getElementById('player'); | ||
var hls = new Hls(); | ||
hls.loadSource(document.querySelector("#source").value); | ||
hls.attachMedia(video); | ||
} | ||
</script> | ||
<h1>Boombox HLS Example</h1> | ||
Source:<br> | ||
<input type="text" id="source" value="output/index.m3u8" style="width:400px">  | ||
<button id="play" onclick="play()">Play</button><br><br> | ||
<video id="player" autoplay muted controls></video> | ||
<script> | ||
const source = document.querySelector("#source"); | ||
source.value = new URLSearchParams(window.location.search).get("src") || "output/index.m3u8"; | ||
play(); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Boombox stream WebRTC from browser example</title> | ||
</head> | ||
|
||
<body | ||
style="background-color: black; color: white; font-family: Arial, Helvetica, sans-serif; min-height: 100vh; margin: 0px; padding: 5px 0px 5px 0px"> | ||
<main> | ||
<h1>Boombox stream WebRTC from browser example</h1> | ||
<div> | ||
Boombox URL: <input type="text" value="ws://localhost:8829" id="url" /> <button id="button">Connect</button> | ||
</div> | ||
<div id="status"></div> | ||
<br> | ||
<video id="preview" autoplay muted></video> | ||
</main> | ||
|
||
<script> | ||
const pcConfig = { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' },] }; | ||
const mediaConstraints = { video: { width: 640, height: 480 }, audio: true }; | ||
const button = document.getElementById("button"); | ||
const connStatus = document.getElementById("status"); | ||
const preview = document.getElementById("preview"); | ||
const url = document.getElementById("url"); | ||
|
||
const connectRTC = async (ws) => { | ||
const localStream = await navigator.mediaDevices.getUserMedia(mediaConstraints); | ||
preview.srcObject = localStream; | ||
const pc = new RTCPeerConnection(pcConfig); | ||
|
||
pc.onicecandidate = event => { | ||
if (event.candidate === null) return; | ||
console.log("Sent ICE candidate:", event.candidate); | ||
ws.send(JSON.stringify({ type: "ice_candidate", data: event.candidate })); | ||
}; | ||
|
||
pc.onconnectionstatechange = () => { | ||
if (pc.connectionState == "connected") { | ||
button.innerHTML = "Disconnect"; | ||
button.onclick = () => { | ||
ws.close(); | ||
localStream.getTracks().forEach(track => track.stop()) | ||
button.onclick = connect; | ||
button.innerHTML = "Connect"; | ||
} | ||
connStatus.innerHTML = "Connected "; | ||
} | ||
} | ||
|
||
for (const track of localStream.getTracks()) { | ||
pc.addTrack(track, localStream); | ||
} | ||
|
||
ws.onmessage = async event => { | ||
const { type, data } = JSON.parse(event.data); | ||
|
||
switch (type) { | ||
case "sdp_answer": | ||
console.log("Received SDP answer:", data); | ||
await pc.setRemoteDescription(data); | ||
break; | ||
case "ice_candidate": | ||
console.log("Recieved ICE candidate:", data); | ||
await pc.addIceCandidate(data); | ||
break; | ||
} | ||
}; | ||
|
||
const offer = await pc.createOffer(); | ||
await pc.setLocalDescription(offer); | ||
console.log("Sent SDP offer:", offer) | ||
ws.send(JSON.stringify({ type: "sdp_offer", data: offer })); | ||
}; | ||
|
||
const connect = () => { | ||
connStatus.innerHTML = "Connecting..." | ||
const ws = new WebSocket(url.value); | ||
ws.onopen = _ => connectRTC(ws); | ||
ws.onclose = event => { | ||
connStatus.innerHTML = "Disconnected" | ||
button.onclick = connect; | ||
button.innerHTML = "Connect"; | ||
console.log("WebSocket connection was terminated:", event); | ||
} | ||
} | ||
|
||
button.onclick = connect; | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Boombox stream WebRTC to browser example</title> | ||
</head> | ||
|
||
<body | ||
style="background-color: black; color: white; font-family: Arial, Helvetica, sans-serif; min-height: 100vh; margin: 0px; padding: 5px 0px 5px 0px"> | ||
<main> | ||
<h1>Boombox stream WebRTC to browser example</h1> | ||
<div> | ||
Boombox URL: <input type="text" value="ws://localhost:8830" id="url" /> <button id="button">Connect</button> | ||
</div> | ||
<br> | ||
<video id="videoPlayer" controls muted autoplay></video> | ||
</main> | ||
<script> | ||
const pcConfig = { 'iceServers': [{ 'urls': 'stun:stun.l.google.com:19302' },] }; | ||
const button = document.getElementById("button"); | ||
const connStatus = document.getElementById("status"); | ||
const url = document.getElementById("url"); | ||
const videoPlayer = document.getElementById("videoPlayer"); | ||
|
||
const connectRTC = async (ws) => { | ||
videoPlayer.srcObject = new MediaStream(); | ||
|
||
const pc = new RTCPeerConnection(pcConfig); | ||
pc.ontrack = event => videoPlayer.srcObject.addTrack(event.track); | ||
videoPlayer.play(); | ||
pc.onicecandidate = event => { | ||
if (event.candidate === null) return; | ||
|
||
console.log("Sent ICE candidate:", event.candidate); | ||
ws.send(JSON.stringify({ type: "ice_candidate", data: event.candidate })); | ||
}; | ||
|
||
ws.onmessage = async event => { | ||
const { type, data } = JSON.parse(event.data); | ||
|
||
switch (type) { | ||
case "sdp_offer": | ||
console.log("Received SDP offer:", data); | ||
await pc.setRemoteDescription(data); | ||
const answer = await pc.createAnswer(); | ||
await pc.setLocalDescription(answer); | ||
ws.send(JSON.stringify({ type: "sdp_answer", data: answer })); | ||
console.log("Sent SDP answer:", answer) | ||
break; | ||
case "ice_candidate": | ||
console.log("Recieved ICE candidate:", data); | ||
await pc.addIceCandidate(data); | ||
} | ||
}; | ||
}; | ||
|
||
const connect = () => { | ||
const ws = new WebSocket(url.value); | ||
ws.onopen = () => connectRTC(ws); | ||
ws.onclose = event => console.log("WebSocket connection was terminated:", event); | ||
} | ||
|
||
button.onclick = connect; | ||
</script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.