mirror of
https://github.com/eliasstepanik/vdo.ninja.git
synced 2026-01-11 13:48:38 +00:00
271 lines
8.5 KiB
HTML
271 lines
8.5 KiB
HTML
<html>
|
|
<head><title>IFRAME Example</title>
|
|
<style>
|
|
body{
|
|
padding:0;
|
|
margin:0;
|
|
background-color: rgb(253,253,253);
|
|
}
|
|
iframe {
|
|
border:0;
|
|
margin:0;
|
|
padding:0;
|
|
display:block;
|
|
margin:10px;
|
|
width:640px;
|
|
height:320px;
|
|
}
|
|
#viewlink {
|
|
width:400px;
|
|
}
|
|
#container {
|
|
display:block;
|
|
padding:0px;
|
|
}
|
|
input{
|
|
padding:5px;
|
|
margin:5px;
|
|
}
|
|
button{
|
|
padding:5px;
|
|
margin:5px;
|
|
}
|
|
</style>
|
|
<script>
|
|
|
|
function loadIframe(){
|
|
|
|
var iframe = document.createElement("iframe");
|
|
var iframeContainer = document.createElement("div");
|
|
var iframesrc = document.getElementById("viewlink").value;
|
|
iframe.allow="autoplay;camera;microphone";
|
|
iframe.allowtransparency="true"
|
|
|
|
if (iframesrc==""){
|
|
iframesrc="./";
|
|
}
|
|
|
|
if (document.getElementById("clean").checked){
|
|
if (iframesrc.includes("?")){
|
|
iframesrc+='&';
|
|
} else {
|
|
iframesrc+='?';
|
|
}
|
|
iframesrc+="cleanoutput";
|
|
}
|
|
if (document.getElementById("transparent").checked){
|
|
if (iframesrc.includes("?")){
|
|
iframesrc+='&';
|
|
} else {
|
|
iframesrc+='?';
|
|
}
|
|
iframesrc+="transparent";
|
|
}
|
|
|
|
if (document.getElementById("hidemenu").checked){
|
|
if (iframesrc.includes("?")){
|
|
iframesrc+='&';
|
|
} else {
|
|
iframesrc+='?';
|
|
}
|
|
iframesrc+="hidemenu";
|
|
}
|
|
|
|
iframe.src = iframesrc;
|
|
|
|
iframeContainer.appendChild(iframe);
|
|
|
|
document.getElementById("container").appendChild(iframeContainer);
|
|
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Mute Speaker";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"mute":true}, '*');}; // "speaker" also works in the same way.
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Un-Mute Speaker";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"mute":false}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Toggle Speaker";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"mute":"toggle"}, '*');}; // open to a better suggestion here.
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Mute Mic";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"mic":false}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Un-Mute Mic";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"mic":true}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Toggle Mic";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"mic":"toggle"}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Disconnect";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"close":true}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Low Bitrate";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"bitrate":30}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "High Bitrate";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"bitrate":5000}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Default Bitrate";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"bitrate":-1}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Reload";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"reload":true}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "50% Volume";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"volume":0.5}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "100% Volume";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"volume":1.0}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Request Stats";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"getStats":true}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Request Loudness Levels";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"getLoudness":true}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Stop Sending Loudness Levels";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"getLoudness":false}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "Say Hello";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"sendChat":"Hello!"}, '*');};
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "previewWebcam()";
|
|
button.onclick = function(){iframe.contentWindow.postMessage({"function":"previewWebcam"}, '*');}; // publishScreen
|
|
iframeContainer.appendChild(button);
|
|
|
|
var button = document.createElement("button");
|
|
button.innerHTML = "CLOSE IFRAME";
|
|
button.onclick = function(){iframeContainer.parentNode.removeChild(iframeContainer);};
|
|
iframeContainer.appendChild(button);
|
|
|
|
|
|
//////////// LISTEN FOR EVENTS
|
|
|
|
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
|
|
var eventer = window[eventMethod];
|
|
var messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message";
|
|
|
|
|
|
/// If you have a routing system setup, you could have just one global listener for all iframes instead.
|
|
|
|
eventer(messageEvent, function (e) {
|
|
if (e.source != iframe.contentWindow){return} // reject messages send from other iframes
|
|
|
|
if ("stats" in e.data){
|
|
var outputWindow = document.createElement("div");
|
|
console.log(e.data.stats);
|
|
|
|
|
|
var out = "<br />total_inbound_connections:"+e.data.stats.total_inbound_connections;
|
|
out += "<br />total_outbound_connections:"+e.data.stats.total_outbound_connections;
|
|
|
|
for (var streamID in e.data.stats.inbound_stats){
|
|
out += "<br /><br /><b>streamID:</b> "+streamID+"<br />";
|
|
out += printValues(e.data.stats.inbound_stats[streamID]);
|
|
}
|
|
|
|
outputWindow.innerHTML = out;
|
|
iframeContainer.appendChild(outputWindow);
|
|
}
|
|
|
|
if ("gotChat" in e.data){
|
|
var outputWindow = document.createElement("div");
|
|
outputWindow.innerHTML = e.data.gotChat.msg;
|
|
outputWindow.style.border="1px dotted black";
|
|
iframeContainer.appendChild(outputWindow);
|
|
}
|
|
|
|
if ("action" in e.data){
|
|
var outputWindow = document.createElement("div");
|
|
outputWindow.innerHTML = "child-page-action: "+e.data.action+"<br />";
|
|
outputWindow.style.border="1px dotted black";
|
|
iframeContainer.appendChild(outputWindow);
|
|
}
|
|
|
|
if ("loudness" in e.data){
|
|
console.log(e.data);
|
|
if (document.getElementById("loudness")){
|
|
outputWindow = document.getElementById("loudness");
|
|
} else {
|
|
var outputWindow = document.createElement("div");
|
|
outputWindow.style.border="1px dotted black";
|
|
iframeContainer.appendChild(outputWindow);
|
|
outputWindow.id = "loudness";
|
|
}
|
|
outputWindow.innerHTML = "child-page-action: loudness<br />";
|
|
for (var key in e.data.loudness) {
|
|
outputWindow.innerHTML += key + " Loudness: " + e.data.loudness[key] + "\n";
|
|
}
|
|
outputWindow.style.border="1px black";
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
function printValues( obj) {
|
|
var out = "";
|
|
for (var key in obj) {
|
|
if (typeof obj[key] === "object") {
|
|
out +="<br />";
|
|
out += printValues(obj[key]);
|
|
} else {
|
|
out +="<b>"+key+"</b>: "+obj[key]+"<br />";
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
|
|
<input placeholder="Enter an OBS.Ninja View URL here" id="viewlink" />
|
|
<button onclick="loadIframe();">ADD</button>
|
|
<input type="checkbox" id="clean" checked>Clean Output
|
|
<input type="checkbox" id="transparent" checked>Transparent
|
|
<input type="checkbox" id="hidemenu">Hide Menu
|
|
<div id="container">
|
|
|
|
</div>
|
|
</body>
|
|
</html> |