Temasys / AdapterJS

AdapterJS Javascript Polyfill and Tools for WebRTC - Skylink WebRTC
http://skylink.io/web
Other
432 stars 100 forks source link

MediaStreamTrack has no prototype #27

Closed ibc closed 9 years ago

ibc commented 9 years ago

In order to check how to properly close/stop a MediaStream I check whether the MediaStreamTrack.prototype.stop exists or not. However the MediaStreamTrack implementation of the plugin has no prototype (it is undefined).

Would it be easy to add it? Otherwise I'll use another approach to check the existence of the stop method.

johache commented 9 years ago

I need to do some checking about that. I will come back to you by tomorrow evening.

johache commented 9 years ago

OK, that was quick: 1 - The Temasys plugin does not really support the "prototype" interface. From my reading, it is, in part due to a ActiveX/NPAPI limitation (not something we can influence) I suppose it would be possible to fake it, but I have doubts on the stability it would have.

2 - In this specific case, the MediaStreamTrack object is actually just a "fake" API that we create in the adapter. It's not un the plugin itself; See the following code from the adapter: MediaStreamTrack = {}; MediaStreamTrack.getSources = function (callback) { AdapterJS.WebRTCPlugin.callWhenPluginReady(function() { AdapterJS.WebRTCPlugin.plugin.GetSources(callback); }); We only added this API to provide access to MediaStreamTrack.getSources. Again, it's probably possible to fake the prototype, but since the MediaStreamTrack is actually different from myLocalStream.getVideoTracks()[0].class, I don't think this is the best idea.

3 - I actually disabled the stop API from the mediastreamtracks because it brought big stability issues. We have an open ticket, but it is not trivial and I don't have an ETA on this one. MediaStream.stop should work.

Hope this helps.

ibc commented 9 years ago

Hi, I understand. However it may be better if MediaStreamTrack is defined in adapter.js as a function (so it has prototype) and then fill it with fake functions (those supported by the plugin when dealing with the like-MediaStreamTrack object):

MediaStreamTrack = function() {};

MediaStreamTrack.prototype.stop = function() {};
etc
johache commented 9 years ago

Successfully tested the following code:

MediaStreamTrack = function() {};
MediaStreamTrack.prototype.stop = function() {};
MediaStreamTrack.getSources = function (callback) {
  AdapterJS.WebRTCPlugin.callWhenPluginReady(function() {
     AdapterJS.WebRTCPlugin.plugin.GetSources(callback);
  });
};

However: 1) You will still not be able to call localStream.getVideoTracks().stop(), 2) Given the way the NPAPI/ActiveX interface works, I don't think I will be to set MediaStreamTrack.prototype.stop = the actual class function in the future...

Therefore I am not sure this makes sense.

ibc commented 9 years ago

2015-01-05 8:51 GMT+01:00 johache notifications@github.com:

Successfully tested the following code:

MediaStreamTrack = function() {};MediaStreamTrack.prototype.stop = function() {};MediaStreamTrack.getSources = function (callback) { AdapterJS.WebRTCPlugin.callWhenPluginReady(function() { AdapterJS.WebRTCPlugin.plugin.GetSources(callback); }); };

However: 1) You will still not be able to call localStream.getVideoTracks().stop(),

Ok, my fault, I didn't ask for an empty stop() method, but just for a prototype object. In my code I check for (typeof MediaStreamTrack.prototype.stop === 'function') in order to call stop() on each track or call it on the MediaStream (deprecated in the spec). So by just adding:

MediaStreamTrack = function() {};

would be enough :)

But if MediaStreamTrack.prototype.stop does exists and is a function, then my check will fail.

2) Given the way the NPAPI/ActiveX interface works, I don't think I will be

to set MediaStreamTrack.prototype.stop = the actual class function in the future...

Therefore I am not sure this makes sense.

Agreed.

— Reply to this email directly or view it on GitHub https://github.com/Temasys/AdapterJS/issues/27#issuecomment-68677242.

Iñaki Baz Castillo ibc@aliax.net

johache commented 9 years ago

But you'd still rather have MediaStreamTrack = function() {}; than MediaStreamTrack = {}; right?

I have no issue with that. @serrynaimo @ncurrier JS gurus, can I have it validated by any one of you?

ibc commented 9 years ago

Sure. If MediaStreamTrack is not a function then it has no prototype.

nasivuela commented 8 years ago

Any updates on this?