Media object doesn't respond to cookie containing object

后端 未结 1 925
情话喂你
情话喂你 2021-01-24 09:36

Sorry if the question is very stupid I am trying to show the stream from a person to another user using js

I have tried putting it in a cookie but it doesnt work even th

相关标签:
1条回答
  • 2021-01-24 10:04

    A cookie is not a centralized universal camera access repository on the web. Thank goodness.

    A MediaStream is a local resource object representing active camera use, not a shareable URL.

    This object lives solely in your local JS page, and isn't addressable on the web.

    Since it doesn't live on any server, transporting the graphical bits from your camera to a friend's system, requires quite a bit of heavy lifting. This includes establishing an RTCPeerConnection which is the domain of WebRTC:

    navigator.mediaDevices.getUserMedia({ video: true })
      .then(function (stream) {
        const iceServers = [{urls: "stun:stun.l.google.com:19302"}];
        const pc = new RTCPeerConnection({iceServers});
    
        for (const track of stream.getTracks())
          pc.addTrack(track, stream);
    
        /* lots of other WebRTC negotiation code */
    

    You'll also typically need a server of some kind, both to solve discovery, i.e. point of contact, as well as a web socket server to exchange critcal offer/answer session descriptions that are necessary for connection establishment, between the two peers.

    Perhaps the simplest proof of concept is this cut'n'paste demo, which let you and a friend exchange the required WebRTC offer/answer session descriptions manually, letting you establish a connection without any server, to see and talk to each other.

    That has about a 70% chance of working. If you're both behind symmetric NATs (most mobile networks), then it gets harder still (you'll need a TURN server, which costs money).

    0 讨论(0)
提交回复
热议问题