javascript - Temasys howto alter existing code -
i have piece of code in place passes constraints getusermedia.
function captureusermedia(callback) { $('#videosource').css('display', 'none'); var videosource = videoselect.value; var constraints = null; constraints = { video: { optional: [{ sourceid: videosource }] }, audio: false } var htmlelement = document.getelementbyid('rtcvideo'); htmlelement.setattribute('autoplay', true); htmlelement.setattribute('controls', true); var mediaconfig = { video: htmlelement, onsuccess: function(stream) { config.attachstream = stream; callback && callback(); htmlelement.setattribute('muted', true); rotateincircle(htmlelement); }, onerror: function() { alert('unable access webcam'); } }; if (constraints) mediaconfig.constraints = constraints; getusermedia(mediaconfig); streamattached = true; }
i.ve tried numerous things working , difficulty perhaps lies in callback found hard head around. how can alter piece of code it'll work? i've tried precede getusermedia navigator needs 3 parameters 2 succes , error callbacks. can see onerror , onsucces calbacks in mediaconfig var. can please take @ it?
update
i saw getusermedia function defined in attached rtcpeerconnection-v1.5.js file:
function getusermedia(options) { var n = navigator, media; n.getmedia = n.webkitgetusermedia || n.mozgetusermedia; n.getmedia(options.constraints || { audio: true, video: video_constraints }, streaming, options.onerror || function(e) { console.error(e); }); function streaming(stream) { var video = options.video; if (video) { video[moz ? 'mozsrcobject' : 'src'] = moz ? stream : window.url.createobjecturl(stream); video.play(); } options.onsuccess && options.onsuccess(stream); media = stream; } return media; }
i'm assuming have more code around that. (videoselect.value won't work videoselect undefined)
if check the spec, constraints , callbacks 3 separate arguments. should like:
getusermedia(mediaconfig.constraints, mediaconfig.onsuccess, mediaconfig.onerror);
i hope helps.
Comments
Post a Comment