How to use the react-native-webrtc.RTCSessionDescription function in react-native-webrtc

To help you get started, we’ve selected a few react-native-webrtc examples, based on popular ways it is used in public projects.

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

github atyenoria / react-native-webrtc-janus-gateway / src / janus.mobile.js View on Github external
// TODO
              }
              // Until we implement the proxying of open requests within the Janus core, we open a channel ourselves whatever the case
              config.dataChannel = config.pc.createDataChannel("JanusDataChannel", {ordered:false});  // FIXME Add options (ordered, maxRetransmits, etc.)
              config.dataChannel.onmessage = onDataChannelMessage;
              config.dataChannel.onopen = onDataChannelStateChange;
              config.dataChannel.onclose = onDataChannelStateChange;
              config.dataChannel.onerror = onDataChannelError;
          }
          // Create offer/answer now
          if(jsep === null || jsep === undefined) {
              console.log("createOffer")
              createOffer(handleId, media, callbacks);
          } else {
              config.pc.setRemoteDescription(
                      new RTCSessionDescription(jsep),
                      function() {
                          Janus.log("Remote description accepted!");
                          createAnswer(handleId, media, callbacks);
                      }, callbacks.error);
          }
      }
github WorldViews / JanusMobile / app / lib / janus.js View on Github external
callbacks.error("Invalid handle");
            return;
        }
        var config = pluginHandle.webrtcStuff;
        if (jsep !== undefined && jsep !== null) {
            if (config.pc === null) {
                Janus.warn("Wait, no PeerConnection?? if this is an answer, use createAnswer and not handleRemoteJsep");
                callbacks.error("No PeerConnection: if this is an answer, use createAnswer and not handleRemoteJsep");
                return;
            }
            if (adapter.browserDetails.browser === "edge") {
                // This is Edge, add an a=end-of-candidates at the end
                jsep.sdp += "a=end-of-candidates\r\n";
            }
            config.pc.setRemoteDescription(
                new RTCSessionDescription(jsep),
                function () {
                    Janus.log("Remote description accepted!");
                    callbacks.success();
                }, callbacks.error);
        } else {
            callbacks.error("Invalid JSEP");
        }
    }
github WorldViews / JanusMobile / app / lib / janus.js View on Github external
config.dataChannel = config.pc.createDataChannel("JanusDataChannel", { ordered: false });	// FIXME Add options (ordered, maxRetransmits, etc.)
            config.dataChannel.onmessage = onDataChannelMessage;
            config.dataChannel.onopen = onDataChannelStateChange;
            config.dataChannel.onclose = onDataChannelStateChange;
            config.dataChannel.onerror = onDataChannelError;
        }
        // Create offer/answer now
        if (jsep === null || jsep === undefined) {
            createOffer(handleId, media, callbacks);
        } else {
            if (adapter.browserDetails.browser === "edge") {
                // This is Edge, add an a=end-of-candidates at the end
                jsep.sdp += "a=end-of-candidates\r\n";
            }
            config.pc.setRemoteDescription(
                new RTCSessionDescription(jsep),
                function () {
                    Janus.log("Remote description accepted!");
                    createAnswer(handleId, media, callbacks);
                }, callbacks.error);
        }
    }
github DimitrisTzimikas / RCTWebRTCDemo2 / src / App.js View on Github external
let fromId = data.from;
  
  if (data.sdp) {
    log('Exchange', data);
  }
  
  let peer;
  if (fromId in pcPeers) {
    peer = pcPeers[fromId];
  } else {
    peer = createPC(fromId, false);
  }
  
  if (data.sdp) {
    //console.log('exchange sdp', data);
    let sdp = new RTCSessionDescription(data.sdp);
    
    let callback = () => peer.remoteDescription.type === 'offer' ? peer.createAnswer(callback2, logError) : null;
    let callback2 = desc => peer.setLocalDescription(desc, callback3, logError);
    let callback3 = () => socket.emit('exchange', { to: fromId, sdp: peer.localDescription });
    
    peer.setRemoteDescription(sdp, callback, logError);
  } else {
    peer.addIceCandidate(new RTCIceCandidate(data.candidate));
  }
};
github 0mkara / RNAWebRTCApp / src / webrtcMiddleware.js View on Github external
function exchange(store, data) {
        if(socketId === null) {
            socketId = data.from;
        }
        if (data.sdp) {
            console.log('exchange sdp', data);
            peerconn.setRemoteDescription(new RTCSessionDescription(data.sdp))
                .then(() => {
                    if (peerconn.remoteDescription.type === "offer") {
                        peerconn.createAnswer(offerOpts)
                            .then(desc => {
                                peerconn.setLocalDescription(desc)
                                    .then(() => {
                                        store.dispatch({ type: EXCHANGE, payload: {'to': data.from, 'sdp': peerconn.localDescription } });
                                    })
                                    .catch(err => console.error("exchange sdp error : ", err))
                            })
                    }
                })
        } else {
            console.log('exchange candidate');
            peerconn.addIceCandidate(new RTCIceCandidate(data.candidate));
        }
github sieuhuflit / react-native-live-stream-webrtc-example / src / PeerConnectionUtils.js View on Github external
const pcPeers = PeerConnectionUtils.getPeers();
  const fromId = data.from;
  let pc;
  if (
    fromId === Utils.getStreamerSocketId() ||
    Utils.getStreamerSocketId() === null
  ) {
    if (fromId in pcPeers) {
      pc = pcPeers[fromId];
    } else {
      pc = createPC(fromId, false);
    }
    if (data.sdp) {
      console.log('exchange sdp', data);
      pc.setRemoteDescription(
        new RTCSessionDescription(data.sdp),
        () => {
          if (pc.remoteDescription.type == 'offer')
            pc.createAnswer(
              desc => {
                console.log('createAnswer', desc);
                pc.setLocalDescription(
                  desc,
                  () => {
                    console.log('setLocalDescription', pc.localDescription);
                    SocketUtils.emitExchangeServerSdp(
                      fromId,
                      pc.localDescription
                    );
                  },
                  error => console.log('error : ' + error)
                );
github atyenoria / react-native-webrtc-janus-gateway / src / janus.mobile.js View on Github external
var pluginHandle = pluginHandles[handleId];
          if(pluginHandle === null || pluginHandle === undefined ||
                  pluginHandle.webrtcStuff === null || pluginHandle.webrtcStuff === undefined) {
              Janus.warn("Invalid handle");
              callbacks.error("Invalid handle");
              return;
          }
          var config = pluginHandle.webrtcStuff;
          if(jsep !== undefined && jsep !== null) {
              if(config.pc === null) {
                  Janus.warn("Wait, no PeerConnection?? if this is an answer, use createAnswer and not handleRemoteJsep");
                  callbacks.error("No PeerConnection: if this is an answer, use createAnswer and not handleRemoteJsep");
                  return;
              }
              config.pc.setRemoteDescription(
                      new RTCSessionDescription(jsep),
                      function() {
                          Janus.log("Remote description accepted!");
                          callbacks.success();
                      }, callbacks.error);
          } else {
              callbacks.error("Invalid JSEP");
          }
      }
github jitsi / jitsi-meet / react / features / base / lib-jitsi-meet / native / RTCPeerConnection.js View on Github external
ip6 && (candidate[4] = ip6);

            for (let i = 8; i < candidate.length; ++i) {
                if (candidate[i] === 'raddr') {
                    ip4 = candidate[++i];
                    (ip6 = ips.get(ip4)) && (candidate[i] = ip6);
                    break;
                }
            }

            lines[l] = candidate.join(' ');
        }
    }

    return new RTCSessionDescription({
        sdp: lines.join('\r\n'),
        type: sessionDescription.type
    });
}
github colinwitkamp / react-native-webrtc-sample / App.js View on Github external
async on_Answer_Received(data) {
    const { payload } = data
    await this.peer.setRemoteDescription(new WebRTCLib.RTCSessionDescription(payload.description))
    payload.candidates.forEach(c => this.peer.addIceCandidate(new RTCIceCandidate(c)))
    this.setState({
      answer_recevied: true
    })
  }
github colinwitkamp / react-native-webrtc-sample / App.js View on Github external
async handleAnswer() {
    const { payload } = this.state.offer
    await this.setupWebRTC()
    
    const { peer } = this
    
    await peer.setRemoteDescription(new WebRTCLib.RTCSessionDescription(payload.description))

    if (Array.isArray(payload.candidates)) {
      payload.candidates.forEach((c) => peer.addIceCandidate(new RTCIceCandidate(c)))
    }
    const answer = await peer.createAnswer()
    await peer.setLocalDescription(answer)
    this.setState({
      offer_answered: true
    })
  }