Giter Site home page Giter Site logo

Choose Camera possible? about webrtc-sdk HOT 8 OPEN

Natrium83 avatar Natrium83 commented on May 30, 2024
Choose Camera possible?

from webrtc-sdk.

Comments (8)

Huseriato avatar Huseriato commented on May 30, 2024 1

Removing and adding a whole connection seems quite complicated. Think about a multi call scenario with many connections to different clients. Is there really no way to use the desired onnegotationneeded event? It's fired on the side where the stream is changed. I'm trying to send an offer/answer to the other side in this case. But the new offer is ignored on the other side. Removing the if-constraint there will result in multiple errors "invalid rtc state errors".

I like to have a "modern" solution. I've control over the webbrowser the user uses. So there is no need to support older browsers. Did you ever tried the modern approach or are there other problems involved, which makes this impossible?

from webrtc-sdk.

stephenlb avatar stephenlb commented on May 30, 2024

Yes. See screenshot below. Animated Gif.

from webrtc-sdk.

stephenlb avatar stephenlb commented on May 30, 2024

animated gif webRTC camera selection (6MB)
webrtc

from webrtc-sdk.

Pacific112 avatar Pacific112 commented on May 30, 2024

If you want to this more programatically and for example by default use rear camera on mobile phone instead of front camera you can:

  1. Enumerate divices and find the one you want to use (example for finding back camera):

      `var videoLabel; 
     var videoDeviceId;
     navigator.mediaDevices.enumerateDevices()
     .then(function (deviceInfos) {
    
         for (var i = 0; i !== deviceInfos.length; ++i) {
             if (deviceInfos[i].kind === 'videoinput') {
                 videoLabel = deviceInfos[i].label.split(' ')[1];
                 if (deviceInfos[i].label.match(/back/g) ||
                     deviceInfos[i].label.match(/environment/g)) {
                     videoDeviceId = deviceInfos[i].deviceId;
                 }
                 else {
                     videoDeviceId = deviceInfos[i].deviceId;
                 }
             }
         }
     });`
    
  2. Create PHONE object like this:

      ` var phone = PHONE({
         number: 1234,
         publish_key: 'pub-c-dbc4d5bc-4bd3-4283-b6c3-25cd5bf331a0',
         subscribe_key: 'sub-c-73238dd8-30df-11e7-bc1c-0619f8945a4f',
         ssl: true,
         media: {audio: true, video: {deviceId: {exact: videoDeviceId}}}
     });`
    

from webrtc-sdk.

stephenlb avatar stephenlb commented on May 30, 2024

This looks amazing!

from webrtc-sdk.

pdxbenjamin avatar pdxbenjamin commented on May 30, 2024

I've been attempting to get a second camera working for awhile now. I could use a bit of guidance.
So far I have the demo of this repo working, I use xirsys as my STUN/TURN service and PubNub for Signalling. All is well.
Within the startcamera() function on line 442 in the webrtc-v2.js I've modified that function and created a Option / Select for Camera 1, Camera 2, etc using the, "navigator.mediaDevices.enumerateDevices()" Found here - https://raw.githubusercontent.com/webrtc/samples/gh-pages/src/content/devices/input-output/js/main.js
This actually works and is allowing me to select from a drop down a USB camera, and then back to the built in camera. This functionality also changes the source "blob". All is well!
However now, what can I do to get the other video stream to update? When I change camera source, the other video freezes and can never recover, short of a full page refresh.

Help?!

@stephenlb @Pacific112

from webrtc-sdk.

Huseriato avatar Huseriato commented on May 30, 2024

Hello,

I'll need assistance in this question too. I've found out, that the client have to send a new sdp offer or answer in the onnegotiationneeded event but all of my attempts failed. When changing the local camera, that the screen on the other side is always freezing, because there is no more stream data.

I've tried this in onnegotiationneeded:

      if(options.direction === ghWebRtcConversationDirection.incoming) {
        console.log('create answer on local stream change');
        if(_descriptionPaket) {
          _peerConnection.setRemoteDescription(
            new RTCSessionDescription(_descriptionPaket),
            function() {
              _peerConnection.createAnswer(
                function(answer) {
                  _peerConnection.setLocalDescription(answer, $.noop, handleError);
                  transmit(options.sessionIdentifier, answer, 2);
                },
                handleError,
                {}
              );
            }
          );
        }
      }
      else if(options.direction === ghWebRtcConversationDirection.outgoing) {
        console.log('create offer on local stream change');
        _peerConnection.createOffer(
          function(offer) {
            transmit(options.sessionIdentifier, offer, 2);
            console.log('sent offer to other client');
          },
          handleError,
          {}
        );
      }

I think there is something missing in the function add_sdp_offer(message). There is a line of code:

if (type in talk)
  return;
talk[type] = true;

So a "reoffer" is always dropped. Commenting out this, results in many "invalid rtc state errors" of the browser. So I really don't know how to change this.

Does anyone have some suggestions?

from webrtc-sdk.

stephenlb avatar stephenlb commented on May 30, 2024

You can best achieve this by ending the existing session and starting a new one. If you want a Seamless Transition, then start the new stream and connect to your caller, upon success, allow the receiving client to close the old connection. You can overlay the original video feed with the new video feed to make this appear seamless.

This simple approach should solve your needs for all WebRTC clients, even older outdated WebRTC Clients will accept this approach.

from webrtc-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.