2018-04-26 15:33:47 +02:00
"use strict" ;
/ *
2018-05-06 02:20:25 +02:00
* ( C ) Copyright 2017 - 2018 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-06-01 14:39:38 +02:00
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
2018-10-01 11:17:05 +02:00
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( b . hasOwnProperty ( p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
2018-12-14 14:01:16 +01:00
} ;
2018-06-01 14:39:38 +02:00
return function ( d , b ) {
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
2018-04-26 15:33:47 +02:00
exports . _ _esModule = true ;
2018-06-01 14:39:38 +02:00
var Session _1 = require ( "./Session" ) ;
2018-05-08 13:01:34 +02:00
var Stream _1 = require ( "./Stream" ) ;
2018-06-01 14:39:38 +02:00
var StreamManager _1 = require ( "./StreamManager" ) ;
2018-04-26 15:33:47 +02:00
var StreamEvent _1 = require ( "../OpenViduInternal/Events/StreamEvent" ) ;
2018-07-11 11:47:53 +02:00
var StreamPropertyChangedEvent _1 = require ( "../OpenViduInternal/Events/StreamPropertyChangedEvent" ) ;
2018-04-26 15:33:47 +02:00
var VideoElementEvent _1 = require ( "../OpenViduInternal/Events/VideoElementEvent" ) ;
var OpenViduError _1 = require ( "../OpenViduInternal/Enums/OpenViduError" ) ;
2018-07-11 11:47:53 +02:00
var platform = require ( "platform" ) ;
2018-12-14 14:01:16 +01:00
platform [ 'isIonicIos' ] = ( platform . product === 'iPhone' || platform . product === 'iPad' ) && platform . ua . indexOf ( 'Safari' ) === - 1 ;
2018-04-26 15:33:47 +02:00
/ * *
* Packs local media streams . Participants can publish it to a session . Initialized with [ [ OpenVidu . initPublisher ] ] method
* /
2018-06-01 14:39:38 +02:00
var Publisher = /** @class */ ( function ( _super ) {
_ _extends ( Publisher , _super ) ;
2018-04-26 15:33:47 +02:00
/ * *
* @ hidden
* /
2018-06-01 14:39:38 +02:00
function Publisher ( targEl , properties , openvidu ) {
var _this = _super . call ( this , new Stream _1 . Stream ( ( ! ! openvidu . session ) ? openvidu . session : new Session _1 . Session ( openvidu ) , { publisherProperties : properties , mediaConstraints : { } } ) , targEl ) || this ;
2018-04-26 15:33:47 +02:00
/ * *
* Whether the Publisher has been granted access to the requested input devices or not
* /
2018-06-01 14:39:38 +02:00
_this . accessAllowed = false ;
/ * *
* Whether you have called [ [ Publisher . subscribeToRemote ] ] with value ` true ` or ` false ` ( * false * by default )
* /
_this . isSubscribedToRemote = false ;
_this . accessDenied = false ;
_this . properties = properties ;
2018-07-11 11:47:53 +02:00
_this . openvidu = openvidu ;
_this . stream . ee . on ( 'local-stream-destroyed' , function ( reason ) {
_this . stream . isLocalStreamPublished = false ;
2018-04-26 15:33:47 +02:00
var streamEvent = new StreamEvent _1 . StreamEvent ( true , _this , 'streamDestroyed' , _this . stream , reason ) ;
2018-07-11 11:47:53 +02:00
_this . emitEvent ( 'streamDestroyed' , [ streamEvent ] ) ;
streamEvent . callDefaultBehavior ( ) ;
2018-04-26 15:33:47 +02:00
} ) ;
2018-06-01 14:39:38 +02:00
return _this ;
2018-04-26 15:33:47 +02:00
}
/ * *
* Publish or unpublish the audio stream ( if available ) . Calling this method twice in a row passing same value will have no effect
2018-07-11 11:47:53 +02:00
*
* # # # # Events dispatched
*
2018-12-14 14:01:16 +01:00
* > _Only if ` Session.publish(Publisher) ` has been called for this Publisher _
*
2018-07-11 11:47:53 +02:00
* The [ [ Session ] ] object of the local participant will dispatch a ` streamPropertyChanged ` event with ` changedProperty ` set to ` "audioActive" ` and ` reason ` set to ` "publishAudio" `
* The [ [ Publisher ] ] object of the local participant will also dispatch the exact same event
*
* The [ [ Session ] ] object of every other participant connected to the session will dispatch a ` streamPropertyChanged ` event with ` changedProperty ` set to ` "audioActive" ` and ` reason ` set to ` "publishAudio" `
* The respective [ [ Subscriber ] ] object of every other participant receiving this Publisher ' s stream will also dispatch the exact same event
*
* See [ [ StreamPropertyChangedEvent ] ] to learn more .
*
2018-04-26 15:33:47 +02:00
* @ param value ` true ` to publish the audio stream , ` false ` to unpublish it
* /
Publisher . prototype . publishAudio = function ( value ) {
2018-07-11 11:47:53 +02:00
var _this = this ;
if ( this . stream . audioActive !== value ) {
this . stream . getMediaStream ( ) . getAudioTracks ( ) . forEach ( function ( track ) {
track . enabled = value ;
} ) ;
2018-12-14 14:01:16 +01:00
if ( ! ! this . session && ! ! this . stream . streamId ) {
this . session . openvidu . sendRequest ( 'streamPropertyChanged' , {
streamId : this . stream . streamId ,
property : 'audioActive' ,
newValue : value ,
reason : 'publishAudio'
} , function ( error , response ) {
if ( error ) {
console . error ( "Error sending 'streamPropertyChanged' event" , error ) ;
}
else {
_this . session . emitEvent ( 'streamPropertyChanged' , [ new StreamPropertyChangedEvent _1 . StreamPropertyChangedEvent ( _this . session , _this . stream , 'audioActive' , value , ! value , 'publishAudio' ) ] ) ;
_this . emitEvent ( 'streamPropertyChanged' , [ new StreamPropertyChangedEvent _1 . StreamPropertyChangedEvent ( _this , _this . stream , 'audioActive' , value , ! value , 'publishAudio' ) ] ) ;
}
} ) ;
}
2018-07-11 11:47:53 +02:00
this . stream . audioActive = value ;
console . info ( "'Publisher' has " + ( value ? 'published' : 'unpublished' ) + ' its audio stream' ) ;
}
2018-04-26 15:33:47 +02:00
} ;
/ * *
* Publish or unpublish the video stream ( if available ) . Calling this method twice in a row passing same value will have no effect
2018-07-11 11:47:53 +02:00
*
* # # # # Events dispatched
*
2018-12-14 14:01:16 +01:00
* > _Only if ` Session.publish(Publisher) ` has been called for this Publisher _
*
2018-07-11 11:47:53 +02:00
* The [ [ Session ] ] object of the local participant will dispatch a ` streamPropertyChanged ` event with ` changedProperty ` set to ` "videoActive" ` and ` reason ` set to ` "publishVideo" `
* The [ [ Publisher ] ] object of the local participant will also dispatch the exact same event
*
* The [ [ Session ] ] object of every other participant connected to the session will dispatch a ` streamPropertyChanged ` event with ` changedProperty ` set to ` "videoActive" ` and ` reason ` set to ` "publishVideo" `
* The respective [ [ Subscriber ] ] object of every other participant receiving this Publisher ' s stream will also dispatch the exact same event
*
* See [ [ StreamPropertyChangedEvent ] ] to learn more .
*
2018-04-26 15:33:47 +02:00
* @ param value ` true ` to publish the video stream , ` false ` to unpublish it
* /
Publisher . prototype . publishVideo = function ( value ) {
2018-07-11 11:47:53 +02:00
var _this = this ;
if ( this . stream . videoActive !== value ) {
this . stream . getMediaStream ( ) . getVideoTracks ( ) . forEach ( function ( track ) {
track . enabled = value ;
} ) ;
2018-12-14 14:01:16 +01:00
if ( ! ! this . session && ! ! this . stream . streamId ) {
this . session . openvidu . sendRequest ( 'streamPropertyChanged' , {
streamId : this . stream . streamId ,
property : 'videoActive' ,
newValue : value ,
reason : 'publishVideo'
} , function ( error , response ) {
if ( error ) {
console . error ( "Error sending 'streamPropertyChanged' event" , error ) ;
}
else {
_this . session . emitEvent ( 'streamPropertyChanged' , [ new StreamPropertyChangedEvent _1 . StreamPropertyChangedEvent ( _this . session , _this . stream , 'videoActive' , value , ! value , 'publishVideo' ) ] ) ;
_this . emitEvent ( 'streamPropertyChanged' , [ new StreamPropertyChangedEvent _1 . StreamPropertyChangedEvent ( _this , _this . stream , 'videoActive' , value , ! value , 'publishVideo' ) ] ) ;
}
} ) ;
}
2018-07-11 11:47:53 +02:00
this . stream . videoActive = value ;
console . info ( "'Publisher' has " + ( value ? 'published' : 'unpublished' ) + ' its video stream' ) ;
}
2018-04-26 15:33:47 +02:00
} ;
/ * *
2018-07-11 11:47:53 +02:00
* Call this method before [ [ Session . publish ] ] if you prefer to subscribe to your Publisher ' s remote stream instead of using the local stream , as any other user would do .
2018-04-26 15:33:47 +02:00
* /
2018-06-01 14:39:38 +02:00
Publisher . prototype . subscribeToRemote = function ( value ) {
value = ( value !== undefined ) ? value : true ;
this . isSubscribedToRemote = value ;
this . stream . subscribeToMyRemote ( value ) ;
2018-04-26 15:33:47 +02:00
} ;
/ * *
* See [ [ EventDispatcher . on ] ]
* /
Publisher . prototype . on = function ( type , handler ) {
var _this = this ;
2018-06-01 14:39:38 +02:00
_super . prototype . on . call ( this , type , handler ) ;
2018-04-26 15:33:47 +02:00
if ( type === 'streamCreated' ) {
2018-06-01 14:39:38 +02:00
if ( ! ! this . stream && this . stream . isLocalStreamPublished ) {
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'streamCreated' , [ new StreamEvent _1 . StreamEvent ( false , this , 'streamCreated' , this . stream , '' ) ] ) ;
2018-04-26 15:33:47 +02:00
}
else {
2018-06-01 14:39:38 +02:00
this . stream . ee . on ( 'stream-created-by-publisher' , function ( ) {
2018-07-11 11:47:53 +02:00
_this . emitEvent ( 'streamCreated' , [ new StreamEvent _1 . StreamEvent ( false , _this , 'streamCreated' , _this . stream , '' ) ] ) ;
2018-04-26 15:33:47 +02:00
} ) ;
}
}
if ( type === 'remoteVideoPlaying' ) {
2018-06-01 14:39:38 +02:00
if ( this . stream . displayMyRemote ( ) && this . videos [ 0 ] && this . videos [ 0 ] . video &&
this . videos [ 0 ] . video . currentTime > 0 &&
this . videos [ 0 ] . video . paused === false &&
this . videos [ 0 ] . video . ended === false &&
this . videos [ 0 ] . video . readyState === 4 ) {
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'remoteVideoPlaying' , [ new VideoElementEvent _1 . VideoElementEvent ( this . videos [ 0 ] . video , this , 'remoteVideoPlaying' ) ] ) ;
2018-04-26 15:33:47 +02:00
}
}
if ( type === 'accessAllowed' ) {
2018-06-01 14:39:38 +02:00
if ( this . accessAllowed ) {
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'accessAllowed' , [ ] ) ;
2018-04-26 15:33:47 +02:00
}
}
if ( type === 'accessDenied' ) {
2018-06-01 14:39:38 +02:00
if ( this . accessDenied ) {
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'accessDenied' , [ ] ) ;
2018-04-26 15:33:47 +02:00
}
}
return this ;
} ;
/ * *
* See [ [ EventDispatcher . once ] ]
* /
Publisher . prototype . once = function ( type , handler ) {
var _this = this ;
2018-06-01 14:39:38 +02:00
_super . prototype . once . call ( this , type , handler ) ;
2018-04-26 15:33:47 +02:00
if ( type === 'streamCreated' ) {
2018-06-01 14:39:38 +02:00
if ( ! ! this . stream && this . stream . isLocalStreamPublished ) {
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'streamCreated' , [ new StreamEvent _1 . StreamEvent ( false , this , 'streamCreated' , this . stream , '' ) ] ) ;
2018-04-26 15:33:47 +02:00
}
else {
2018-06-01 14:39:38 +02:00
this . stream . ee . once ( 'stream-created-by-publisher' , function ( ) {
2018-07-11 11:47:53 +02:00
_this . emitEvent ( 'streamCreated' , [ new StreamEvent _1 . StreamEvent ( false , _this , 'streamCreated' , _this . stream , '' ) ] ) ;
2018-04-26 15:33:47 +02:00
} ) ;
}
}
if ( type === 'remoteVideoPlaying' ) {
2018-06-01 14:39:38 +02:00
if ( this . stream . displayMyRemote ( ) && this . videos [ 0 ] && this . videos [ 0 ] . video &&
this . videos [ 0 ] . video . currentTime > 0 &&
this . videos [ 0 ] . video . paused === false &&
this . videos [ 0 ] . video . ended === false &&
this . videos [ 0 ] . video . readyState === 4 ) {
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'remoteVideoPlaying' , [ new VideoElementEvent _1 . VideoElementEvent ( this . videos [ 0 ] . video , this , 'remoteVideoPlaying' ) ] ) ;
2018-04-26 15:33:47 +02:00
}
}
if ( type === 'accessAllowed' ) {
2018-06-01 14:39:38 +02:00
if ( this . accessAllowed ) {
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'accessAllowed' , [ ] ) ;
2018-04-26 15:33:47 +02:00
}
}
if ( type === 'accessDenied' ) {
2018-06-01 14:39:38 +02:00
if ( this . accessDenied ) {
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'accessDenied' , [ ] ) ;
2018-04-26 15:33:47 +02:00
}
}
return this ;
} ;
/* Hidden methods */
/ * *
* @ hidden
* /
Publisher . prototype . initialize = function ( ) {
var _this = this ;
return new Promise ( function ( resolve , reject ) {
var errorCallback = function ( openViduError ) {
2018-06-01 14:39:38 +02:00
_this . accessDenied = true ;
_this . accessAllowed = false ;
2018-04-26 15:33:47 +02:00
reject ( openViduError ) ;
} ;
var successCallback = function ( mediaStream ) {
2018-06-01 14:39:38 +02:00
_this . accessAllowed = true ;
_this . accessDenied = false ;
2018-10-01 11:17:05 +02:00
if ( _this . properties . audioSource instanceof MediaStreamTrack ) {
2018-04-26 15:33:47 +02:00
mediaStream . removeTrack ( mediaStream . getAudioTracks ( ) [ 0 ] ) ;
mediaStream . addTrack ( _this . properties . audioSource ) ;
}
2018-10-01 11:17:05 +02:00
if ( _this . properties . videoSource instanceof MediaStreamTrack ) {
2018-04-26 15:33:47 +02:00
mediaStream . removeTrack ( mediaStream . getVideoTracks ( ) [ 0 ] ) ;
mediaStream . addTrack ( _this . properties . videoSource ) ;
}
// Apply PublisherProperties.publishAudio and PublisherProperties.publishVideo
if ( ! ! mediaStream . getAudioTracks ( ) [ 0 ] ) {
2018-07-23 11:37:18 +02:00
var enabled = ( _this . stream . audioActive !== undefined && _this . stream . audioActive !== null ) ? _this . stream . audioActive : ! ! _this . stream . outboundStreamOpts . publisherProperties . publishAudio ;
mediaStream . getAudioTracks ( ) [ 0 ] . enabled = enabled ;
2018-04-26 15:33:47 +02:00
}
if ( ! ! mediaStream . getVideoTracks ( ) [ 0 ] ) {
2018-07-23 11:37:18 +02:00
var enabled = ( _this . stream . videoActive !== undefined && _this . stream . videoActive !== null ) ? _this . stream . videoActive : ! ! _this . stream . outboundStreamOpts . publisherProperties . publishVideo ;
mediaStream . getVideoTracks ( ) [ 0 ] . enabled = enabled ;
2018-04-26 15:33:47 +02:00
}
2018-07-11 11:47:53 +02:00
_this . videoReference = document . createElement ( 'video' ) ;
2018-12-14 14:01:16 +01:00
if ( platform . name === 'Safari' ) {
_this . videoReference . setAttribute ( 'playsinline' , 'true' ) ;
}
2018-07-11 11:47:53 +02:00
_this . videoReference . srcObject = mediaStream ;
2018-04-26 15:33:47 +02:00
_this . stream . setMediaStream ( mediaStream ) ;
2018-06-01 14:39:38 +02:00
if ( ! _this . stream . displayMyRemote ( ) ) {
// When we are subscribed to our remote we don't still set the MediaStream object in the video elements to
// avoid early 'streamPlaying' event
_this . stream . updateMediaStreamInVideos ( ) ;
}
if ( ! ! _this . firstVideoElement ) {
_this . createVideoElement ( _this . firstVideoElement . targetElement , _this . properties . insertMode ) ;
}
delete _this . firstVideoElement ;
2018-07-11 11:47:53 +02:00
if ( _this . stream . isSendVideo ( ) ) {
if ( ! _this . stream . isSendScreen ( ) ) {
2018-12-14 14:01:16 +01:00
if ( platform [ 'isIonicIos' ] || platform . name === 'Safari' ) {
// iOS Ionic or Safari. Limitation: cannot set videoDimensions directly, as the videoReference is not loaded
// if not added to DOM. Must add it to DOM and wait for videoWidth and videoHeight properties to be defined
_this . videoReference . style . display = 'none' ;
document . body . appendChild ( _this . videoReference ) ;
var videoDimensionsSet _1 = function ( ) {
_this . stream . videoDimensions = {
width : _this . videoReference . videoWidth ,
height : _this . videoReference . videoHeight
} ;
_this . stream . isLocalStreamReadyToPublish = true ;
_this . stream . ee . emitEvent ( 'stream-ready-to-publish' , [ ] ) ;
document . body . removeChild ( _this . videoReference ) ;
} ;
var interval _1 ;
_this . videoReference . onloadedmetadata = function ( ) {
if ( _this . videoReference . videoWidth === 0 ) {
interval _1 = setInterval ( function ( ) {
if ( _this . videoReference . videoWidth !== 0 ) {
videoDimensionsSet _1 ( ) ;
clearInterval ( interval _1 ) ;
}
} , 10 ) ;
}
else {
videoDimensionsSet _1 ( ) ;
}
2018-07-11 11:47:53 +02:00
} ;
}
else {
2018-12-14 14:01:16 +01:00
// Rest of platforms
// With no screen share, video dimension can be set directly from MediaStream (getSettings)
// Orientation must be checked for mobile devices (width and height are reversed)
var _a = mediaStream . getVideoTracks ( ) [ 0 ] . getSettings ( ) , width = _a . width , height = _a . height ;
if ( ( platform . os . family === 'iOS' || platform . os . family === 'Android' ) && ( window . innerHeight > window . innerWidth ) ) {
// Mobile portrait mode
_this . stream . videoDimensions = {
width : height || 0 ,
height : width || 0
} ;
}
else {
_this . stream . videoDimensions = {
width : width || 0 ,
height : height || 0
} ;
}
_this . stream . isLocalStreamReadyToPublish = true ;
_this . stream . ee . emitEvent ( 'stream-ready-to-publish' , [ ] ) ;
2018-07-11 11:47:53 +02:00
}
}
else {
// With screen share, video dimension must be got from a video element (onloadedmetadata event)
_this . videoReference . onloadedmetadata = function ( ) {
_this . stream . videoDimensions = {
width : _this . videoReference . videoWidth ,
height : _this . videoReference . videoHeight
} ;
_this . screenShareResizeInterval = setInterval ( function ( ) {
var firefoxSettings = mediaStream . getVideoTracks ( ) [ 0 ] . getSettings ( ) ;
2018-12-14 14:01:16 +01:00
var newWidth = ( platform . name === 'Chrome' || platform . name === 'Opera' ) ? _this . videoReference . videoWidth : firefoxSettings . width ;
var newHeight = ( platform . name === 'Chrome' || platform . name === 'Opera' ) ? _this . videoReference . videoHeight : firefoxSettings . height ;
2018-07-11 11:47:53 +02:00
if ( _this . stream . isLocalStreamPublished &&
( newWidth !== _this . stream . videoDimensions . width ||
newHeight !== _this . stream . videoDimensions . height ) ) {
var oldValue _1 = { width : _this . stream . videoDimensions . width , height : _this . stream . videoDimensions . height } ;
_this . stream . videoDimensions = {
width : newWidth || 0 ,
height : newHeight || 0
} ;
_this . session . openvidu . sendRequest ( 'streamPropertyChanged' , {
streamId : _this . stream . streamId ,
property : 'videoDimensions' ,
newValue : JSON . stringify ( _this . stream . videoDimensions ) ,
reason : 'screenResized'
} , function ( error , response ) {
if ( error ) {
console . error ( "Error sending 'streamPropertyChanged' event" , error ) ;
}
else {
_this . session . emitEvent ( 'streamPropertyChanged' , [ new StreamPropertyChangedEvent _1 . StreamPropertyChangedEvent ( _this . session , _this . stream , 'videoDimensions' , _this . stream . videoDimensions , oldValue _1 , 'screenResized' ) ] ) ;
_this . emitEvent ( 'streamPropertyChanged' , [ new StreamPropertyChangedEvent _1 . StreamPropertyChangedEvent ( _this , _this . stream , 'videoDimensions' , _this . stream . videoDimensions , oldValue _1 , 'screenResized' ) ] ) ;
}
} ) ;
}
} , 500 ) ;
_this . stream . isLocalStreamReadyToPublish = true ;
_this . stream . ee . emitEvent ( 'stream-ready-to-publish' , [ ] ) ;
} ;
}
}
else {
_this . stream . isLocalStreamReadyToPublish = true ;
_this . stream . ee . emitEvent ( 'stream-ready-to-publish' , [ ] ) ;
}
2018-04-26 15:33:47 +02:00
resolve ( ) ;
} ;
2018-10-01 11:17:05 +02:00
// Check if new constraints need to be generated. No constraints needed if
// - video track is given and no audio
// - audio track is given and no video
// - both video and audio tracks are given
if ( ( _this . properties . videoSource instanceof MediaStreamTrack && ! _this . properties . audioSource )
|| ( _this . properties . audioSource instanceof MediaStreamTrack && ! _this . properties . videoSource )
|| ( _this . properties . videoSource instanceof MediaStreamTrack && _this . properties . audioSource instanceof MediaStreamTrack ) ) {
var mediaStream = new MediaStream ( ) ;
if ( _this . properties . videoSource instanceof MediaStreamTrack ) {
mediaStream . addTrack ( _this . properties . videoSource ) ;
}
if ( _this . properties . audioSource instanceof MediaStreamTrack ) {
mediaStream . addTrack ( _this . properties . audioSource ) ;
}
// MediaStreamTracks are handled within callback - just call callback with new MediaStream() and let it handle the sources
successCallback ( mediaStream ) ;
// Return as we do not need to process further
return ;
}
2018-04-26 15:33:47 +02:00
_this . openvidu . generateMediaConstraints ( _this . properties )
. then ( function ( constraints ) {
var outboundStreamOptions = {
mediaConstraints : constraints ,
publisherProperties : _this . properties
} ;
_this . stream . setOutboundStreamOptions ( outboundStreamOptions ) ;
var constraintsAux = { } ;
2018-05-03 11:48:57 +02:00
var timeForDialogEvent = 1250 ;
2018-06-01 14:39:38 +02:00
if ( _this . stream . isSendVideo ( ) || _this . stream . isSendAudio ( ) ) {
var definedAudioConstraint _1 = ( ( constraints . audio === undefined ) ? true : constraints . audio ) ;
constraintsAux . audio = _this . stream . isSendScreen ( ) ? false : definedAudioConstraint _1 ;
2018-04-26 15:33:47 +02:00
constraintsAux . video = constraints . video ;
var startTime _1 = Date . now ( ) ;
_this . setPermissionDialogTimer ( timeForDialogEvent ) ;
navigator . mediaDevices . getUserMedia ( constraintsAux )
2018-06-01 14:39:38 +02:00
. then ( function ( mediaStream ) {
2018-04-26 15:33:47 +02:00
_this . clearPermissionDialogTimer ( startTime _1 , timeForDialogEvent ) ;
2018-06-01 14:39:38 +02:00
if ( _this . stream . isSendScreen ( ) && _this . stream . isSendAudio ( ) ) {
// When getting desktop as user media audio constraint must be false. Now we can ask for it if required
constraintsAux . audio = definedAudioConstraint _1 ;
2018-04-26 15:33:47 +02:00
constraintsAux . video = false ;
startTime _1 = Date . now ( ) ;
_this . setPermissionDialogTimer ( timeForDialogEvent ) ;
navigator . mediaDevices . getUserMedia ( constraintsAux )
. then ( function ( audioOnlyStream ) {
_this . clearPermissionDialogTimer ( startTime _1 , timeForDialogEvent ) ;
2018-06-01 14:39:38 +02:00
mediaStream . addTrack ( audioOnlyStream . getAudioTracks ( ) [ 0 ] ) ;
successCallback ( mediaStream ) ;
2018-04-26 15:33:47 +02:00
} ) [ "catch" ] ( function ( error ) {
_this . clearPermissionDialogTimer ( startTime _1 , timeForDialogEvent ) ;
2018-12-14 14:01:16 +01:00
if ( error . name === 'Error' ) {
// Safari OverConstrainedError has as name property 'Error' instead of 'OverConstrainedError'
error . name = error . constructor . name ;
}
2018-06-01 14:39:38 +02:00
var errorName , errorMessage ;
2018-04-26 15:33:47 +02:00
switch ( error . name . toLowerCase ( ) ) {
case 'notfounderror' :
errorName = OpenViduError _1 . OpenViduErrorName . INPUT _AUDIO _DEVICE _NOT _FOUND ;
errorMessage = error . toString ( ) ;
2018-06-01 14:39:38 +02:00
errorCallback ( new OpenViduError _1 . OpenViduError ( errorName , errorMessage ) ) ;
2018-04-26 15:33:47 +02:00
break ;
case 'notallowederror' :
2018-06-01 14:39:38 +02:00
errorName = OpenViduError _1 . OpenViduErrorName . DEVICE _ACCESS _DENIED ;
2018-04-26 15:33:47 +02:00
errorMessage = error . toString ( ) ;
2018-06-01 14:39:38 +02:00
errorCallback ( new OpenViduError _1 . OpenViduError ( errorName , errorMessage ) ) ;
2018-04-26 15:33:47 +02:00
break ;
case 'overconstrainederror' :
if ( error . constraint . toLowerCase ( ) === 'deviceid' ) {
errorName = OpenViduError _1 . OpenViduErrorName . INPUT _AUDIO _DEVICE _NOT _FOUND ;
2018-06-01 14:39:38 +02:00
errorMessage = "Audio input device with deviceId '" + constraints . video . deviceId . exact + "' not found" ;
2018-04-26 15:33:47 +02:00
}
else {
errorName = OpenViduError _1 . OpenViduErrorName . PUBLISHER _PROPERTIES _ERROR ;
errorMessage = "Audio input device doesn't support the value passed for constraint '" + error . constraint + "'" ;
}
2018-06-01 14:39:38 +02:00
errorCallback ( new OpenViduError _1 . OpenViduError ( errorName , errorMessage ) ) ;
break ;
2018-04-26 15:33:47 +02:00
}
} ) ;
}
else {
2018-06-01 14:39:38 +02:00
successCallback ( mediaStream ) ;
2018-04-26 15:33:47 +02:00
}
} ) [ "catch" ] ( function ( error ) {
_this . clearPermissionDialogTimer ( startTime _1 , timeForDialogEvent ) ;
2018-12-14 14:01:16 +01:00
if ( error . name === 'Error' ) {
// Safari OverConstrainedError has as name property 'Error' instead of 'OverConstrainedError'
error . name = error . constructor . name ;
}
2018-06-01 14:39:38 +02:00
var errorName , errorMessage ;
2018-04-26 15:33:47 +02:00
switch ( error . name . toLowerCase ( ) ) {
case 'notfounderror' :
2018-06-01 14:39:38 +02:00
navigator . mediaDevices . getUserMedia ( {
audio : false ,
video : constraints . video
} )
. then ( function ( mediaStream ) {
mediaStream . getVideoTracks ( ) . forEach ( function ( track ) {
track . stop ( ) ;
} ) ;
errorName = OpenViduError _1 . OpenViduErrorName . INPUT _AUDIO _DEVICE _NOT _FOUND ;
errorMessage = error . toString ( ) ;
errorCallback ( new OpenViduError _1 . OpenViduError ( errorName , errorMessage ) ) ;
} ) [ "catch" ] ( function ( e ) {
2018-04-26 15:33:47 +02:00
errorName = OpenViduError _1 . OpenViduErrorName . INPUT _VIDEO _DEVICE _NOT _FOUND ;
2018-06-01 14:39:38 +02:00
errorMessage = error . toString ( ) ;
errorCallback ( new OpenViduError _1 . OpenViduError ( errorName , errorMessage ) ) ;
} ) ;
2018-04-26 15:33:47 +02:00
break ;
case 'notallowederror' :
2018-06-01 14:39:38 +02:00
errorName = _this . stream . isSendScreen ( ) ? OpenViduError _1 . OpenViduErrorName . SCREEN _CAPTURE _DENIED : OpenViduError _1 . OpenViduErrorName . DEVICE _ACCESS _DENIED ;
2018-04-26 15:33:47 +02:00
errorMessage = error . toString ( ) ;
2018-06-01 14:39:38 +02:00
errorCallback ( new OpenViduError _1 . OpenViduError ( errorName , errorMessage ) ) ;
2018-04-26 15:33:47 +02:00
break ;
case 'overconstrainederror' :
2018-06-01 14:39:38 +02:00
navigator . mediaDevices . getUserMedia ( {
audio : false ,
video : constraints . video
} )
. then ( function ( mediaStream ) {
mediaStream . getVideoTracks ( ) . forEach ( function ( track ) {
track . stop ( ) ;
} ) ;
if ( error . constraint . toLowerCase ( ) === 'deviceid' ) {
errorName = OpenViduError _1 . OpenViduErrorName . INPUT _AUDIO _DEVICE _NOT _FOUND ;
errorMessage = "Audio input device with deviceId '" + constraints . audio . deviceId . exact + "' not found" ;
}
else {
errorName = OpenViduError _1 . OpenViduErrorName . PUBLISHER _PROPERTIES _ERROR ;
errorMessage = "Audio input device doesn't support the value passed for constraint '" + error . constraint + "'" ;
}
errorCallback ( new OpenViduError _1 . OpenViduError ( errorName , errorMessage ) ) ;
} ) [ "catch" ] ( function ( e ) {
if ( error . constraint . toLowerCase ( ) === 'deviceid' ) {
errorName = OpenViduError _1 . OpenViduErrorName . INPUT _VIDEO _DEVICE _NOT _FOUND ;
errorMessage = "Video input device with deviceId '" + constraints . video . deviceId . exact + "' not found" ;
}
else {
errorName = OpenViduError _1 . OpenViduErrorName . PUBLISHER _PROPERTIES _ERROR ;
errorMessage = "Video input device doesn't support the value passed for constraint '" + error . constraint + "'" ;
}
errorCallback ( new OpenViduError _1 . OpenViduError ( errorName , errorMessage ) ) ;
} ) ;
break ;
2018-04-26 15:33:47 +02:00
}
} ) ;
}
else {
reject ( new OpenViduError _1 . OpenViduError ( OpenViduError _1 . OpenViduErrorName . NO _INPUT _SOURCE _SET , "Properties 'audioSource' and 'videoSource' cannot be set to false or null at the same time when calling 'OpenVidu.initPublisher'" ) ) ;
}
} ) [ "catch" ] ( function ( error ) {
errorCallback ( error ) ;
} ) ;
} ) ;
} ;
2018-06-01 14:39:38 +02:00
/ * *
* @ hidden
* /
Publisher . prototype . reestablishStreamPlayingEvent = function ( ) {
if ( this . ee . getListeners ( 'streamPlaying' ) . length > 0 ) {
this . addPlayEventToFirstVideo ( ) ;
}
} ;
2018-04-26 15:33:47 +02:00
/* Private methods */
Publisher . prototype . setPermissionDialogTimer = function ( waitTime ) {
var _this = this ;
this . permissionDialogTimeout = setTimeout ( function ( ) {
2018-07-11 11:47:53 +02:00
_this . emitEvent ( 'accessDialogOpened' , [ ] ) ;
2018-04-26 15:33:47 +02:00
} , waitTime ) ;
} ;
Publisher . prototype . clearPermissionDialogTimer = function ( startTime , waitTime ) {
clearTimeout ( this . permissionDialogTimeout ) ;
if ( ( Date . now ( ) - startTime ) > waitTime ) {
// Permission dialog was shown and now is closed
2018-07-11 11:47:53 +02:00
this . emitEvent ( 'accessDialogClosed' , [ ] ) ;
2018-04-26 15:33:47 +02:00
}
} ;
return Publisher ;
2018-06-01 14:39:38 +02:00
} ( StreamManager _1 . StreamManager ) ) ;
2018-04-26 15:33:47 +02:00
exports . Publisher = Publisher ;
//# sourceMappingURL=Publisher.js.map