sourcey / libsourcey

C++14 evented IO libraries for high performance networking and media based applications
https://sourcey.com/libsourcey
GNU Lesser General Public License v2.1
1.31k stars 344 forks source link

createObjectURL() on localStream no longer works on modern browsers (deprecated) #264

Open DanAndersen opened 5 years ago

DanAndersen commented 5 years ago

I encountered an issue when dealing with the webrtcrecorder JS sample, which uses the following code in symple.player.webrtc.js to set the video src URL:

navigator.getUserMedia(this.userMediaConstraints,
                    function (localStream) { // success

                        // Play the local video stream and create the SDP offer.
                        self.video.src = URL.createObjectURL(localStream);
                        self.pc.addStream(localStream);
                        self.pc.createOffer(
                            function(desc) { // success
                                Symple.log('symple:webrtc: offer', desc);
                                self._onLocalSDP(desc); 
                            },
                            function(err) { // error
                                Symple.log('symple:webrtc: offer failed', err);
                            });

                        // Store the active local stream
                        self.activeStream = localStream;
                    },
                    function(err) { // error
                        self.setError('getUserMedia() failed: ' + err);
                    });

I now get an error on self.video.src = URL.createObjectURL(localStream);:

Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.

Apparently this functionality (of creating a URL from a MediaStream) is now deprecated and has been removed from current versions of Chrome and Firefox as of mid/late 2018. See https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL for details. Apparently the new recommended approach is to set the srcObject property to the localStream directly:

self.video.srcObject = localStream;
CrazyIFriT commented 4 years ago

Uncaught (in promise) TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.

Sigue saliendo