forked from aullman/OpenTok-Angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopentok-angular.min.js
10 lines (10 loc) · 3.81 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 (https://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(e,n){var i={streams:[],connections:[],publishers:[],init:function(t,o,s,r){this.session=e.initSession(t,o),i.session.on({sessionConnected:function(){i.publishers.forEach(function(e){i.session.publish(e,function(i){i&&n.$emit("otPublisherError",i,e)})})},streamCreated:function(e){n.$apply(function(){i.streams.push(e.stream)})},streamDestroyed:function(e){n.$apply(function(){i.streams.splice(i.streams.indexOf(e.stream),1)})},sessionDisconnected:function(){n.$apply(function(){i.streams.splice(0,i.streams.length),i.connections.splice(0,i.connections.length)})},connectionCreated:function(e){n.$apply(function(){i.connections.push(e.connection)})},connectionDestroyed:function(e){n.$apply(function(){i.connections.splice(i.connections.indexOf(e.connection),1)})}}),this.session.connect(s,function(e){r&&r(e,i.session)}),this.trigger("init")},addPublisher:function(e){this.publishers.push(e),this.trigger("otPublisherAdded")}};return e.$.eventing(i),i}]).directive("otLayout",["$window","$parse","OT","OTSession",function(e,n,i,t){return{restrict:"E",link:function(i,o,s){var r=n(s.props)(),c=initLayoutContainer(o[0],r),u=function(){c.layout(),i.$emit("otLayoutComplete")};i.$watch(function(){return o.children().length},u),e.addEventListener("resize",u),i.$on("otLayout",u);var a=function(){t.session.on("streamPropertyChanged",function(e){"videoDimensions"===e.changedProperty&&u()})};t.session?a():t.on("init",a)}}}]).directive("otPublisher",["OTSession",function(e){return{restrict:"E",scope:{props:"&"},link:function(n,i,t){var o=n.props()||{};o.width=o.width?o.width:ng.element(i).width(),o.height=o.height?o.height:ng.element(i).height();var s=ng.element(i).children();n.publisher=OT.initPublisher(t.apikey||e.session.apiKey,i[0],o,function(e){e&&n.$emit("otPublisherError",e,n.publisher)}),ng.element(i).append(s),n.publisher.on({accessDenied:function(){n.$emit("otAccessDenied")},accessDialogOpened:function(){n.$emit("otAccessDialogOpened")},accessDialogClosed:function(){n.$emit("otAccessDialogClosed")},accessAllowed:function(){ng.element(i).addClass("allowed"),n.$emit("otAccessAllowed")},loaded:function(){n.$emit("otLayout")},streamCreated:function(){n.$emit("otStreamCreated")},streamDestroyed:function(){n.$emit("otStreamDestroyed")}}),n.$on("$destroy",function(){e.session?e.session.unpublish(n.publisher):n.publisher.destroy(),e.publishers=e.publishers.filter(function(e){return e!==n.publisher}),n.publisher=null}),e.session&&(e.session.connected||e.session.isConnected&&e.session.isConnected())&&e.session.publish(n.publisher,function(e){e&&n.$emit("otPublisherError",e,n.publisher)}),e.addPublisher(n.publisher)}}}]).directive("otSubscriber",["OTSession",function(e){return{restrict:"E",scope:{stream:"=",props:"&"},link:function(n,i){var t=n.stream,o=n.props()||{};o.width=o.width?o.width:ng.element(i).width(),o.height=o.height?o.height:ng.element(i).height();var s=ng.element(i).children(),r=e.session.subscribe(t,i[0],o,function(e){e&&n.$emit("otSubscriberError",e,r)});r.on("loaded",function(){n.$emit("otLayout")}),ng.element(i).append(s),n.$on("$destroy",function(){e.session.unsubscribe(r)})}}}]);