src/opentok-screen-sharing.js
function () {

    var createPublisher = function (publisherDiv) {

      var innerDeferred = $.Deferred();

      var getContainer = function () {
        if (publisherDiv) { return publisherDiv; }
        if (typeof _this.screenSharingContainer === 'function') {
          return document.querySelector(_this.screenSharingContainer('publisher', 'screen'));
        } else {
          return _this.screenSharingContainer;
        }
      }

      var container = getContainer();
      var properties =
        _this.localScreenProperties ||
        _this.localScreenProperties ||
        _defaultScreenProperties;

      _this.publisher = OT.initPublisher(container, properties, function (error) {
        if (error) {
          _triggerEvent('screenSharingError', error);
          innerDeferred.reject(_.extend(_.omit(error, 'messsage'), {
            message: 'Error starting the screen sharing',
          }));
        } else {
          _this.publisher.on('mediaStopped', function () {
            end();
          });
          innerDeferred.resolve();
        }
      });

      return innerDeferred.promise();
    };

    var outerDeferred = $.Deferred();

    if (_this.annotation && _this.externalWindow) {
      _log(_logEventData.enableAnnotations, _logEventData.variationSuccess);

      _accPack.setupExternalAnnotation()
        .then(function (annotationWindow) {
          _this.annotationWindow = annotationWindow || null;
          var annotationElements = annotationWindow.createContainerElements();
          createPublisher(annotationElements.publisher)
            .then(function () {
              outerDeferred.resolve(annotationElements.annotation);
            });

        });
    } else {

      createPublisher()
        .then(function () {
          outerDeferred.resolve();
        });

    }

    return outerDeferred.promise();
  }
function () {

    var createPublisher = function (publisherDiv) {

      var innerDeferred = $.Deferred();

      var getContainer = function () {
        if (publisherDiv) { return publisherDiv; }
        if (typeof _this.screenSharingContainer === 'function') {
          return document.querySelector(_this.screenSharingContainer('publisher', 'screen'));
        } else {
          return _this.screenSharingContainer;
        }
      }

      var container = getContainer();
      var properties =
        _this.localScreenProperties ||
        _this.localScreenProperties ||
        _defaultScreenProperties;

      _this.publisher = OT.initPublisher(container, properties, function (error) {
        if (error) {
          _triggerEvent('screenSharingError', error);
          innerDeferred.reject(_.extend(_.omit(error, 'messsage'), {
            message: 'Error starting the screen sharing',
          }));
        } else {
          _this.publisher.on('mediaStopped', function () {
            end();
          });
          innerDeferred.resolve();
        }
      });

      return innerDeferred.promise();
    };

    var outerDeferred = $.Deferred();

    if (_this.annotation && _this.externalWindow) {
      _log(_logEventData.enableAnnotations, _logEventData.variationSuccess);

      _accPack.setupExternalAnnotation()
        .then(function (annotationWindow) {
          _this.annotationWindow = annotationWindow || null;
          var annotationElements = annotationWindow.createContainerElements();
          createPublisher(annotationElements.publisher)
            .then(function () {
              outerDeferred.resolve(annotationElements.annotation);
            });

        });
    } else {

      createPublisher()
        .then(function () {
          outerDeferred.resolve();
        });

    }

    return outerDeferred.promise();
  }
function ( ) { var createPublisher = function ( publisherDiv ) { var innerDeferred = $ . Deferred ( ) ; var getContainer = function ( ) { if ( publisherDiv ) { return publisherDiv ; } if ( typeof _this . screenSharingContainer === 'function' ) { return document . querySelector ( _this . screenSharingContainer ( 'publisher' , 'screen' ) ) ; } else { return _this . screenSharingContainer ; } } var container = getContainer ( ) ; var properties = _this . localScreenProperties || _this . localScreenProperties || _defaultScreenProperties ; _this . publisher = OT . initPublisher ( container , properties , function ( error ) { if ( error ) { _triggerEvent ( 'screenSharingError' , error ) ; innerDeferred . reject ( _ . extend ( _ . omit ( error , 'messsage' ) , { message : 'Error starting the screen sharing' , } ) ) ; } else { _this . publisher . on ( 'mediaStopped' , function ( ) { end ( ) ; } ) ; innerDeferred . resolve ( ) ; } } ) ; return innerDeferred . promise ( ) ; } ; var outerDeferred = $ . Deferred ( ) ; if ( _this . annotation && _this . externalWindow ) { _log ( _logEventData . enableAnnotations , _logEventData . variationSuccess ) ; _accPack . setupExternalAnnotation ( ) . then ( function ( annotationWindow ) { _this . annotationWindow = annotationWindow || null ; var annotationElements = annotationWindow . createContainerElements ( ) ; createPublisher ( annotationElements . publisher ) . then ( function ( ) { outerDeferred . resolve ( annotationElements . annotation ) ; } ) ; } ) ; } else { createPublisher ( ) . then ( function ( ) { outerDeferred . resolve ( ) ; } ) ; } return outerDeferred . promise ( ) ; }
Create a publisher for the screen.  If we're using annotation, we first need
to create the annotion window and get a reference to its annotation container
element so that we can pass it to the initPublisher function.
@returns {promise} < Resolve: [Object] Container element for annotation in external window >
Create a publisher for the screen . If we re using annotation we first need to create the annotion window and get a reference to its annotation container element so that we can pass it to the initPublisher function .