2015-01-28 14:35:22 +00:00
|
|
|
var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
|
2014-12-19 13:59:08 +00:00
|
|
|
|
2015-01-20 15:56:00 +00:00
|
|
|
function LocalStream(stream, type, eventEmitter, videoType)
|
2014-12-19 13:59:08 +00:00
|
|
|
{
|
|
|
|
this.stream = stream;
|
|
|
|
this.eventEmitter = eventEmitter;
|
|
|
|
this.type = type;
|
2015-01-20 15:56:00 +00:00
|
|
|
this.videoType = videoType;
|
2014-12-19 13:59:08 +00:00
|
|
|
var self = this;
|
2015-01-12 13:23:29 +00:00
|
|
|
if(type == "audio")
|
|
|
|
{
|
|
|
|
this.getTracks = function () {
|
|
|
|
return self.stream.getAudioTracks();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.getTracks = function () {
|
|
|
|
return self.stream.getVideoTracks();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-12-19 13:59:08 +00:00
|
|
|
this.stream.onended = function()
|
|
|
|
{
|
|
|
|
self.streamEnded();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalStream.prototype.streamEnded = function () {
|
|
|
|
this.eventEmitter.emit(StreamEventTypes.EVENT_TYPE_LOCAL_ENDED, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalStream.prototype.getOriginalStream = function()
|
|
|
|
{
|
|
|
|
return this.stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
LocalStream.prototype.isAudioStream = function () {
|
|
|
|
return (this.stream.getAudioTracks() && this.stream.getAudioTracks().length > 0);
|
2015-01-12 13:23:29 +00:00
|
|
|
};
|
2014-12-19 13:59:08 +00:00
|
|
|
|
|
|
|
LocalStream.prototype.mute = function()
|
|
|
|
{
|
|
|
|
var ismuted = false;
|
2015-01-12 13:23:29 +00:00
|
|
|
var tracks = this.getTracks();
|
2014-12-19 13:59:08 +00:00
|
|
|
|
|
|
|
for (var idx = 0; idx < tracks.length; idx++) {
|
|
|
|
ismuted = !tracks[idx].enabled;
|
2015-01-12 13:23:29 +00:00
|
|
|
tracks[idx].enabled = ismuted;
|
2014-12-19 13:59:08 +00:00
|
|
|
}
|
|
|
|
return ismuted;
|
2015-01-12 13:23:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LocalStream.prototype.setMute = function(mute)
|
|
|
|
{
|
|
|
|
var tracks = this.getTracks();
|
|
|
|
|
|
|
|
for (var idx = 0; idx < tracks.length; idx++) {
|
|
|
|
tracks[idx].enabled = mute;
|
|
|
|
}
|
|
|
|
};
|
2014-12-19 13:59:08 +00:00
|
|
|
|
|
|
|
LocalStream.prototype.isMuted = function () {
|
|
|
|
var tracks = [];
|
2015-01-12 13:23:29 +00:00
|
|
|
if(this.type == "audio")
|
2014-12-19 13:59:08 +00:00
|
|
|
{
|
|
|
|
tracks = this.stream.getAudioTracks();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tracks = this.stream.getVideoTracks();
|
|
|
|
}
|
|
|
|
for (var idx = 0; idx < tracks.length; idx++) {
|
|
|
|
if(tracks[idx].enabled)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-12 13:23:29 +00:00
|
|
|
LocalStream.prototype.getId = function () {
|
|
|
|
return this.stream.getTracks()[0].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-12-19 13:59:08 +00:00
|
|
|
module.exports = LocalStream;
|