Temasys / SkylinkJS

SkylinkJS Javascript WebRTC SDK
http://skylink.io/web
Other
275 stars 57 forks source link

SkylinkJS dont work after using it at same room for some time #231

Closed jonasmedeiros closed 8 years ago

jonasmedeiros commented 8 years ago

When I change the room name to test it works, what happen to that room, that is crashing the project, the user cant stream at this room, how can I clean it, or fixed? no error method is called, the client wants to contract you, but it should work fine.

var skylink = new Skylink();
    skylink.setLogLevel(4);
    skylink.on('peerJoined', function(peerId, peerInfo, isSelf) {
      if(isSelf) return; // We already have a video element for our video and don't need to create a new one.
      var vid = document.createElement('video');
      vid.autoplay = true;
      vid.muted = true; // Added to avoid feedback when testing locally
      vid.id = peerId;
      document.body.appendChild(vid);
    });

    skylink.on('incomingStream', function(peerId, stream, isSelf) {
      if(isSelf) return;
      var vid = document.getElementById(peerId);
      attachMediaStream(vid, stream);
    });

    skylink.on('peerLeft', function(peerId) {
      var vid = document.getElementById(peerId);
      document.body.removeChild(vid);
    });

    skylink.on('mediaAccessSuccess', function(stream) {
      var vid = document.getElementById('myvideo');
      attachMediaStream(vid, stream);
    });

    skylink.init({
      apiKey: 'f6084524-d7a4-49b8-aed1-4a8732632ea5', // Get your own key at developer.temasys.com.sg
      defaultRoom: "fouro_142"
    }, function (error, success) {
      if (error) {
        document.getElementById('status').innerHTML = 'Failed retrieval for room information.<br>Error: ' + (error.error.message || error.error);
      } else {
           document.getElementById('status').innerHTML = 'Room information has been loaded. Room is ready for user to join.';
        document.getElementById('start').style.display = 'block';
      }
    });

    skylink.joinRoom({
      audio: true,
      video: true
    }, function (error, success) {
      if (error) {
        document.getElementById('status').innerHTML = 'Failed joining room.<br>' +
    'Error: ' + (error.error.message || error.error);
      } else {
        document.getElementById('status').innerHTML = 'Joined room.';
      }
    });
oooookk7 commented 8 years ago

Hi @gunsline2, you might want to try this:

var skylink = new Skylink();
    skylink.setLogLevel(4);
    skylink.on('peerJoined', function(peerId, peerInfo, isSelf) {
      if(isSelf) return; // We already have a video element for our video and don't need to create a new one.
      var vid = document.createElement('video');
      vid.autoplay = true;
      vid.muted = true; // Added to avoid feedback when testing locally
      vid.id = peerId;
      document.body.appendChild(vid);
    });

    skylink.on('incomingStream', function(peerId, stream, isSelf) {
      if(isSelf) return;
      var vid = document.getElementById(peerId);
      if (vid) {
        attachMediaStream(vid, stream);
      }
    });

    skylink.on('peerLeft', function(peerId) {
      var vid = document.getElementById(peerId);
      if (vid) {
         document.body.removeChild(vid);
      }
    });

    skylink.on('mediaAccessSuccess', function(stream) {
      var vid = document.getElementById('myvideo');
      attachMediaStream(vid, stream);
    });

    skylink.init({
      appKey: 'f6084524-d7a4-49b8-aed1-4a8732632ea5', // Get your own key at developer.temasys.com.sg
      defaultRoom: "fouro_142"
    }, function (error, success) {
      if (error) {
        document.getElementById('status').innerHTML = 'Failed retrieval for room information.<br>Error: ' + (error.error.message || error.error);
      } else {
           document.getElementById('status').innerHTML = 'Room information has been loaded. Room is ready for user to join.';
        document.getElementById('start').style.display = 'block';

         skylink.joinRoom({
           audio: true,
            video: true
         }, function (error, success) {
            if (error) {
              document.getElementById('status').innerHTML = 'Failed joining room.<br>' +
                 'Error: ' + (error.error.message || error.error);
            } else {
               document.getElementById('status').innerHTML = 'Joined room.';
            }
         });
      }
    });
oooookk7 commented 8 years ago

Because the workflow requires init() to be invoked first but due to it being asynchronous, it has a callback which would return if result was successful or failed. The suggestion was to only invoke joinRoom() after init() was successful to ensure that init() process was completed successfully before joining the room.

oooookk7 commented 8 years ago

You may see it being handled asychronously in this codepen here.

jonasmedeiros commented 8 years ago

Hi @letchoo I made a code pain with it working and not check please http://codepen.io/gunsline/pen/BzBXVa (not working because of room )

http://codepen.io/gunsline/pen/RRbXJO ( working because changed the room )

cant be like this, at the middle conversation user cant talk anymore because something happen to the room, please check your server what is wrong with this case.

The code above was sent by you @letchoo that's I got it from that link.

jonasmedeiros commented 8 years ago

I tried your code is not working look http://codepen.io/gunsline/pen/vKBoQM (not working case with room fouro_142)

Working room temp http://codepen.io/gunsline/pen/ezOqbG

Now you can check your server?

oooookk7 commented 8 years ago

Hi @gunsline2,

Did you managed to test "Full Page View" ? I think you might have to verify your account. We could reproduce your codepen issue (fouro_142) and we are investigating on it.

jonasmedeiros commented 8 years ago

Yes I have tested on my project your solution, as you saw at code pen is not working, I think the room have a limit of users, and for some reason is not cleaning the users and is getting full, after sometime it dont work, that might be a guess.

oooookk7 commented 8 years ago

Hi @gunsline2, do you happen to have MCU enabled for your key? Btw we suggest to keep the environment for http://codepen.io/gunsline/pen/vKBoQM the same so our team can debug this issue.

jonasmedeiros commented 8 years ago

hi @letchoo How do I do that?

oooookk7 commented 8 years ago

Hi @gunsline2, to check if your key has enabled MCU, access your key and expand the "View Experimental Features". See if "Skylink Media Relay" is set to "ON". I would suggest setting it to "OFF" and see if it works for your environment.

jonasmedeiros commented 8 years ago

Hi @letchoo Have done that not working check the image.

screen shot 2016-05-27 at 7 42 01 am

oooookk7 commented 8 years ago

Hi @gunsline2, is your key f6084524-d7a4-49b8-aed1-4a8732632ea5?

jonasmedeiros commented 8 years ago

my key 'f6084524-d7a4-49b8-aed1-4a8732632ea5'

jonasmedeiros commented 8 years ago

I have added codepen to my hosts so you can test there

oooookk7 commented 8 years ago

Alright. We are investigating on how we can resolve this issue. Meanwhile, do you mind creating a new key (without "Skylink Media Relay" (MCU) turned "OFF").

oooookk7 commented 8 years ago

Hi @gunsline2, do you have any open tab with that Key? If so, do you mind closing them so we can investigate this issue when using MCU.

jonasmedeiros commented 8 years ago

I will make a new key with mcu turned off thanks for the help, let me know if you got the error, I might correct my code if it is doing something wrong.

jonasmedeiros commented 8 years ago

I will update the project now with a new key, so you can test.

oooookk7 commented 8 years ago

@gunsline2, thank you!

jonasmedeiros commented 8 years ago

Just changed the key of the project, please @letchoo let me know if am doing something wrong at the project, it is an AngularJS project, I connect to the room by ajax, I had a problem that the peerjoined event was sending the same PeerId a lot of times, I resolved that making array of peers and check them, but I think that is the problem.

oooookk7 commented 8 years ago

Hi @gunsline2, could you check if your ajax is giving you multiple responses. If you don't mind, we can take a look at your demo.

jonasmedeiros commented 8 years ago

I will make an example and put it to heroku, might take some time.

jonasmedeiros commented 8 years ago

Hi @letchoo studying a bit the code I checked that all on event on skylink at a javascrit project will duplicate each time it get to the room, that is why is calling 2 3 or more times.

jonasmedeiros commented 8 years ago

Found this on your code SkylinkDemo.off("peerJoined"); commented

jonasmedeiros commented 8 years ago

In my case I put the bellow code and now is not calling lot of times the events

skylink = new Skylink();

      skylink.off('peerJoined');
      skylink.off('incomingStream');
      skylink.off('peerLeft');
      skylink.off('incomingMessage');
      skylink.off('peerUpdated');
      skylink.off('mediaAccessSuccess');
      skylink.off('iceConnectionState');
      skylink.off('channelError');
      skylink.off('mediaAccessError');

      skylink.on('peerJoined', function(peerId, peerInfo, isSelf) {

        if( isSelf ){ return };
oooookk7 commented 8 years ago

Hi @gunsline2, yes it does as Skylink class was mean to be initialised as an object once. I'm assuming that you create the Skylink object on some ajax load? In the future, we will plan to make it to be able to instantiate multiple times in the future releases.

oooookk7 commented 8 years ago

Does the connection work for you now currently?

jonasmedeiros commented 8 years ago

@letchoo Im testing hope that was the problem, until now is working fine.

jonasmedeiros commented 8 years ago

@letchoo You are correct, I use an AngularJS directive so it call an ajax to add the html, and there is a service where skylink is.

oooookk7 commented 8 years ago

@gunsline2 our demo currently made mostly to works with one-time creation of the Skylink object, but however we will look into it and make the relevant fixes for it for the future releases. It is in a plan.

oooookk7 commented 8 years ago

Btw if this issue persists, please re-open this ticket. Since this issue (connection not working) has been resolved for you currently, I'll be closing this ticket. We will eventually look into some of the other issues listed (event handlers being called multiple times) or the connection issue with MCU (Skylink Media Relay) with the backend guys.

oooookk7 commented 8 years ago

Please do reference ticket #232 for the multiple Skylink object instances.

jonasmedeiros commented 8 years ago

@letchoo thanks for the support.

oooookk7 commented 8 years ago

@gunsline2 welcomed