Last active
August 17, 2018 23:05
-
-
Save j0sh/7124066 to your computer and use it in GitHub Desktop.
Foresight JSBridge demos. frame.html: Frame capture
activity.html: Frame capture with audio activity detection
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Foresight JSBridge Demo: Frame Capturing</title> | |
| <script type="text/javascript" src="swfobject.js"></script> | |
| <script type="text/javascript"> | |
| var swf = null, video = null, micid = null; | |
| var WIDTH=320,HEIGHT=240 | |
| function getframe() | |
| { | |
| if (null == swf || null == video) return; | |
| var res = swf.foresight_frame(video); | |
| if (null == res) return; | |
| document.getElementById("theimg").src = "data:image/png;base64,"+res; | |
| console.log(swf.foresight_activity({mic:micid})); | |
| } | |
| function miccb(ev) | |
| { | |
| console.log(ev); | |
| } | |
| function foresight_ready() | |
| { | |
| swf = document.getElementById("foresight"); | |
| swf.foresight_loglevel(1); | |
| var camid = swf.foresight_camera({width: WIDTH, height: HEIGHT}); | |
| micid = swf.foresight_mic({status:"miccb", activity:"miccb", loopback:true}); | |
| video = swf.foresight_video({camera: camid, x:0, y:0, width:WIDTH,height:HEIGHT}); | |
| setInterval(getframe, 2500); | |
| } | |
| swfobject.embedSWF( | |
| "foresight.swf", "flashContent", | |
| WIDTH, HEIGHT, | |
| "11.1.0", "", | |
| {}, {}, {id:"foresight"}, null); | |
| </script> | |
| </head> | |
| <body> | |
| <div id="flashdiv" style="float:left"> | |
| <div id="flashContent">Flash is required (sorry!), please enable or install Flash 11.0+</div> | |
| </div> | |
| <div><img id="theimg"></img></div> | |
| </body> | |
| </html> |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Foresight JSBridge Demo: Frame Capturing</title> | |
| <script type="text/javascript" src="swfobject.js"></script> | |
| <script type="text/javascript"> | |
| var swf = null, video = null; | |
| var WIDTH=320,HEIGHT=240 | |
| function getframe() | |
| { | |
| if (null == swf || null == video) return; | |
| var res = swf.foresight_frame(video); | |
| if (null == res) return; | |
| document.getElementById("theimg").src = "data:image/png;base64,"+res; | |
| } | |
| function foresight_ready() | |
| { | |
| swf = document.getElementById("foresight"); | |
| swf.foresight_loglevel(99); | |
| var camid = swf.foresight_camera({width: WIDTH, height: HEIGHT}); | |
| video = swf.foresight_video({camera: camid, x:0, y:0, width:WIDTH,height:HEIGHT}); | |
| setInterval(getframe, 2500); | |
| } | |
| swfobject.embedSWF( | |
| "foresight.swf", "flashContent", | |
| WIDTH, HEIGHT, | |
| "11.1.0", "", | |
| {}, {}, {id:"foresight"}, null); | |
| </script> | |
| </head> | |
| <body> | |
| <div id="flashdiv" style="float:left"> | |
| <div id="flashContent">Flash is required (sorry!), please enable or install Flash 11.0+</div> | |
| </div> | |
| <div><img id="theimg"></img></div> | |
| </body> | |
| </html> |
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Test Console: Foresight Streaming Systems</title> | |
| <script type="text/javascript" src="swfobject.js"></script> | |
| <script type="text/javascript"> | |
| var qs = (function(a) { | |
| if (a == "") return {}; | |
| var b = {}; | |
| for (var i = 0; i < a.length; i++) { | |
| var p = a[i].split("="); | |
| if (p.length != 2) continue; | |
| b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); | |
| } | |
| return b; | |
| })(window.location.search.substr(1).split('&')); | |
| var swf = null; | |
| function onstatus(args) | |
| { | |
| console.log(args); | |
| if ("NetConnection.Connect.Success" == args.code) { | |
| var pub = null == qs.publish ? null : qs.publish; | |
| if (pub !== null) { | |
| var m = swf.foresight_mic({speex:{framesPerPacket: 1, enableVAD:true}, rate:16000}); | |
| var p = swf.foresight_publish({name:pub, callback: "onstatus", mic:m}); | |
| //var c = swf.foresight_camera({stream:p}); | |
| var c = swf.foresight_camera({stream:p, width:640, height:360, fps:30, keyint:30, quality:65, h264:{profile:"baseline", level:"3"}}); | |
| swf.foresight_video({camera:c}); | |
| log("Connected to server. Publishing stream: "+pub); | |
| } else { | |
| var stream = null == qs.stream ? "beakybird" : qs.stream; | |
| log("Connected to server. Playing stream: "+stream); | |
| var q = {stream: swf.foresight_play({name: stream, callback: "onstatus"}), width:352*1.5, height:288*1.5, smoothing:true}; | |
| swf.foresight_buffertime(q.stream, 0.0); | |
| swf.foresight_video(q); | |
| } | |
| } else if ("NetConnection.Connect.Failed" == args.code) { | |
| log("Unable to connect to server"); | |
| } else if ("NetConnection.Connect.Closed" == args.code) { | |
| log("Lost connection to server"); | |
| } else { | |
| log(args.code+" "+args.target); | |
| } | |
| } | |
| function onmetadata(args) { | |
| log("onmetadata!"); | |
| log(args); | |
| } | |
| function talk(args) { | |
| log(args); | |
| swf.foresight_call("message", null, null, "a bottle drifting thru the wine-dark sea"); | |
| log("sent message"); | |
| } | |
| function foresight_ready() | |
| { | |
| var app = null == qs.app ? "flvplayback" : qs.app; | |
| var port = null == qs.port ? "" : ":"+qs.port; | |
| var host = null == qs.host ? "localhost" : qs.host; | |
| var proto = null == qs.proto ? "rtmp" : qs.proto; | |
| swf = document.getElementById("foresight"); | |
| swf.foresight_loglevel(2); | |
| swf.foresight_new({onStatus: "onstatus", join: "join", leave: "leave", pub:"pub", register:"register", msg:"talk", onMetaData: "onmetadata"}); | |
| swf.foresight_connect(proto+"://"+host+port+"/"+app); | |
| document.getElementById("chatbox").style.height = document.getElementById("cont").offsetHeight - document.getElementById("stdin").offsetHeight - 5 + "px"; | |
| if (-1 != navigator.userAgent.search("Chrome")) print("<b>Google Chrome : For stability, disable the Pepper (PPAPI) plugin for Flash in chrome://plugins</b>"); | |
| } | |
| function log(str) { | |
| console.log(str); | |
| print("<div style='text-align:center; font-weight:bold;'>console: "+str+"</div>"); | |
| } | |
| function print(str) { | |
| var cb = document.getElementById("chatbox"); | |
| cb.innerHTML += str; | |
| cb.scrollTop = cb.scrollHeight; | |
| } | |
| function sendtext() { | |
| var d = document.getElementById("textbox"), t = d.value; | |
| console.log("Sending message "+t); | |
| if ("" != t) swf.foresight_call({method: "msg", args:t}); | |
| d.value = ""; | |
| } | |
| function checkenter(e) { | |
| if(e.keyCode == 13) sendtext(); | |
| } | |
| swfobject.embedSWF( | |
| "foresight.swf", "flashContent", | |
| "640px", "480px", | |
| "11.1.0", "", | |
| {}, {}, {id:"foresight", quality:"best"}, null); | |
| </script> | |
| </head> | |
| <body> | |
| <div id="flashContent">Flash is required (sorry!), please enable or install Flash 11.0+</div> | |
| <div id="chatbox"></div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment