jiti-meet/modules/RTC/LocalStream.js

87 lines
1.8 KiB
JavaScript
Raw Normal View History

var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
2014-12-19 13:59:08 +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;
this.videoType = videoType;
2014-12-19 13:59:08 +00:00
var self = this;
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);
};
2014-12-19 13:59:08 +00:00
LocalStream.prototype.mute = function()
{
var ismuted = false;
var tracks = this.getTracks();
2014-12-19 13:59:08 +00:00
for (var idx = 0; idx < tracks.length; idx++) {
ismuted = !tracks[idx].enabled;
tracks[idx].enabled = ismuted;
2014-12-19 13:59:08 +00:00
}
return ismuted;
};
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 = [];
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;
}
LocalStream.prototype.getId = function () {
return this.stream.getTracks()[0].id;
}
2014-12-19 13:59:08 +00:00
module.exports = LocalStream;