10 examples of 'navigator getusermedia' in JavaScript

Every line of 'navigator getusermedia' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
143function getUserMedia() {
144 try {
145 navigator.webkitGetUserMedia("video,audio", gotStream, gotStreamFailed);
146 }
147 catch (e) {
148 console.log(e);
149 }
150}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

109function getUserMedia() {
110 try {
111 navigator.webkitGetUserMedia({video:true, audio:true}, gotStream, gotStreamFailed);
112 trace("Requested access to local media");
113 } catch (e) {
114 trace_exception(e, "getUserMedia error");
115 }
116}
16function getUserMedia(constraints, onSuccessCallback, onFailCallback){
17 console.log("Getting user media.");
18 navigator.webkitGetUserMedia(constraints,
19 onSuccessCallbackWraper, onFailCallback);
20
21 function onSuccessCallbackWraper(stream) {
22 console.log("GetUserMedia success.");
23 localStreams[stream.id] = stream;
24 onSuccessCallback(stream);
25 }
26}
42function getUserMedia(dictionary, callback, error) {
43 try {
44 navigator.getUserMedia(dictionary, callback, error);
45 } catch (e) {
46 alert('getUserMedia threw exception :' + e);
47 }
48}
81function getMedia(constraints) {
82 if (stream) {
83 video.src = null;
84 stream.stop();
85 }
86 navigator.getUserMedia(constraints, successCallback, errorCallback);
87}
154function captureUserMedia(success_callback) {
155 var session = {
156 audio: true,
157 video: true
158 };
159
160 navigator.getUserMedia(session, success_callback, function(error) {
161 alert('Unable to capture your camera. Please check console logs.');
162 console.error(error);
163 });
164}
83start () {
84 if (!this.supportsUserMedia) {
85 return Promise.reject(new Error('UserMedia not supported'))
86 }
87
88 const acceptsAudio = this.opts.modes.indexOf('video-audio') !== -1 ||
89 this.opts.modes.indexOf('audio-only') !== -1
90 const acceptsVideo = this.opts.modes.indexOf('video-audio') !== -1 ||
91 this.opts.modes.indexOf('video-only') !== -1 ||
92 this.opts.modes.indexOf('picture') !== -1
93
94 // ask user for access to their camera
95 return this.mediaDevices.getUserMedia({
96 audio: acceptsAudio,
97 video: acceptsVideo
98 })
99}
213function requestMedia(){
214 var constraints = { audio: true,
215 video:{
216 width: { min: width, ideal: width, max: width },
217 height: { min: height, ideal: height, max: height },
218 }
219 };
220 navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
221 video_show(stream);//only show locally, not remotely
222
223 socket.emit('config_rtmpDestination',url);
224 socket.emit('start','start');
225 mediaRecorder = new MediaRecorder(stream);
226 mediaRecorder.start(0);
227
228 mediaRecorder.onstop = function(e) {
229 stream.stop();
230
231 }
232 //document.getElementById('button_start').disabled=false; 
233
234 mediaRecorder.ondataavailable = function(e) {
235
236 socket.emit("binarystream",e.data);
237 state="start";
238 //chunks.push(e.data);
239 }
240 }).catch(function(err) {
241 console.log('The following error occured: ' + err);
242 show_output('Local getUserMedia ERROR:'+err);
243 output_message.innerHTML="Local video source size is not soupport or No camera ?"+output_video.videoWidth+"x"+output_video.videoHeight;
244 state="stop";
245 button_start.disabled=true;
246 button_server.disabled=false;
247 });
248}
86function isSupported() {
87 return (navigator.getUserMedia || navigator.webkitGetUserMedia);
88 // Disabled for now: No good support
89 // navigator.mozGetUserMedia || navigator.msGetUserMedia);
90}
1function attachUserMedia(videoElement) {
2 if ("getUserMedia" in navigator) {
3 navigator.getUserMedia(
4 {audio : true, video : true, toString : function(){return "video, audio";}},
5 function(stream) {
6 videoElement.src = stream;
7 },
8 function(e) {
9 console.log(err);
10 }
11 );
12 } else if ("webkitGetUserMedia" in navigator) {
13 navigator.webkitGetUserMedia(
14 {audio : true, video : true, toString : function(){return "video, audio";}},
15 function(stream) {
16 var url = webkitURL.createObjectURL(stream);
17 videoElement.src = url;
18 },
19 function(e) {
20 console.log(err);
21 }
22 );
23 } else {
24 console.log("nothing : user stream");
25 }
26}

Related snippets