2018-04-26 15:33:47 +02:00
|
|
|
/*
|
2020-02-04 11:25:54 +01:00
|
|
|
* (C) Copyright 2017-2020 OpenVidu (https://openvidu.io)
|
2018-04-26 15:33:47 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-05-08 13:01:34 +02:00
|
|
|
import { Stream } from './Stream';
|
2018-05-29 18:28:58 +02:00
|
|
|
import { StreamManager } from './StreamManager';
|
2018-04-26 15:33:47 +02:00
|
|
|
import { SubscriberProperties } from '../OpenViduInternal/Interfaces/Public/SubscriberProperties';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Packs remote media streams. Participants automatically receive them when others publish their streams. Initialized with [[Session.subscribe]] method
|
|
|
|
*/
|
2018-05-29 18:28:58 +02:00
|
|
|
export class Subscriber extends StreamManager {
|
2018-04-26 15:33:47 +02:00
|
|
|
|
2019-01-27 14:42:46 +01:00
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
|
|
|
properties: SubscriberProperties;
|
2018-04-26 15:33:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @hidden
|
|
|
|
*/
|
2018-05-23 15:01:40 +02:00
|
|
|
constructor(stream: Stream, targEl: string | HTMLElement, properties: SubscriberProperties) {
|
|
|
|
super(stream, targEl);
|
|
|
|
this.element = this.targetElement;
|
2018-04-26 15:33:47 +02:00
|
|
|
this.stream = stream;
|
|
|
|
this.properties = properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subscribe or unsubscribe from the audio stream (if available). Calling this method twice in a row passing same value will have no effect
|
|
|
|
* @param value `true` to subscribe to the audio stream, `false` to unsubscribe from it
|
|
|
|
*/
|
|
|
|
subscribeToAudio(value: boolean): Subscriber {
|
2018-05-14 19:06:53 +02:00
|
|
|
this.stream.getMediaStream().getAudioTracks().forEach((track) => {
|
|
|
|
track.enabled = value;
|
|
|
|
});
|
|
|
|
console.info("'Subscriber' has " + (value ? 'subscribed to' : 'unsubscribed from') + ' its audio stream');
|
2018-04-26 15:33:47 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subscribe or unsubscribe from the video stream (if available). Calling this method twice in a row passing same value will have no effect
|
|
|
|
* @param value `true` to subscribe to the video stream, `false` to unsubscribe from it
|
|
|
|
*/
|
|
|
|
subscribeToVideo(value: boolean): Subscriber {
|
2018-05-14 19:06:53 +02:00
|
|
|
this.stream.getMediaStream().getVideoTracks().forEach((track) => {
|
|
|
|
track.enabled = value;
|
|
|
|
});
|
|
|
|
console.info("'Subscriber' has " + (value ? 'subscribed to' : 'unsubscribed from') + ' its video stream');
|
2018-04-26 15:33:47 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|