Jump to content
  • 0

webRTCAdaptor.join() is not called in peer to peer connection


Tahmid Khandokar
 Share

Question

Hello, there!
I'm working with peer to peer connection. Before, I used ws://ovh36.antmedia.io:5080/LiveApp/websocket this URL as a webSocket URL. In that time all worked fine. But now, I've switched the webSocket URL to my local ams server URL. And now the join() method is not calling. Please help me, it's urgent for me.
Here is my code bellow:

<html>
  <head>
    <title>Ant Media Server WebRTC Peer</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta charset="UTF-8" />
    <script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
  </head>
  <body>
    <div class="container" style="padding: 40px 15px; text-align: center">
      <video
        id="localVideo"
        autoplay
        muted
        controls
        playsinline
        width="480"
      ></video>
      <video id="remoteVideo" autoplay controls playsinline width="480"></video>
      <br />
      <br />
      <div class="input-group offset-sm-2 col-sm-8">
        <input
          type="text"
          class="form-control"
          value="stream1"
          id="streamName"
          placeholder="Type stream name"
        />
        <span class="input-group-btn">
          <button class="btn btn-primary" disabled id="join_button">
            Join
          </button>
          <button class="btn btn-primary" disabled id="leave_button">
            Leave
          </button>
        </span>
      </div>
      <div style="padding: 10px">
        <button class="btn btn-outline-primary" id="turn_off_camera">
          Turn off Camera
        </button>
        <button class="btn btn-outline-primary" id="turn_on_camera">
          Turn on Camera
        </button>

        <button class="btn btn-outline-primary" id="mute_mic">
          Mute Local Mic
        </button>
        <button class="btn btn-outline-primary" id="unmute_mic">
          Unmute Local Mic
        </button>
      </div>
    </div>

    <script></script>
  </body>
  <script type="module">
    import { WebRTCAdaptor } from "./js/webrtc_adaptor.js";

    var join_button = document.getElementById("join_button");
    join_button.addEventListener("click", join, false);
    var leave_button = document.getElementById("leave_button");
    leave_button.addEventListener("click", leave, false);
    var turn_on_camera = document.getElementById("turn_on_camera");
    turn_on_camera.addEventListener("click", turnOnLocalCamera, false);
    var turn_off_camera = document.getElementById("turn_off_camera");
    turn_off_camera.addEventListener("click", turnOffLocalCamera, false);
    var mute_mic = document.getElementById("mute_mic");
    mute_mic.addEventListener("click", muteLocalMic, false);
    var unmute_mic = document.getElementById("unmute_mic");
    unmute_mic.addEventListener("click", unmuteLocalMic, false);

    var streamNameBox = document.getElementById("streamName");

    function join() {
      webRTCAdaptor.join(streamNameBox.value);
    }

    function leave() {
      webRTCAdaptor.leave(streamNameBox.value);
    }

    function turnOffLocalCamera() {
      webRTCAdaptor.turnOffLocalCamera(streamNameBox.value);
    }

    function turnOnLocalCamera() {
      webRTCAdaptor.turnOnLocalCamera(streamNameBox.value);
    }

    function muteLocalMic() {
      webRTCAdaptor.muteLocalMic(streamNameBox.value);
    }

    function unmuteLocalMic() {
      webRTCAdaptor.unmuteLocalMic(streamNameBox.value);
    }

    var pc_config = {
      iceServers: [
        {
          urls: "stun:stun1.l.google.com:19302",
        },
      ],
    };

    var sdpConstraints = {
      OfferToReceiveAudio: true,
      OfferToReceiveVideo: true,
    };
    var mediaConstraints = {
      video: true,
      audio: true,
    };

    var appName = location.pathname.substring(
      0,
      location.pathname.lastIndexOf("/") + 1
    );
    var websocketURL = "ws://127.0.0.1:5080/LiveApp/websocket";

    if (location.protocol.startsWith("https")) {
      websocketURL =
        "wss://" + location.hostname + ":5443" + appName + "websocket";
    }

    var webRTCAdaptor = new WebRTCAdaptor({
      websocket_url: websocketURL,
      mediaConstraints: mediaConstraints,
      peerconnection_config: pc_config,
      sdp_constraints: sdpConstraints,
      localVideoId: "localVideo",
      remoteVideoId: "remoteVideo",
      callback: function (info) {
        if (info == "initialized") {
          console.log("initialized");
          join_button.disabled = false;
          leave_button.disabled = true;
        } else if (info == "joined") {
          //joined the stream
          console.log("joined");
          join_button.disabled = true;
          leave_button.disabled = false;
        } else if (info == "leaved") {
          //leaved the stream
          console.log("leaved");
          join_button.disabled = false;
          leave_button.disabled = true;
        }
      },
      callbackError: function (error) {
        //some of the possible errors, NotFoundError, SecurityError,PermissionDeniedError

        console.log("error callback: " + error);
        alert(error);
      },
    });
  </script>
</html>

Note: I run this code with live server. Added that, ws://ovh36.antmedia.io:5080/LiveApp/websocket this URL is now not working. Using this URL I get 'webSocket not connected' error.
 

Edited by Tahmid Khandokar
something I've missed
Link to comment
Share on other sites

  • Answers 1
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

Top Posters For This Question

1 answer to this question

Recommended Posts

 Share


×
×
  • Create New...