How to use the wrtc.RTCSessionDescription function in wrtc

To help you get started, we’ve selected a few wrtc 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 local-group-games / web-udp / packages / client / src / provider / web-rtc / rtc-connection-provider.ts View on Github external
break
      }
      // Route session descriptions to peers.
      case "OFFER":
      case "ANSWER": {
        const {
          src,
          payload: { sdp },
        } = message
        const peer = this.peers[src] || this.addPeer(src)

        let description: RTCSessionDescription

        try {
          description = new RTCSessionDescription(sdp)
        } catch (e) {
          throw new Error("Invalid SDP")
        }

        peer.setRemoteDescription(description)

        if (message.type === "OFFER") {
          const sdp = await peer.answer()

          this.onPeerSDP(sdp, src)
        }

        break
      }
      case "KEEP_ALIVE": {
        this.transport.send({
github local-group-games / web-udp / lib / server.js View on Github external
peer.addIceCandidate(ice);

          break;
        }
        // Route session descriptions to peers.
        case "OFFER":
        case "ANSWER": {
          var _src = message.src,
            sdp = message.payload.sdp;

          var _peer = _this._peers[_src] || _this._addPeer(_src);

          var description = void 0;

          try {
            description = new wrtc.RTCSessionDescription(sdp);
          } catch (e) {
            throw new Error("Invalid SDP");
          }

          _peer.setRemoteDescription(description);

          if (message.type === "OFFER") {
            _peer.answer();
          }

          break;
        }
        default:
          break;
      }
    };
github udevbe / westfield / server / node / example.livestream / compositor-server.js View on Github external
function clientStreamDescription(streamSource, description) {

    const signal = JSON.parse(description);

    if (signal.sdp) {

        streamSource.implementation.peerConnection.setRemoteDescription(new webrtc.RTCSessionDescription(signal.sdp)).then(() => {
            return streamSource.implementation.peerConnection.createAnswer();
        }).then((desc) => {
            return streamSource.implementation.peerConnection.setLocalDescription(desc);
        }).then(() => {
            streamSource.server_stream_description(JSON.stringify({"sdp": streamSource.implementation.peerConnection.localDescription}));
        }).catch((error) => {
            console.error(error);
            streamSource.client.close();
        });

    } else if (signal.candidate) {
        streamSource.implementation.peerConnection.addIceCandidate(new webrtc.RTCIceCandidate(signal.candidate)).catch((error) => {
            console.error("Error: Failure during addIceCandidate()", error);
            streamSource.client.close();
        });
    }
github noia-network / webrtc-direct / server / src / webrtc-direct.ts View on Github external
function setRemoteDescription1(desc: RTCSessionDescriptionInit): void {
            if (channel == null) {
                throw new Error("Channel is null.");
            }

            logger.verbose(`${LOG_PREFIX} ${chalk.magentaBright(`${channel.id} pc1: set remote description`)}`, desc.sdp);
            channel.pc.setRemoteDescription(
                new wrtc.RTCSessionDescription(desc),
                () => {
                    res.status(200).json({
                        success: true
                    });
                    if (channel == null) {
                        throw new Error("Channel is destroyed!");
                    }
                    logger.verbose(`${LOG_PREFIX} ${chalk.cyanBright("channel.pc.localDescription.sdp")}`, channel.pc.localDescription.sdp);
                    logger.verbose(
                        `${LOG_PREFIX} ${chalk.magentaBright("channel.pc.remoteDescription.sdp")}`,
                        channel.pc.remoteDescription.sdp
                    );
                },
                handleError
            );
            channel.status = Statuses.Answered;
github noia-network / webrtc-direct / server / src / webrtc-direct.ts View on Github external
function setLocalDescription1(desc: RTCSessionDescriptionInit): void {
            logger.verbose(`${LOG_PREFIX} ${chalk.cyanBright(`${channel.id} pc1: set local description:`)}`, desc.sdp);
            pc1.setLocalDescription(new wrtc.RTCSessionDescription(desc), setRemoteDescription2.bind(null, desc), handleError);
        }

wrtc

Standards-compliant WebRTC implementation for Node

BSD-2-Clause
Latest version published 3 years ago

Package Health Score

60 / 100
Full package analysis