muaz-khan / WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
https://www.webrtc-experiment.com/
MIT License
11.76k stars 3.95k forks source link

stop to many getUserMedia request to the user #36

Open FreCap opened 11 years ago

FreCap commented 11 years ago

I have seen that every time you start a call/session, RTCMulti asks user the approval again.

Inside the function getUserMedia(), can't we save the current local stream, and reuse it every time it's asked?

Example:

        var userMediaInited = false;
        var userMediaStream = null;
        function getUserMedia(options) {
        var n = navigator,
            media;
        resourcesNeeded = (options.constraints || {
                audio: true,
                video: video_constraints
            };

        if(userMediaInited && userMediaStream
                           && userMediaInited.audio >= resourcesNeeded.audio
                           && userMediaInited.video >= resourcesNeeded.video)
            streaming(userMediaStream)
        else{
                 n.getMedia = n.webkitGetUserMedia || n.mozGetUserMedia;
                 n.getMedia(resourcesNeeded, streaming, options.onerror || function (e) {
                       console.error(e);
                 });
        }
        function streaming(stream) {
            video = options.video;
            if (video) {
                video[moz ? 'mozSrcObject' : 'src'] = moz ? stream : window.webkitURL.createObjectURL(stream);
                video.play();
            }
            options.onsuccess(stream);
            userMediaStream = media = stream;
        }

        return media;
    }
muaz-khan commented 11 years ago

I planned to include session re-initiation feature in RTCMultiConnection-v1.3 where streams will be stored in an object for re-usability for not only the entire session; but also for the lifetime of the browser instance.

Sessions can be re-initiated many times in the meanwhile. This feature will be included in the final release of v-1.3.

Renegotiation feature prompts getUserMedia on each invocation; so re-usability is important there too.

Possible kinds of streams that can be requested:

  1. audio + video stream
  2. audio-only stream
  3. video-only stream
  4. screen capturing stream

audio+screen or video+screen is not permitted in a single getUserMedia request.