Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

javascript - Kurento onicecandidate event not invoked for browser

I'm trying to develop an application using kurento Media Server. I'm using NodeJS as application server with socket.io for signaling and kurento-client. On client side I'm using kurento-utils library. SDP offer/answer mechanism between nodejs and client page is working as expected. I'm facing problem with icecandidate events.

As mention in docs we need to pass handler function to onicecandidate event when creating a webRtcPeer which receives icecandidates. here is complete code that I have wrote for client side using kurento-utils lib for creating webRtcPeer.

const socket = io();

const $videoLocal = document.querySelector(".local-video");
const $videoRemote = document.querySelector(".remote-video");

const $inputUsername = document.querySelector("#username");

const $btnCreateRoom = document.querySelector("#create-room");
const $btnJoinRoom = document.querySelector("#join-room");

let room = null,
  message = null,
  webRtcPeer = null;

let username = "";

socket.on("message", function (message) {
  switch (message.eventType) {
    case "icecandidate":
      console.log(message.candidate);
      webRtcPeer.addIceCandidate(message.candidate);
      break;

    default:
      break;
  }
});

$btnCreateRoom.addEventListener("click", async (e) => {
  e.preventDefault();
  username = $inputUsername.value;
  if (username !== "") {
    try {
      const { _webRtcPeer, sdpOffer } = await createWebRtcPeer();
      message = {
        eventType: "create-room",
        user: {
          username,
        },
        sdpOffer,
      };
      socket.emit("message", message, function (error, _room, sdpAnswer) {
        if (error) return console.log("unable to create room", error);
        room = _room;
        webRtcPeer.processAnswer(sdpAnswer);
      });
    } catch (error) {
      console.log(error);
    }
  } else {
    console.log("Username null");
  }
});

const createWebRtcPeer = function () {
  return new Promise((resolve, reject) => {
    const onIceCandidate = function (candidate) {
      console.log(candidate);
    };

    const options = {
      localVideo: $videoLocal,
      remoteVideo: $videoRemote,
      onicecandidate: onIceCandidate,
      mediaConstraints: {
        audio: true,
        video: true,
      },
      configuration: {
        iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
      },
    };

    const _webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(
      options,
      function (error) {
        if (error) return reject(error);
        webRtcPeer = _webRtcPeer;
        // webRtcPeer.peerConnection.onicecandidate = function (event) {
        //   let message = {
        //     eventType: "icecandidate",
        //     candidate: event.candidate,
        //     room,
        //     user: {
        //       username,
        //     },
        //   };
        //   socket.emit("message", message);
        // };
        this.generateOffer((error, sdpOffer) => {
          if (error) return reject(error);
          resolve({ _webRtcPeer, sdpOffer });
        });
      }
    );
  });
};

As you can see I have tried registering a event handler directly RTCPeerConnection object using webRtcPeer.peerConnection.onicecandidate. This part of code below:

// webRtcPeer.peerConnection.onicecandidate = function (event) {
        //   let message = {
        //     eventType: "icecandidate",
        //     candidate: event.candidate,
        //     room,
        //     user: {
        //       username,
        //     },
        //   };
        //   socket.emit("message", message);
        // };

This successfully receives icecandidates but I want it to be received on webRtcPeer object onicecandiate method only which does not get invoked.

question from:https://stackoverflow.com/questions/65643803/kurento-onicecandidate-event-not-invoked-for-browser

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...