forked from westy92/OpenTok-Angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opentok-angular.min.js
10 lines (10 loc) · 3.11 KB
/
opentok-angular.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* opentok-angular (https://github.com/aullman/OpenTok-Angular)
*
* Angular module for OpenTok
*
* @Author: Adam Ullman (http://github.com/aullman)
* @Copyright (c) 2014 Adam Ullman
* @License: Released under the MIT license (http://opensource.org/licenses/MIT)
**/
if(!window.OT)throw new Error("You must include the OT library before the OT_Angular library");var ng;ng="undefined"==typeof angular&&"undefined"!=typeof require?require("angular"):angular;var initLayoutContainer;initLayoutContainer=window.hasOwnProperty("initLayoutContainer")||"undefined"==typeof require?window.initLayoutContainer:require("opentok-layout-js").initLayoutContainer,ng.module("opentok",[]).factory("OT",function(){return OT}).factory("OTSession",["OT","$rootScope",function(n,e){var t={streams:[],connections:[],publishers:[],init:function(i,o){return this.session=n.initSession(i,o),t.session.on({sessionConnected:function(){},streamCreated:function(n){e.$apply(function(){t.streams.push(n.stream)})},streamDestroyed:function(n){e.$apply(function(){t.streams.splice(t.streams.indexOf(n.stream),1)})},sessionDisconnected:function(){e.$apply(function(){t.streams.splice(0,t.streams.length),t.connections.splice(0,t.connections.length)})},connectionCreated:function(n){e.$apply(function(){t.connections.push(n.connection)})},connectionDestroyed:function(n){e.$apply(function(){t.connections.splice(t.connections.indexOf(n.connection),1)})}}),this.trigger("init"),n.checkSystemRequirements()},connect:function(n,e){this.session.connect(n,function(n){e&&e(n)})},initPublisher:function(e,t,i){return n.initPublisher(e,t,function(n){i&&i(n)})},publish:function(n,e){t.session.publish(n,function(n){e&&e(n)})},addPublisher:function(n){this.publishers.push(n),this.trigger("otPublisherAdded")}};return n.$.eventing(t),t}]).directive("otLayout",["$window","$parse","OT","OTSession",function(n,e,t,i){return{restrict:"E",link:function(t,o,r){var s=e(r.props)(),c=initLayoutContainer(o[0],s),u=function(){c.layout(),t.$emit("otLayoutComplete")};t.$watch(function(){return o.children().length},u),n.addEventListener("resize",u),t.$on("otLayout",u);var a=function(){i.session.on("streamPropertyChanged",function(n){"videoDimensions"===n.changedProperty&&u()})};i.session?a():i.on("init",a)}}}]).directive("otPublisher",["OTSession",function(n){return{restrict:"E",scope:{props:"&",callBack:"&"},link:function(n,e,t){var i=n.props()||{};i.width=i.width?i.width:ng.element(e).width(),i.height=i.height?i.height:ng.element(e).height();var o=ng.element(e).children();n.callBack&&n.callBack({initPublisherProperties:{targetElement:e[0],props:i}}),ng.element(e).append(o)}}}]).directive("otSubscriber",["OTSession",function(n){return{restrict:"E",scope:{stream:"=",props:"&"},link:function(e,t){var i=e.stream,o=e.props()||{};o.width=o.width?o.width:ng.element(t).width(),o.height=o.height?o.height:ng.element(t).height();var r=ng.element(t).children(),s=n.session.subscribe(i,t[0],o,function(n){n&&e.$emit("otSubscriberError",n,s)});s.on("loaded",function(){e.$emit("otLayout")}),ng.element(t).append(r),e.$on("$destroy",function(){console.log("in subscriber destroy"),n.session.unsubscribe(s)})}}}]);