-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
signals: Add support for starting and stopping cefsrc from js
See the sample in the html/ directory for an example usage. This should be useful for those webpages that have non-trivial load times (webgl apps, etc) - allowing the page to signal from javascript to the gst pipeline that the page is ready for display. We can also send an EOS signal to be turned into an event on cefsrc. Flag for enabling this feature is listen-for-js-signals, and then on the javascript side you can send signals (see html sample for detail): window.gstSendMsg({ request: "ready" | "eos", ...})
- Loading branch information
1 parent
9046108
commit 2ffad41
Showing
3 changed files
with
193 additions
and
29 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
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,90 @@ | ||
<html> | ||
<head> | ||
<title>Signals Sample</title> | ||
<script language="JavaScript"> | ||
const tStart = 3; // s | ||
const tBad = 1; // s | ||
const tDur = 5; // s | ||
const dt = 0.1; // s | ||
let time = 0; | ||
let remTime = tStart + tDur; | ||
|
||
function sendMessage(msg) { | ||
// Send "command" to renderer process in CEF, which gets routed to | ||
// the main thread | ||
window.gstSendMsg({ | ||
request: msg, | ||
onSuccess: function(response) { | ||
try { | ||
const json = JSON.parse(response); | ||
showResult(json, false); | ||
if (json && json.success && json.cmd === "ready") { | ||
console.log("sending eos signal in 5s..."); | ||
setTimeout(() => { | ||
console.log("sending eos signal"); | ||
sendMessage("eos"); | ||
}, tDur * 1000); | ||
} | ||
} catch (e) { | ||
console.error("parse error", e); | ||
} | ||
}, | ||
onFailure: function(error_code, error_message) { | ||
try { | ||
const json = JSON.parse(error_message); | ||
showResult(json, true); | ||
} catch (e) { | ||
console.error("parse error", e); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function showResult(resultJson, isError) { | ||
document.getElementById("result").innerHTML += | ||
"<br />" + `${isError ? "error" : "response"} at ${time.toFixed(1)}s: ` + "<br />" + | ||
JSON.stringify(resultJson, null, 4); | ||
} | ||
|
||
console.log("sending 'ready' signal in 3s..."); | ||
setTimeout(() => { | ||
console.log("sending 'ready' signal"); | ||
sendMessage("ready"); | ||
}, tStart * 1000); | ||
|
||
setTimeout(() => { | ||
console.log("sending test 'bad' signal"); | ||
sendMessage("bad"); | ||
}, (tStart + tBad) * 1000); | ||
|
||
setInterval(() => { | ||
document.getElementById("timer").innerHTML = | ||
`countdown: ${remTime.toFixed(1)}s` + "<br />" + | ||
`running: ${time.toFixed(1)}s`; | ||
|
||
time += dt; | ||
remTime -= dt; | ||
}, dt * 1000); | ||
</script> | ||
</head> | ||
<body | ||
style=" | ||
overflow: hidden; | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 20px; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: white; | ||
" | ||
> | ||
<div id="result" style="background-color: aqua; width: 30%; text-align: center;"> | ||
Responses: | ||
</div> | ||
<div id="timer" style="background-color: hotpink; width: 30%; text-align: center;"></div> | ||
</div> | ||
</body> | ||
</html> |