foxdog-studios / meteor-webrtc

WebRTC signalling for Meteor
Apache License 2.0
76 stars 17 forks source link

Cant connect with other user in the room. #9

Closed ggndpsingh-old closed 9 years ago

ggndpsingh-old commented 9 years ago

Hey, I just converted your example code's home.coffee to jQuery and added it to my project. But I cant seem to make the connections work.

I am very new to Meteor and I have been at it for 2 hours but cannot figure out the problem. I can get the local steam on both sides but not the remote stream. Clicking the call button doesn't pass anything to the other user.

Here is my code

Session.set('hasWebRTC', false);

Template.liveCall.onCreated (function() {
  var dataChannel, dataChannelConfig, hasWebRTC, mediaConfig, ref, ref1, roomName, rtcPeerConnectionConfig, servers, videoConfig, webRTCSignaller;
  if (((ref = Meteor.settings) != null ? (ref1 = ref["public"]) != null ? ref1.servers : void 0 : void 0) != null) {
    servers = Meteor.settings["public"].servers;
  } else {
    servers = {
      iceServers: []
    };
  }
  rtcPeerConnectionConfig = {};
  dataChannelConfig = {};
  videoConfig = {
    mandatory: {
      maxWidth: 320,
      maxHeight: 240
    }
  };
  mediaConfig = {
    video: true,
    audio: true
  };
  webRTCSignaller = null;
  dataChannel = null;
  roomName = Router.current().params.roomName;
  Session.set('roomName', roomName);
  hasWebRTC = false;
  if (typeof RTCPeerConnection !== "undefined" && RTCPeerConnection !== null) {
    this._webRTCSignaller = SingleWebRTCSignallerFactory.create(stream, roomName, 'master', servers, rtcPeerConnectionConfig, mediaConfig);
    hasWebRTC = true;
  } else {
    console.error('No RTCPeerConnection available :(');
  }
  Session.set('hasWebRTC', hasWebRTC);
  if (!hasWebRTC) {
    return;
  }
  return this._webRTCSignaller.start();
});

Template.liveCall.onDestroyed (function() {
  return this._webRTCSignaller.stop();
});

Template.liveCall.helpers({
  roomName: function() {
    var roomName;
    roomName = Session.get('roomName');
    if (roomName) {
      return Meteor.absoluteUrl(Router.path('liveCall', {
        roomName: roomName
      }).slice(1));
    }
  },
  localStream: function() {
    if (!Session.get('hasWebRTC')) {
      return;
    }
    return Template.instance()._webRTCSignaller.getLocalStream();
  },
  remoteStream: function() {
    if (!Session.get('hasWebRTC')) {
      return;
    }
    return Template.instance()._webRTCSignaller.getRemoteStream();
  },
  canCall: function() {
    var webRTCSignaller;
    if (!Session.get('hasWebRTC')) {
      return 'disabled';
    }
    webRTCSignaller = Template.instance()._webRTCSignaller;
    if (!(webRTCSignaller.started() && !webRTCSignaller.inCall() && !webRTCSignaller.waitingForResponse() && !webRTCSignaller.waitingToCreateAnswer())) {
      return 'disabled';
    }
  },
  canSend: function() {
    if (!Session.get('hasWebRTC')) {
      return 'disabled';
    }
    if (!dataChannel.isOpen()) {
      return 'disabled';
    }
  },
  callText: function() {
    var webRTCSignaller;
    if (!Session.get('hasWebRTC')) {
      return "Your browser doesn't suuport Web RTC :(";
    }
    webRTCSignaller = Template.instance()._webRTCSignaller;
    if (webRTCSignaller.waitingForUserMedia()) {
      return 'Waiting for you to share your camera';
    }
    if (webRTCSignaller.waitingForResponse()) {
      return 'Waiting for response';
    }
    if (webRTCSignaller.waitingToCreateAnswer()) {
      return 'Someone is calling you';
    }
    return 'Begin call with the other person in the room';
  }
});

Template.liveCall.events({
  'click [name="call"]': function(event, template) {
    event.preventDefault();
    if (template._webRTCSignaller == null) {
      return;
    }
    return template._webRTCSignaller.createOffer();
  }
});

I appreciate any help.

Thanks

Gagan