├── .gitignore ├── Gruntfile.js ├── LICENSE ├── README.md ├── bower.json ├── dist ├── angular-rtcomm.js ├── angular-rtcomm.min.js └── css │ ├── angular-rtcomm.css │ └── angular-rtcomm.min.css ├── karma.conf.js ├── package.json ├── src ├── css │ └── angular-rtcomm.css ├── js │ ├── angular-rtcomm.js │ ├── rtcomm-directives.js │ ├── rtcomm-presence.js │ └── rtcomm-services.js └── templates │ └── rtcomm │ ├── rtcomm-alert.html │ ├── rtcomm-chat.html │ ├── rtcomm-endpoint-status.html │ ├── rtcomm-iframe.html │ ├── rtcomm-modal-alert.html │ ├── rtcomm-modal-call.html │ ├── rtcomm-presence.html │ ├── rtcomm-queues.html │ ├── rtcomm-register.html │ ├── rtcomm-sessionmgr.html │ └── rtcomm-video.html └── test ├── sample.html ├── sampleConfig.json ├── testChat.js └── testRtcommServiceSpec.js /.gitignore: -------------------------------------------------------------------------------- 1 | /.settings 2 | /bower_components 3 | /node_modules 4 | .project -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | 3 | require('load-grunt-tasks')(grunt); 4 | 5 | // Project configuration. 6 | grunt.initConfig({ 7 | pkg: grunt.file.readJSON('package.json'), 8 | 9 | meta: { 10 | banner: '/**\n' + 11 | ' * Copyright 2014 IBM Corp.\n' + 12 | ' *\n' + 13 | ' * Licensed under the Apache License, Version 2.0 (the "License");\n' + 14 | ' * you may not use this file except in compliance with the License.\n' + 15 | ' * You may obtain a copy of the License at\n' + 16 | ' *\n' + 17 | ' * http://www.apache.org/licenses/LICENSE-2.0\n' + 18 | ' *\n' + 19 | ' * Unless required by applicable law or agreed to in writing, software\n' + 20 | ' * distributed under the License is distributed on an "AS IS" BASIS,\n' + 21 | ' * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n' + 22 | ' * See the License for the specific language governing permissions and\n' + 23 | ' * limitations under the License.\n' + 24 | ' *\n' + 25 | ' * <%= pkg.description %>\n' + 26 | ' * @version v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' + 27 | ' * @link <%= pkg.homepage %>\n' + 28 | ' * @author <%= pkg.author %>\n' + 29 | ' */\n' 30 | }, 31 | 32 | dirs: { 33 | src: 'src', 34 | dest: 'dist' 35 | }, 36 | 37 | concat: { 38 | options: { 39 | banner: '<%= meta.banner %>' 40 | }, 41 | dist: { 42 | // src: ['<%= dirs.src %>/*.js', '<%= dirs.src %>/**/*.js'], 43 | src: ['<%= dirs.src %>/js/angular-rtcomm.js', '<%= dirs.src %>/js/rtcomm-services.js', '<%= dirs.src %>/js/rtcomm-directives.js', '<%= dirs.src %>/js/rtcomm-presence.js'], 44 | dest: '<%= dirs.dest %>/<%= pkg.name %>.js' 45 | } 46 | }, 47 | 48 | copy: { 49 | main: { 50 | expand: true, 51 | cwd: '<%= dirs.src %>', 52 | src: ['css/*.css'], 53 | dest: '<%= dirs.dest %>', 54 | } 55 | }, 56 | 57 | cssmin: { 58 | my_target: { 59 | files: [{ 60 | expand: true, 61 | cwd: '<%= dirs.src %>', 62 | src: ['css/*.css'], 63 | dest: '<%= dirs.dest %>', 64 | ext: '.min.css' 65 | }] 66 | } 67 | }, 68 | 69 | ngAnnotate: { 70 | dist: { 71 | files: { 72 | '<%= dirs.dest %>/<%= pkg.name %>.js': ['<%= dirs.dest %>/<%= pkg.name %>.js'] 73 | } 74 | } 75 | }, 76 | 77 | uglify: { 78 | options: { 79 | banner: '<%= meta.banner %>' 80 | }, 81 | dist: { 82 | src: ['<%= concat.dist.dest %>'], 83 | dest: '<%= dirs.dest %>/<%= pkg.name %>.min.js' 84 | } 85 | }, 86 | 87 | jshint: { 88 | files: ['Gruntfile.js', '<%= dirs.src %>/*.js', 'test/unit/*.js'], 89 | options: { 90 | curly: false, 91 | browser: true, 92 | eqeqeq: true, 93 | immed: true, 94 | latedef: true, 95 | newcap: true, 96 | noarg: true, 97 | sub: true, 98 | undef: true, 99 | boss: true, 100 | eqnull: true, 101 | expr: true, 102 | node: true, 103 | globals: { 104 | exports: true, 105 | angular: false, 106 | $: false 107 | } 108 | } 109 | }, 110 | 111 | watch: { 112 | dev: { 113 | files: ['<%= dirs.src %>/**'], 114 | tasks: ['build'] 115 | }, 116 | }, 117 | 118 | ngtemplates: { 119 | 'angular-rtcomm-ui': { 120 | cwd: '<%= dirs.src %>', 121 | src: ['templates/rtcomm/**.html', '!templates/rtcomm/rtcomm-presence.html'], 122 | dest: '<%= dirs.dest %>/<%= pkg.name %>.js', 123 | options: { 124 | htmlmin: { collapseWhitespace: true, collapseBooleanAttributes: true }, 125 | append: 'true' 126 | } 127 | }, 128 | 'angular-rtcomm-presence': { 129 | cwd: '<%= dirs.src %>', 130 | src: 'templates/rtcomm/rtcomm-presence.html', 131 | dest: '<%= dirs.dest %>/<%= pkg.name %>.js', 132 | options: { 133 | htmlmin: { collapseWhitespace: true, collapseBooleanAttributes: true }, 134 | append: 'true' 135 | } 136 | 137 | } 138 | } 139 | }); 140 | 141 | // Build task. 142 | grunt.registerTask('build', ['jshint', 'concat', 'ngtemplates', 'ngAnnotate', 'uglify', 'copy', 'cssmin']); 143 | 144 | // Default task. 145 | //grunt.registerTask('default', ['build', 'watch']); 146 | grunt.registerTask('default', ['build']); 147 | 148 | }; 149 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | lib.angular-rtcomm 2 | ================== 3 | This repository contains the Rtcomm Angular.js module. The Rtcomm Angular module exposes a set of real-time communication features in the form of a service and a number of Angular directives and controllers. 4 | This module is built on the [rtcomm.js](https://github.com/WASdev/lib.rtcomm.clientjs) open source JavaScript library which wraps [WebRTC](http://www.webrtc.org/) with call 5 | signaling and a number of advanced real-time communications capabilities like presence and chat. 6 | 7 | ## Requirements 8 | Rtcomm utilizes MQTT for call signaling so at a minimum you will need an MQTT message broker that supports web sockets. There are many open source and productized versions of MQTT message brokers available. 9 | 10 | ## Install 11 | To install the angular-rtcomm module for use in an AngularJS application, you can use bower: 12 | 13 | **bower install angular-rtcomm** 14 | 15 | ## Build 16 | To build the angular-rtcomm module, you can use npm: 17 | 18 | This is useful if you want to modify the angular-rtcomm templates. 19 | 20 | ## Test 21 | This repository relies on Karma for testing. To run the test framework you can type the following in the root lib.angular-rtcomm directory: 22 | 23 | **karma start** 24 | 25 | Note that the test framework assumes the MQTT broker is running on localhost:9080. There is also currently a dependency on the WebSphere Liberty server (which includes an embedded MQTT broker) for some of the Rtcomm features. The link to download a version of WebSphere Liberty for development and testing can be found at the top of the page. 26 | 27 | We are working on an npm install of the development environment so stay tuned. 28 | 29 | A sample page is also included in the test directory along with a sample config file that can be used to run the test. 30 | 31 | ## Usage 32 | 33 | ### Initialization 34 | To use the module, you will need to include the following js and css files with your project: 35 | 36 | First the angular-rtcomm related files: 37 | ```html 38 | 39 | 40 | ``` 41 | 42 | See the dist directory for minified versions. 43 | 44 | In addition, the angular-rtcomm module relies on the following additional JavaScript libraries that can be accessed via various CDNs: 45 | 46 | ```html 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | ``` 60 | 61 | 62 | **Note** 63 | The above dependencies can be accessed via CDN as above or via your bower_component install location. 64 | We are also working to reduce the number of dependencies (or to at least provide more flexibility in when these dependencies are required). 65 | 66 | 67 | ### Module injection 68 | AngularJS applications inject the angular-rtcomm module as follows: 69 | 70 | var sampleModule = angular.module('sampleModule', ['angular-rtcomm']); 71 | 72 | ### RtcommService 73 | The RtcommService is the singleton that controls all aspects of the Rtcomm module. Its the only service AngularJS applications need to inject when using the angular-rtcomm module. 74 | 75 | The RtcommService broadcasts all its related events to the $rootScope. The events published by the RtcommService are a combination of events generated by the angular-rtcomm module and the rtcomm.js library described above that this module wraps. Here is the list of events: 76 | 77 | * queueupdate 78 | * newendpoint 79 | * session:started 80 | * session:alerting 81 | * session:trying 82 | * session:ringing 83 | * session:queued 84 | * session:failed 85 | * session:stopped 86 | * webrtc:connected 87 | * webrtc:disconnected 88 | * chat:connected 89 | * chat:message 90 | * destroyed 91 | * rtcomm::init 92 | * endpointActivated 93 | * noEndpointActivated 94 | * rtcomm::iframeUpdate 95 | 96 | And the methods exposed by the RtcommService include the following: 97 | 98 | * isInitialized 99 | * setConfig 100 | * getPresenceMonitor 101 | * publishPresence 102 | * addToPresenceRecord 103 | * removeFromPresenceRecord 104 | * setPresenceRecordState 105 | * getEndpoint 106 | * destroyEndpoint 107 | * register 108 | * unregister 109 | * joinQueue 110 | * leaveQueue 111 | * getQueues 112 | * sendChatMessage 113 | * getChats 114 | * isWebrtcConnected 115 | * getSessionState 116 | * setAlias 117 | * setUserID 118 | * setPresenceTopic 119 | * getIframeURL 120 | * putIframeURL 121 | * placeCall 122 | * getSessions 123 | * setActiveEndpoint 124 | * getActiveEndpoint 125 | * getRemoteEndpoint 126 | * setDefaultViewSelector 127 | * setViewSelector 128 | * setVideoView 129 | 130 | 131 | ### List of AngularJS directives 132 | Here is a complete list of all the currently supported directives. 133 | 134 | #### rtcomm-register: 135 | Directive used to register an endpoint. Registration implies creation of a user record as a retained message on the configured presence topic which can be accessed by any endpoint or service that has permissions to subscribe on the registration topic. This is registration is required after initialization. If the user name is specified in advance, for example via a cookie, the userid can be specified when initializing the RtcommService: 136 | ```html 137 | 138 | ``` 139 | No init parameters. 140 | 141 | #### rtcomm-queues: 142 | Directive used to view and join any available call queue. Can be used by helpdesk agents (only availble when working with WebSphere): 143 | ```html 144 | 145 | ``` 146 | 147 | #### rtcomm-presence: 148 | Directive used to view presence information: 149 | ```html 150 | 151 | ``` 152 | 153 | #### rtcomm-chat: 154 | Directive used to display a chat window: 155 | ```html 156 | 157 | ``` 158 | 159 | #### rtcomm-video: 160 | Directive that contains a WebRTC video window (both self and remote views): 161 | ```html 162 | 163 | ``` 164 | 165 | #### rtcomm-endpoint-status: 166 | Directive that displays status about the active endpoint: 167 | ```html 168 | 169 | ``` 170 | 171 | #### rtcomm-sessionmgr: 172 | Directive that manages multiple endpoints and their associated sessions. For instance, used by a helpdesk agent to manage multiple sessions: 173 | ```html 174 | 175 | ``` 176 | 177 | ### List of AngularJS Controllers 178 | 179 | This controller can read configuration from a specified JSON file: 180 | **RtcommConfigController** 181 | 182 | This controller displays the alerting modal which allows the user to accept or reject an inbound call: 183 | **RtcommAlertModalController** 184 | 185 | This controller displays an outbound call modal: 186 | **RtcommCallModalController** 187 | 188 | This doc is a work in progress. Still need to document all the init parameteres for each directive, more details on testing, etc. 189 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-rtcomm", 3 | "version": "1.0.3", 4 | "description": "Angular module for Rtcomm", 5 | "main": [ 6 | "dist/angular-rtcomm.js", 7 | "dist/angular-rtcomm.min.js", 8 | "dist/css/angular-rtcomm.css", 9 | "dist/css/angular-rtcomm.min.css" 10 | ], 11 | "keywords": [ 12 | "webrtc", 13 | "rtcomm", 14 | "angularjs" 15 | ], 16 | "authors": [ 17 | "Brian Pulito", 18 | "Scott Graham" 19 | ], 20 | "license": "Apache", 21 | "homepage": "https://developer.ibm.com/wasdev/docs/webrtc/", 22 | "ignore": [ 23 | "**/.*", 24 | "node_modules", 25 | "bower_components", 26 | "test", 27 | "tests", 28 | "src", 29 | "Gruntfile.js", 30 | "package.json" 31 | ], 32 | "dependencies": { 33 | "jquery": "~2.1.1", 34 | "angular-tree-control": "~0.2.7", 35 | "bootstrap": "~3.3.1", 36 | "angular": "^1.4.6", 37 | "angular-bootstrap": "~0.13.0", 38 | "rtcomm": "^1.0.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /dist/angular-rtcomm.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2014 IBM Corp. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Angular module for Rtcomm 17 | * @version v1.0.3 - 2016-02-02 18 | * @link https://github.com/WASdev/lib.angular-rtcomm 19 | * @author Brian Pulito (https://github.com/bpulito) 20 | */ 21 | !function(){angular.module("angular-rtcomm",["ui.bootstrap","treeControl","angular-rtcomm-ui","angular-rtcomm-presence","angular-rtcomm-service"])}(),function(){function a(a,b,c){b.debug("RtcommConfigService: Abs URL: "+a.absUrl());var d=a.search().disableRtcomm;d="undefined"==typeof d||null===d?!1:"true"===d?!0:!1,b.debug("RtcommConfigService: _disableRtcomm = "+d);var e={server:a.host(),port:a.port(),rtcommTopicPath:"/rtcomm/",createEndpoint:!1,appContext:"default",userid:"",presence:{topic:""}};b.debug("providerConfig.server: "+e.server),b.debug("providerConfig.port: "+e.port);var f={chat:!0,webrtc:!0},g=!0,h=!0,i="DEBUG",j=null,k=null,l=function(a){e.server="undefined"!=typeof a.server?a.server:e.server,e.port="undefined"!=typeof a.port?a.port:e.port,e.rtcommTopicPath="undefined"!=typeof a.rtcommTopicPath?a.rtcommTopicPath:e.rtcommTopicPath,e.createEndpoint="undefined"!=typeof a.createEndpoint?a.createEndpoint:e.createEndpoint,e.appContext="undefined"!=typeof a.appContext?a.appContext:e.appContext,e.presence.topic="undefined"!=typeof a.presenceTopic?a.presenceTopic:e.presence.topic,f.chat="undefined"!=typeof a.chat?a.chat:f.chat,f.webrtc="undefined"!=typeof a.webrtc?a.webrtc:f.webrtc,g="undefined"!=typeof a.broadcastAudio?a.broadcastAudio:g,h="undefined"!=typeof a.broadcastVideo?a.broadcastVideo:h,k="undefined"!=typeof a.ringbacktone?a.ringbacktone:k,j="undefined"!=typeof a.ringtone?a.ringtone:j,i="undefined"!=typeof a.rtcommDebug?a.rtcommDebug:i,b.debug("rtcommDebug from config is: "+a.rtcommDebug),"undefined"!=typeof a.userid&&(e.userid=a.userid),b.debug("providerConfig is now: ",e)};return{setProviderConfig:function(a){l(a)},getProviderConfig:function(){return e},getWebRTCEnabled:function(){return f.webrtc},getChatEnabled:function(){return f.chat},getBroadcastAudio:function(){return g},getBroadcastVideo:function(){return h},getRingTone:function(){return j},getRingBackTone:function(){return k},getRtcommDebug:function(){return i},isRtcommDisabled:function(){return d}}}function b(a,b,c,d){var e=new rtcomm.EndpointProvider,f=!1,g=null,h=[],i=null,j=!1,k="selfView",l="remoteView";e.setLogLevel(d.getRtcommDebug()),b.debug("rtcomm-service - endpointProvider log level is: "+e.getLogLevel()),b.debug("rtcomm-service - endpointProvider log level should be: "+d.getRtcommDebug()),e.setAppContext(d.getProviderConfig().appContext);var m=function(){return null==i&&(i={state:"available",userDefines:[]}),i},n=function(){var a={ringbacktone:d.getRingBackTone(),ringtone:d.getRingTone(),webrtcConfig:{broadcast:{audio:d.getBroadcastAudio(),video:d.getBroadcastVideo()}},webrtc:d.getWebRTCEnabled(),chat:d.getChatEnabled()};return a};e.on("reset",function(a){x({type:"danger",msg:a.reason})}),e.on("queueupdate",function(c){b.debug("<<------rtcomm-service------>> - Event: queueupdate"),b.debug("queueupdate",c),a.$evalAsync(function(){a.$broadcast("queueupdate",c)})}),e.on("newendpoint",function(c){b.debug("<<------rtcomm-service------>> - Event: newendpoint remoteEndpointID: "+c.getRemoteEndpointID()),c.on("onetimemessage",function(c){if(b.debug("<<------rtcomm-onetimemessage------>> - Event: ",c),"undefined"!=c.onetimemessage.type&&"iFrameURL"==c.onetimemessage.type){var d=s(c.endpoint.id);d.iFrameURL=c.onetimemessage.iFrameURL,a.$evalAsync(function(){a.$broadcast("rtcomm::iframeUpdate",c.endpoint.id,c.onetimemessage.iFrameURL)})}}),a.$evalAsync(function(){a.$broadcast("newendpoint",c)})});var o=function(c){b.debug("<<------rtcomm-service------>> - Event: "+c.eventName+" remoteEndpointID: "+c.endpoint.getRemoteEndpointID()),a.$evalAsync(function(){if(c.eventName.indexOf("session:")>-1){var b=s(c.endpoint.id);b.sessionState=c.eventName}a.$broadcast(c.eventName,c)}),1==j&&a.$digest()};e.setRtcommEndpointConfig({ringtone:d.getRingTone(),ringbacktone:d.getRingBackTone(),"session:started":function(c){b.debug("<<------rtcomm-service------>> - Event: "+c.eventName+" remoteEndpointID: "+c.endpoint.getRemoteEndpointID()),a.$evalAsync(function(){var b=s(c.endpoint.id);v(c.endpoint.id),b.sessionStarted=!0,b.remoteEndpointID=c.endpoint.getRemoteEndpointID(),a.$broadcast(c.eventName,c)}),1==j&&a.$digest()},"session:alerting":o,"session:trying":o,"session:ringing":o,"session:queued":o,"session:failed":function(c){b.debug("<<------rtcomm-service------>> - Event: "+c.eventName+" remoteEndpointID: "+c.endpoint.getRemoteEndpointID()),a.$evalAsync(function(){t(c.endpoint.id),a.$broadcast(c.eventName,c)}),1==j&&a.$digest()},"session:stopped":function(c){b.debug("<<------rtcomm-service------>> - Event: "+c.eventName+" remoteEndpointID: "+c.endpoint.getRemoteEndpointID()),a.$evalAsync(function(){t(c.endpoint.id),a.$broadcast(c.eventName,c)}),1==j&&a.$digest()},"webrtc:connected":function(c){b.debug("<<------rtcomm-service------>> - Event: "+c.eventName+" remoteEndpointID: "+c.endpoint.getRemoteEndpointID()),a.$evalAsync(function(){s(c.endpoint.id).webrtcConnected=!0,a.$broadcast(c.eventName,c)}),1==j&&a.$digest()},"webrtc:remotemuted":function(c){b.debug("<<------rtcomm-service------>> - Event: "+c.eventName+" remoteEndpointID: "+c.endpoint.getRemoteEndpointID()),a.$evalAsync(function(){a.$broadcast(c.eventName,c)}),1==j&&a.$digest()},"webrtc:disconnected":function(c){b.debug("<<------rtcomm-service------>> - Event: "+c.eventName+" remoteEndpointID: "+c.endpoint.getRemoteEndpointID()),a.$evalAsync(function(){var b=r(c.endpoint.id);null!=b&&(b.webrtcConnected=!1),a.$broadcast(c.eventName,c)}),1==j&&a.$digest()},"chat:connected":o,"chat:disconnected":o,"chat:message":function(c){b.debug("<<------rtcomm-service------>> - Event: "+c.eventName+" remoteEndpointID: "+c.endpoint.getRemoteEndpointID()),a.$evalAsync(function(){var b={time:new Date,name:c.message.from,message:angular.copy(c.message.message)};s(c.endpoint.id).chats.push(b),a.$broadcast(c.eventName,c)}),1==j&&a.$digest()},destroyed:o});var p=function(c){b.debug("<<------rtcomm-service------>> - Event: Provider init succeeded"),null!=i&&(b.debug("RtcommService: initSuccess: updating presence record"),e.publishPresence(i)),a.$evalAsync(function(){var b={ready:c.ready,registered:c.registered,endpoint:c.endpoint,userid:d.getProviderConfig().userid};a.$broadcast("rtcomm::init",!0,b)}),1==j&&a.$digest()},q=function(c){b.debug("<<------rtcomm-service------>> - Event: Provider init failed: error: ",c),a.$evalAsync(function(){a.$broadcast("rtcomm::init",!1,c)}),1==j&&a.$digest()},r=function(a){for(var b=null,c=0;c> - Event: ",c),"undefined"!=c.onetimemessage.type&&"iFrameURL"==c.onetimemessage.type){var d=s(c.endpoint.id);d.iFrameURL=c.onetimemessage.iFrameURL,a.$evalAsync(function(){a.$broadcast("rtcomm::iframeUpdate",c.endpoint.id,c.onetimemessage.iFrameURL)})}})):d=e.getRtcommEndpoint(c),d},v=function(b){var c=w();if(null!=c&&c!=b){var d=r(c);null!=d&&(d.activated=!1)}var d=s(b);d.activated=!0,a.$broadcast("endpointActivated",b)},w=function(){for(var a=null,b=0;b-1&&c.chat.enable(),b.indexOf("webrtc")>-1){var d=!0;b.indexOf("disableTrickleICE")>-1&&(d=!1),c.webrtc.enable({trickleICE:d})}return v(c.id),c.connect(a),c.id},getSessions:function(){return h},endCall:function(a){a.disconnect()},setActiveEndpoint:function(a){v(a)},getActiveEndpoint:function(){return w()},getRemoteEndpoint:function(a){var b=null;if(null!=a){var c=r(a);null!=c&&(b=c.remoteEndpointID)}return b},setDefaultViewSelector:function(){k="selfView",l="remoteView"},setViewSelector:function(a,b){k=a,l=b},setVideoView:function(a){b.debug("rtcommVideo: setting local media");var c=null;"undefined"!=typeof a&&null!=a?c=u(a):null!=w()&&(c=u(w())),null!=c&&c.webrtc.setLocalMedia({mediaOut:document.querySelector("#"+k),mediaIn:document.querySelector("#"+l)})}}}angular.module("angular-rtcomm-service",[]).config(["$logProvider",function(a){a.debugEnabled(!0)}]).factory("RtcommConfigService",a).factory("RtcommService",b),a.$inject=["$location","$log","$window"],b.$inject=["$rootScope","$log","$http","RtcommConfigService"]}(),function(){function a(a,b){return{restrict:"E",templateUrl:"templates/rtcomm/rtcomm-sessionmgr.html",controller:["$scope",function(c){c.sessions=a.getSessions(),c.sessMgrActiveEndpointUUID=a.getActiveEndpoint(),c.publishPresence=!1,c.sessionPresenceData=[],c.init=function(a){c.publishPresence=a,c.updatePresence()},c.$on("endpointActivated",function(a,d){b.debug("rtcommSessionmgr: endpointActivated ="+d),c.sessMgrActiveEndpointUUID=d}),c.$on("session:started",function(a,d){b.debug("rtcommSessionmgr: session:started: uuid ="+d.endpoint.id),c.updatePresence()}),c.activateSession=function(d){b.debug("rtcommSessionmgr: activateEndpoint ="+d),c.sessMgrActiveEndpointUUID!=d&&a.setActiveEndpoint(d)},c.updatePresence=function(){1==c.publishPresence&&(a.removeFromPresenceRecord(c.sessionPresenceData,!1),c.sessionPresenceData=[{name:"sessions",value:String(c.sessions.length)}],a.addToPresenceRecord(c.sessionPresenceData))}}],controllerAs:"sessionmgr"}}function b(a,b){return{restrict:"E",templateUrl:"templates/rtcomm/rtcomm-register.html",controller:["$scope",function(c){c.nextAction="Register",c.reguserid="",c.invalid=!1;var d=/(\$|#|\+|\/|\\)+/i;c.$watch("reguserid",function(){c.reguserid.length<1||d.test(c.reguserid)?c.invalid=!0:c.invalid=!1}),c.onRegClick=function(){"Register"!==c.nextAction||d.test(c.reguserid)?(b.debug("Unregister: reguserid ="+c.reguserid),a.unregister()):(b.debug("Register: reguserid ="+c.reguserid),a.register(c.reguserid))},c.$on("rtcomm::init",function(a,b,d){1==b?(c.nextAction="Unregister",c.reguserid=d.userid):(c.nextAction="Register","destroyed"==d?c.reguserid="":c.reguserid="Init failed:"+d)})}],controllerAs:"register"}}function c(a,b){return{restrict:"E",templateUrl:"templates/rtcomm/rtcomm-queues.html",controller:["$scope",function(c){c.rQueues=[],c.autoJoinQueues=!1,c.queuePresenceData=[],c.queuePublishPresence=!1,c.queueFilter=null,c.init=function(a,d,e){b.debug("rtcommQueues: autoJoinQueues = "+a),c.autoJoinQueues=a,c.queuePublishPresence=d,"undefined"!=typeof e&&(c.queueFilter=e)},c.$on("queueupdate",function(a,d){b.debug("rtcommQueues: scope queues",c.rQueues),Object.keys(d).forEach(function(a){b.debug("rtcommQueues: Push queue: "+d[a]),b.debug("rtcommQueues: autoJoinQueues: "+c.autoJoinQueues),0==c.filterOutQueue(d[a])&&(c.rQueues.push(d[a]),1==c.autoJoinQueues&&c.onQueueClick(d[a]))}),c.updateQueuePresence()}),c.$on("rtcomm::init",function(a,d,e){0==d&&(b.debug("rtcommQueues: init: clear queues"),c.rQueues=[])}),c.filterOutQueue=function(a){var b=!0;if(null!=c.queueFilter)for(var d=0;d0?(d.bind("scroll",function(){d.prop("scrollTop")+d.prop("clientHeight")==d.prop("scrollHeight")?a.scrollToBottom(!0):a.scrollToBottom(!1)}),a.$watch("chats",function(){e&&d.scrollTop(d.prop("scrollHeight"))},!0)):b.warn("chatPanel not found: most likely you need to load jquery prior to angular")}}}function h(a,b,c,d,e){return{restrict:"E",templateUrl:"templates/rtcomm/rtcomm-iframe.html",controller:["$scope",function(f){f.iframeActiveEndpointUUID=a.getActiveEndpoint(),f.iframeURL=null,f.initiframeURL=null,f.syncSource=!1,f.init=function(a){1==a&&(f.syncSource=!0,f.initiframeURL=d.absUrl())},f.$on("session:started",function(c,d){b.debug("session:started received: endpointID = "+d.endpoint.id),1==f.syncSource&&a.putIframeURL(d.endpoint.id,f.initiframeURL)}),f.$on("endpointActivated",function(d,e){b.debug("rtcommIframe: endpointActivated ="+e),0==f.syncSource&&(f.iframeURL=c.trustAsResourceUrl(a.getIframeURL(e)),f.iframeActiveEndpointUUID=e)}),f.$on("noEndpointActivated",function(a){0==f.syncSource&&(f.iframeURL=c.trustAsResourceUrl("about:blank"),f.iframeActiveEndpointUUID=null)}),f.$on("rtcomm::iframeUpdate",function(a,d,g){0==f.syncSource?(b.debug("rtcomm::iframeUpdate: "+g),g+="?disableRtcomm=true",f.iframeURL=c.trustAsResourceUrl(g)):(b.debug("rtcomm::iframeUpdate: load this url in a new tab: "+g),e.open(c.trustAsResourceUrl(g),"_blank"))}),f.setURL=function(d){b.debug("rtcommIframe: setURL: newURL: "+d),a.putIframeURL(f.iframeActiveEndpointUUID,d),f.iframeURL=c.trustAsResourceUrl(d)},f.forward=function(){},f.backward=function(){}}],controllerAs:"rtcommiframe"}}function i(a,b,c,d,e){b.alertingEndpointUUID=null,b.autoAnswerNewMedia=!1,b.alertActiveEndpointUUID=c.getActiveEndpoint(),b.caller=null,b.init=function(a){e.debug("rtcommAlert: autoAnswerNewMedia = "+a),b.autoAnswerNewMedia=a},b.$on("endpointActivated",function(a,c){b.alertActiveEndpointUUID=c}),b.$on("session:alerting",function(a,c){b.alertActiveEndpointUUID==c.endpoint.id&&0==b.autoAnswerNewMedia||b.alertActiveEndpointUUID!=c.endpoint.id?(e.debug("rtcommAlert: display alterting model: alertActiveEndpointUUID = "+c.endpoint+" autoAnswerNewMedia = "+b.autoAnswerNewMedia),b.caller=c.endpoint.getRemoteEndpointID(),b.alertingEndpointUUID=c.endpoint.id,b.showAlerting()):(e.debug("Accepting media from: "+c.endpoint.getRemoteEndpointID()+" for endpoint: "+c.endpoint.id),c.endpoint.accept())}),b.showAlerting=function(f){var g=d.open({templateUrl:"templates/rtcomm/rtcomm-modal-alert.html",controller:"RtcommAlertModalInstanceController",size:f,backdrop:"static",resolve:{caller:function(){return b.caller}}});g.result.then(function(){var d=c.getEndpoint(b.alertingEndpointUUID);d&&(e.debug("Accepting call from: "+b.caller+" for endpoint: "+b.alertingEndpointUUID),d.accept(),a.$broadcast("rtcomm::alert-success"),d=null)},function(){var a=c.getEndpoint(b.alertingEndpointUUID);a&&(e.debug("Rejecting call from: "+b.caller+" for endpoint: "+b.alertingEndpointUUID),a.reject(),a=null)})}}function j(a,b,c,d){a.caller=d,a.ok=function(){c.debug("Accepting alerting call"),b.close()},a.cancel=function(){c.debug("Rejecting alerting call"),b.dismiss("cancel")}}function k(a,b,c,d){a.calleeID=null,a.callerID=null,a.enableCallModel=!1,a.mediaToEnable=["chat"],a.init=function(b,c){a.calleeID=b,"undefined"!=typeof c&&(a.mediaToEnable=c)},a.$on("rtcomm::init",function(b,c,e){d.debug("RtcommCallModalController: rtcomm::init: success = "+c),1==c?a.enableCallModel=!0:a.enableCallModel=!1}),a.$on("session:started",function(b,c){a.enableCallModel=!1}),a.$on("session:stopped",function(b,c){a.enableCallModel=!0}),a.placeCall=function(e){var f=c.open({templateUrl:"templates/rtcomm/rtcomm-modal-call.html",controller:"RtcommCallModalInstanceController",size:e,resolve:{}});f.result.then(function(c){d.debug("rtcommCallModal: Calling calleeID: "+a.calleeID),d.debug("rtcommCallModal: CallerID: "+c),null==a.callerID&&"undefined"!=typeof c&&""!=c&&(a.callerID=c,b.setAlias(c)),b.placeCall(a.calleeID,a.mediaToEnable)},function(){d.info("Modal dismissed at: "+new Date)})}}function l(a,b,c){a.endpointAlias="",a.ok=function(){b.close(a.endpointAlias)},a.cancel=function(){b.dismiss("cancel")}}function m(a,b,c,d){a.extendedConfig=null,d.debug("RtcommConfigController: configURL = "+a.configURL),a.setConfig=function(a){d.debug("RtcommConfigController: setting config data:"+a),c.setConfig(a)},a.init=function(b,c){d.debug("RtcommConfigController: initing configURL = "+b),a.configURL=b,"undefined"!=typeof c&&(a.extendedConfig=c),a.getConfig()},a.getConfig=function(){b.get(a.configURL).success(function(b){null!=a.extendedConfig&&(angular.extend(b,a.extendedConfig),d.debug("RtcommConfigController: extended config object: "+b)),c.setConfig(b)}).error(function(a,b,c,e){d.debug("RtcommConfigController: error accessing config: "+b)})}}function n(a,b,c,d){a.avConnected=c.isWebrtcConnected(c.getActiveEndpoint()),a.init=function(a,b){c.setViewSelector(a,b);var d=c.getActiveEndpoint();"undefined"!=typeof d&&null!=d&&c.setVideoView(d)};var e=c.getActiveEndpoint();"undefined"!=typeof e&&null!=e&&c.setVideoView(e),a.$on("endpointActivated",function(b,e){d.debug("rtcommVideo: endpointActivated ="+e),c.setVideoView(e),a.avConnected=c.isWebrtcConnected(c.getActiveEndpoint())}),a.$on("noEndpointActivated",function(b){a.avConnected=!1}),a.$on("webrtc:connected",function(b,d){c.getActiveEndpoint()==d.endpoint.id&&(a.avConnected=!0)}),a.$on("webrtc:disconnected",function(b,d){c.getActiveEndpoint()==d.endpoint.id&&(a.avConnected=!1)})}function o(a,b,c,d,e){a.epCtrlActiveEndpointUUID=d.getActiveEndpoint(),a.epCtrlAVConnected=d.isWebrtcConnected(a.epCtrlActiveEndpointUUID),a.sessionState=d.getSessionState(a.epCtrlActiveEndpointUUID),a.disconnect=function(){e.debug("Disconnecting call for endpoint: "+a.epCtrlActiveEndpointUUID),d.getEndpoint(a.epCtrlActiveEndpointUUID).disconnect()},a.toggleAV=function(){e.debug("Enable AV for endpoint: "+a.epCtrlActiveEndpointUUID),0==a.epCtrlAVConnected?d.getEndpoint(a.epCtrlActiveEndpointUUID).webrtc.enable(function(a,b){a||(e.debug("Enable failed: ",b),d.alert({type:"danger",msg:b}))}):(e.debug("Disable AV for endpoint: "+a.epCtrlActiveEndpointUUID),d.getEndpoint(a.epCtrlActiveEndpointUUID).webrtc.disable())},a.$on("session:started",function(b,c){e.debug("session:started received: endpointID = "+c.endpoint.id),a.epCtrlActiveEndpointUUID==c.endpoint.id&&(a.sessionState="session:started")}),a.$on("session:stopped",function(b,c){e.debug("session:stopped received: endpointID = "+c.endpoint.id),a.epCtrlActiveEndpointUUID==c.endpoint.id&&(a.sessionState="session:stopped")}),a.$on("session:failed",function(b,c){e.debug("session:failed received: endpointID = "+c.endpoint.id),a.epCtrlActiveEndpointUUID==c.endpoint.id&&(a.sessionState="session:failed")}),a.$on("webrtc:connected",function(b,c){a.epCtrlActiveEndpointUUID==c.endpoint.id&&(a.epCtrlAVConnected=!0)}),a.$on("webrtc:disconnected",function(b,c){a.epCtrlActiveEndpointUUID==c.endpoint.id&&(a.epCtrlAVConnected=!1)}),a.$on("endpointActivated",function(b,c){a.epCtrlActiveEndpointUUID=c,a.epCtrlAVConnected=d.isWebrtcConnected(c)}),a.$on("noEndpointActivated",function(b){a.epCtrlAVConnected=!1})}angular.module("angular-rtcomm-ui",["ui.bootstrap","angular-rtcomm-service"]).directive("rtcommSessionManager",a).directive("rtcommRegister",b).directive("rtcommQueues",c).directive("rtcommAlert",d).directive("rtcommEndpointStatus",e).directive("rtcommVideo",f).directive("rtcommChat",g).directive("rtcommIframe",h).controller("RtcommAlertModalController",i).controller("RtcommAlertModalInstanceController",j).controller("RtcommCallModalController",k).controller("RtcommCallModalInstanceController",l).controller("RtcommConfigController",m).controller("RtcommVideoController",n).controller("RtcommEndpointController",o),a.$inject=["RtcommService","$log"],b.$inject=["RtcommService","$log"],c.$inject=["RtcommService","$log"],d.$inject=["$log"],e.$inject=["RtcommService","$log"],f.$inject=["RtcommService","$log"],g.$inject=["RtcommService","$log"],h.$inject=["RtcommService","$log","$sce","$location","$window"],i.$inject=["$rootScope","$scope","RtcommService","$modal","$log"],j.$inject=["$scope","$modalInstance","$log","caller"],k.$inject=["$scope","RtcommService","$modal","$log"],l.$inject=["$scope","$modalInstance","RtcommService"],m.$inject=["$scope","$http","RtcommService","$log"],n.$inject=["$scope","$http","RtcommService","$log"],o.$inject=["$scope","$rootScope","$http","RtcommService","$log"]}(),function(){function a(a,b){return{restrict:"E",templateUrl:"templates/rtcomm/rtcomm-presence.html",controller:["$scope","$rootScope",function(c,d){c.monitorTopics=[],c.presenceData=[],c.expandedNodes=[],c.protocolList={chat:!0,webrtc:!1},c.flatten=!1,c.treeOptions={nodeChildren:"nodes",dirSelectable:!0,injectClasses:{ul:"a1",li:"a2",liSelected:"a7",iExpanded:"a3",iCollapsed:"a4",iLeaf:"a5",label:"a6",labelSelected:"a8"}},c.init=function(a){c.protocolList.chat="boolean"==typeof a.chat?a.chat:c.protocolList.chat,c.protocolList.webrtc="boolean"==typeof a.webrtc?a.webrtc:c.protocolList.webrtc,c.flatten="boolean"==typeof a.flatten?a.flatten:c.flatten},c.onCallClick=function(b){var e=a.getEndpoint();a.setActiveEndpoint(e.id),1==c.protocolList.chat&&e.chat.enable(),1==c.protocolList.webrtc&&e.webrtc.enable(function(b,c){b||a.alert({type:"danger",msg:c})}),e.connect(b),d.$broadcast("rtcomm::presence-click")},c.$on("rtcomm::init",function(d,e,f){a.publishPresence();var g=a.getPresenceMonitor();g.on("updated",function(a){b.debug("<<------rtcommPresence: updated------>>"),c.flatten&&(b.debug("<<------rtcommPresence: updated using flattened data ------>>"),c.presenceData=a[0].flatten()),c.$apply()}),c.flatten||(c.presenceData=g.getPresenceData()),c.presenceData.length>=1&&c.expandedNodes.push(c.presenceData[0]);for(var h=0;h{{alert.msg}}'),a.put("templates/rtcomm/rtcomm-chat.html",'
Chat
  • {{chat.name}} {{chat.time | date:\'HH:mm:ss\'}}

    {{chat.message}}

'),a.put("templates/rtcomm/rtcomm-endpoint-status.html",'
'),a.put("templates/rtcomm/rtcomm-iframe.html",'
URL Sharing
'), 22 | a.put("templates/rtcomm/rtcomm-modal-alert.html",''),a.put("templates/rtcomm/rtcomm-modal-call.html",''),a.put("templates/rtcomm/rtcomm-queues.html",'
Queues
'),a.put("templates/rtcomm/rtcomm-register.html",'
'),a.put("templates/rtcomm/rtcomm-sessionmgr.html",'
'),a.put("templates/rtcomm/rtcomm-video.html",'
')}]),angular.module("angular-rtcomm-presence").run(["$templateCache",function(a){"use strict";a.put("templates/rtcomm/rtcomm-presence.html",'
{{node.name}} {{node.value ? \': \' + node.value : \'\'}}
')}]); -------------------------------------------------------------------------------- /dist/css/angular-rtcomm.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 IBM Corp. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Video window related css */ 18 | #videoContainer { 19 | position: relative; 20 | left:0; 21 | right:0; 22 | top:0; 23 | bottom:0; 24 | background-color: #fff; 25 | } 26 | 27 | /* ID dictates the style */ 28 | #selfViewContainer { 29 | position:absolute; 30 | top: 3%; 31 | left: 70%; 32 | width: 20%; 33 | height:20%; 34 | padding:0px; 35 | z-index: 5; 36 | } 37 | 38 | /* Class dictates the style */ 39 | .selfView { 40 | width: 100%; 41 | height: 100%; 42 | } 43 | 44 | /* Class dictates the style */ 45 | .remoteView { 46 | min-width: 160px; 47 | min-height: 120px; 48 | max-height: 100%; 49 | width:100%; 50 | z-index: 1; 51 | } 52 | 53 | /* Chat related css */ 54 | .chat 55 | { 56 | list-style: none; 57 | margin: 0; 58 | padding: 0; 59 | } 60 | 61 | .chat li 62 | { 63 | margin-bottom: 10px; 64 | padding-bottom: 5px; 65 | border-bottom: 1px dotted #B3A9A9; 66 | } 67 | 68 | .chat li .chat-body p 69 | { 70 | margin: 0; 71 | color: #777777; 72 | } 73 | 74 | /*.slidedown .glyphicon, .chat .glyphicon*/ 75 | 76 | .panel 77 | { 78 | /*margin-right: 1px;*/ 79 | height: 100%; 80 | } 81 | 82 | .panel-body 83 | { 84 | overflow-y: scroll; 85 | height: 300px; 86 | background-color: white; 87 | margin: 5px; 88 | } 89 | 90 | .panel-footer 91 | { 92 | margin: 5px; 93 | } 94 | 95 | ::-webkit-scrollbar-track 96 | { 97 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 98 | background-color: #F5F5F5; 99 | } 100 | 101 | ::-webkit-scrollbar 102 | { 103 | width: 12px; 104 | background-color: #F5F5F5; 105 | } 106 | 107 | ::-webkit-scrollbar-thumb 108 | { 109 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3); 110 | background-color: #555; 111 | } 112 | 113 | .endpoint-status { 114 | width: 100%; 115 | height: 50px; 116 | z-index: 5; 117 | background: #aaa; 118 | color: white; 119 | border-radius: 4px; 120 | border: 1px solid #428bca; 121 | padding-top: 2px; 122 | padding-bottom: 2px; 123 | } 124 | 125 | .session-manager { 126 | width: 100%; 127 | height: 50px; 128 | z-index: 5; 129 | background: #aaa; 130 | color: white; 131 | border-radius: 4px; 132 | border: 1px solid #428bca; 133 | } 134 | 135 | .session-manager-buttom { 136 | padding-left: 2px; 137 | } 138 | 139 | 140 | .session-mgr-container{ 141 | border: 1px solid black; 142 | padding: 5px; 143 | border-radius: 4px; 144 | } 145 | 146 | .queueContainer { 147 | padding-top: 2px; 148 | padding-bottom: 2px; 149 | padding-left: 2px; 150 | padding-right: 2px; 151 | } 152 | 153 | .nopadding-left { 154 | padding-left: 0 !important; 155 | margin-left: 0 !important; 156 | } 157 | 158 | .nopadding-right { 159 | padding-right: 0 !important; 160 | margin-right: 0 !important; 161 | } 162 | 163 | .vertical-stretch 164 | { 165 | top: 0; 166 | bottom: 0; 167 | } 168 | 169 | .rtcomm-iframe 170 | { 171 | overflow: scroll; 172 | width: 100%; 173 | height: 700px; 174 | } 175 | -------------------------------------------------------------------------------- /dist/css/angular-rtcomm.min.css: -------------------------------------------------------------------------------- 1 | #videoContainer{position:relative;left:0;right:0;top:0;bottom:0;background-color:#fff}#selfViewContainer{position:absolute;top:3%;left:70%;width:20%;height:20%;padding:0;z-index:5}.selfView{width:100%;height:100%}.remoteView{min-width:160px;min-height:120px;max-height:100%;width:100%;z-index:1}.chat{list-style:none;margin:0;padding:0}.chat li{margin-bottom:10px;padding-bottom:5px;border-bottom:1px dotted #B3A9A9}.chat li .chat-body p{margin:0;color:#777}.panel{height:100%}.panel-body{overflow-y:scroll;height:300px;background-color:#fff;margin:5px}.panel-footer{margin:5px}::-webkit-scrollbar-track{-webkit-box-shadow:inset 0 0 6px rgba(0,0,0,.3);background-color:#F5F5F5}::-webkit-scrollbar{width:12px;background-color:#F5F5F5}::-webkit-scrollbar-thumb{-webkit-box-shadow:inset 0 0 6px rgba(0,0,0,.3);background-color:#555}.endpoint-status{width:100%;height:50px;z-index:5;background:#aaa;color:#fff;border-radius:4px;border:1px solid #428bca;padding-top:2px;padding-bottom:2px}.session-manager{width:100%;height:50px;z-index:5;background:#aaa;color:#fff;border-radius:4px;border:1px solid #428bca}.session-manager-buttom{padding-left:2px}.session-mgr-container{border:1px solid #000;padding:5px;border-radius:4px}.queueContainer{padding:2px}.nopadding-left{padding-left:0!important;margin-left:0!important}.nopadding-right{padding-right:0!important;margin-right:0!important}.vertical-stretch{top:0;bottom:0}.rtcomm-iframe{overflow:scroll;width:100%;height:700px} -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | // Generated on Fri Dec 05 2014 13:58:19 GMT-0500 (Eastern Standard Time) 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | 7 | // base path that will be used to resolve all patterns (eg. files, exclude) 8 | basePath: '', 9 | 10 | // frameworks to use 11 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 12 | frameworks: ['jasmine', 'mocha', 'chai'], 13 | 14 | // list of files / patterns to load in the browser 15 | files: [ 16 | 'node_modules/angular/angular.js', 17 | 'node_modules/angular-mocks/angular-mocks.js', 18 | 'bower_components/jquery/dist/jquery.js', 19 | 'bower_components/angular-bootstrap/ui-bootstrap-tpls.js', 20 | 'bower_components/angular-modal-service/dst/angular-modal-service.js', 21 | 'bower_components/angular-tree-control/angular-tree-control.js', 22 | 'bower_components/bower-mqttws/mqttws31.js', 23 | 'bower_components/rtcomm/dist/rtcomm.js', 24 | 'src/js/rtcomm-services.js', 25 | 'src/js/rtcomm-directives.js', 26 | 'test/*Spec.js' 27 | ], 28 | 29 | 30 | // list of files to exclude 31 | exclude: [ 32 | ], 33 | 34 | 35 | // preprocess matching files before serving them to the browser 36 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 37 | preprocessors: { 38 | 'src/templates/*.html': 'ng-html2js' 39 | }, 40 | 41 | 42 | // test results reporter to use 43 | // possible values: 'dots', 'progress' 44 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 45 | reporters: ['progress'], 46 | 47 | 48 | // web server port 49 | port: 9876, 50 | 51 | 52 | // enable / disable colors in the output (reporters and logs) 53 | colors: true, 54 | 55 | 56 | // level of logging 57 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 58 | logLevel: config.LOG_DEBUG, 59 | 60 | 61 | // enable / disable watching file and executing tests whenever any file changes 62 | autoWatch: false, 63 | 64 | 65 | // start these browsers 66 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 67 | //browsers: ['Chrome', 'Firefox'], 68 | browsers: ['Chrome'], 69 | 70 | 71 | // Continuous Integration mode 72 | // if true, Karma captures browsers, runs the tests and exits 73 | singleRun: true 74 | }); 75 | }; 76 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-rtcomm", 3 | "version": "1.0.3", 4 | "description": "Angular module for Rtcomm", 5 | "main": "Gruntfile.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/WASdev/lib.angular-rtcomm" 12 | }, 13 | "keywords": [ 14 | "WebRTC", 15 | "Rtcomm" 16 | ], 17 | "author": "Brian Pulito (https://github.com/bpulito)", 18 | "license": "Apache", 19 | "bugs": { 20 | "url": "https://github.com/WASdev/lib.angular-rtcomm/issues" 21 | }, 22 | "homepage": "https://github.com/WASdev/lib.angular-rtcomm", 23 | "devDependencies": { 24 | "angular": "^1.3.5", 25 | "angular-mocks": "^1.3.5", 26 | "chai": "^1.10.0", 27 | "grunt": "^0.4.5", 28 | "grunt-angular-templates": "^0.5.7", 29 | "grunt-contrib-concat": "^0.5.0", 30 | "grunt-contrib-copy": "^0.7.0", 31 | "grunt-contrib-cssmin": "^0.10.0", 32 | "grunt-contrib-jshint": "^0.10.0", 33 | "grunt-contrib-uglify": "^0.6.0", 34 | "grunt-contrib-watch": "^0.6.1", 35 | "grunt-karma": "^0.9.0", 36 | "grunt-ng-annotate": "^0.8.0", 37 | "grunt-serve": "^0.1.6", 38 | "karma": "^0.12.28", 39 | "karma-chai": "^0.1.0", 40 | "karma-chrome-launcher": "^0.1.7", 41 | "karma-firefox-launcher": "^0.1.3", 42 | "karma-ie-launcher": "^0.1.5", 43 | "karma-jasmine": "^0.3.2", 44 | "karma-mocha": "^0.1.10", 45 | "karma-ng-html2js-preprocessor": "^0.1.2", 46 | "load-grunt-tasks": "^1.0.0", 47 | "mocha": "^2.0.1" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/css/angular-rtcomm.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 IBM Corp. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Video window related css */ 18 | #videoContainer { 19 | position: relative; 20 | left:0; 21 | right:0; 22 | top:0; 23 | bottom:0; 24 | background-color: #fff; 25 | } 26 | 27 | /* ID dictates the style */ 28 | #selfViewContainer { 29 | position:absolute; 30 | top: 3%; 31 | left: 70%; 32 | width: 20%; 33 | height:20%; 34 | padding:0px; 35 | z-index: 5; 36 | } 37 | 38 | /* Class dictates the style */ 39 | .selfView { 40 | width: 100%; 41 | height: 100%; 42 | } 43 | 44 | /* Class dictates the style */ 45 | .remoteView { 46 | min-width: 160px; 47 | min-height: 120px; 48 | max-height: 100%; 49 | width:100%; 50 | z-index: 1; 51 | } 52 | 53 | /* Chat related css */ 54 | .chat 55 | { 56 | list-style: none; 57 | margin: 0; 58 | padding: 0; 59 | } 60 | 61 | .chat li 62 | { 63 | margin-bottom: 10px; 64 | padding-bottom: 5px; 65 | border-bottom: 1px dotted #B3A9A9; 66 | } 67 | 68 | .chat li .chat-body p 69 | { 70 | margin: 0; 71 | color: #777777; 72 | } 73 | 74 | /*.slidedown .glyphicon, .chat .glyphicon*/ 75 | 76 | .panel 77 | { 78 | /*margin-right: 1px;*/ 79 | height: 100%; 80 | } 81 | 82 | .panel-body 83 | { 84 | overflow-y: scroll; 85 | height: 300px; 86 | background-color: white; 87 | margin: 5px; 88 | } 89 | 90 | .panel-footer 91 | { 92 | margin: 5px; 93 | } 94 | 95 | ::-webkit-scrollbar-track 96 | { 97 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); 98 | background-color: #F5F5F5; 99 | } 100 | 101 | ::-webkit-scrollbar 102 | { 103 | width: 12px; 104 | background-color: #F5F5F5; 105 | } 106 | 107 | ::-webkit-scrollbar-thumb 108 | { 109 | -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3); 110 | background-color: #555; 111 | } 112 | 113 | .endpoint-status { 114 | width: 100%; 115 | height: 50px; 116 | z-index: 5; 117 | background: #aaa; 118 | color: white; 119 | border-radius: 4px; 120 | border: 1px solid #428bca; 121 | padding-top: 2px; 122 | padding-bottom: 2px; 123 | } 124 | 125 | .session-manager { 126 | width: 100%; 127 | height: 50px; 128 | z-index: 5; 129 | background: #aaa; 130 | color: white; 131 | border-radius: 4px; 132 | border: 1px solid #428bca; 133 | } 134 | 135 | .session-manager-buttom { 136 | padding-left: 2px; 137 | } 138 | 139 | 140 | .session-mgr-container{ 141 | border: 1px solid black; 142 | padding: 5px; 143 | border-radius: 4px; 144 | } 145 | 146 | .queueContainer { 147 | padding-top: 2px; 148 | padding-bottom: 2px; 149 | padding-left: 2px; 150 | padding-right: 2px; 151 | } 152 | 153 | .nopadding-left { 154 | padding-left: 0 !important; 155 | margin-left: 0 !important; 156 | } 157 | 158 | .nopadding-right { 159 | padding-right: 0 !important; 160 | margin-right: 0 !important; 161 | } 162 | 163 | .vertical-stretch 164 | { 165 | top: 0; 166 | bottom: 0; 167 | } 168 | 169 | .rtcomm-iframe 170 | { 171 | overflow: scroll; 172 | width: 100%; 173 | height: 700px; 174 | } 175 | -------------------------------------------------------------------------------- /src/js/angular-rtcomm.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This is the main angular-rtcomm module. 3 | */ 4 | (function() { 5 | angular.module('angular-rtcomm', [ 6 | 'ui.bootstrap', 7 | 'treeControl', 8 | 'angular-rtcomm-ui', 9 | 'angular-rtcomm-presence', 10 | 'angular-rtcomm-service' 11 | ]); 12 | })(); 13 | -------------------------------------------------------------------------------- /src/js/rtcomm-directives.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The angular-rtcomm-ui module 3 | * This has controllers and directives in it. 4 | */ 5 | (function(){ 6 | 7 | angular 8 | .module('angular-rtcomm-ui', [ 9 | 'ui.bootstrap', 10 | 'angular-rtcomm-service']) 11 | .directive('rtcommSessionManager', rtcommSessionManager) 12 | .directive('rtcommRegister', rtcommRegister) 13 | .directive('rtcommQueues', rtcommQueues) 14 | .directive('rtcommAlert', rtcommAlert) 15 | .directive('rtcommEndpointStatus', rtcommEndpointStatus) 16 | .directive('rtcommVideo', rtcommVideo) 17 | .directive('rtcommChat', rtcommChat) 18 | .directive('rtcommIframe', rtcommIframe) 19 | .controller('RtcommAlertModalController', RtcommAlertModalController) 20 | .controller('RtcommAlertModalInstanceController', RtcommAlertModalInstanceController) 21 | .controller('RtcommCallModalController', RtcommCallModalController) 22 | .controller('RtcommCallModalInstanceController', RtcommCallModalInstanceController) 23 | .controller('RtcommConfigController', RtcommConfigController) 24 | .controller('RtcommVideoController', RtcommVideoController) 25 | .controller('RtcommEndpointController', RtcommEndpointController); 26 | 27 | /************* Endpoint Provider Directives *******************************/ 28 | /** 29 | * This directive is used to manage multiple sessions. If you are only supporting at most one session you wont need 30 | * this directive. The associated template provides a way to switch between active sessions. The session must be in 31 | * the started state to be managed by this directive and is removed when the session stops. 32 | */ 33 | 34 | rtcommSessionManager.$inject=['RtcommService', '$log']; 35 | function rtcommSessionManager (RtcommService, $log) { 36 | return { 37 | restrict: 'E', 38 | templateUrl: 'templates/rtcomm/rtcomm-sessionmgr.html', 39 | controller: function ($scope) { 40 | $scope.sessions = RtcommService.getSessions(); 41 | $scope.sessMgrActiveEndpointUUID = RtcommService.getActiveEndpoint(); 42 | $scope.publishPresence = false; 43 | $scope.sessionPresenceData = []; 44 | 45 | $scope.init = function(publishPresence) { 46 | $scope.publishPresence = publishPresence; 47 | $scope.updatePresence(); 48 | }; 49 | 50 | $scope.$on('endpointActivated', function (event, endpointUUID) { 51 | $log.debug('rtcommSessionmgr: endpointActivated =' + endpointUUID); 52 | $scope.sessMgrActiveEndpointUUID = endpointUUID; 53 | }); 54 | 55 | $scope.$on('session:started', function (event, eventObject) { 56 | $log.debug('rtcommSessionmgr: session:started: uuid =' + eventObject.endpoint.id); 57 | 58 | $scope.updatePresence(); 59 | }); 60 | 61 | $scope.activateSession = function(endpointUUID) { 62 | $log.debug('rtcommSessionmgr: activateEndpoint =' + endpointUUID); 63 | if ($scope.sessMgrActiveEndpointUUID != endpointUUID){ 64 | RtcommService.setActiveEndpoint(endpointUUID); 65 | } 66 | }; 67 | 68 | $scope.updatePresence = function(){ 69 | // Update the presence record if enabled 70 | if ($scope.publishPresence == true){ 71 | RtcommService.removeFromPresenceRecord ($scope.sessionPresenceData, false); 72 | 73 | $scope.sessionPresenceData = [{ 74 | 'name' : "sessions", 75 | 'value' : String($scope.sessions.length)}]; 76 | 77 | RtcommService.addToPresenceRecord ($scope.sessionPresenceData); 78 | } 79 | }; 80 | 81 | }, 82 | controllerAs: 'sessionmgr' 83 | }; 84 | }; 85 | 86 | /** 87 | * This directive is used to manage the registration of an endpoint provider. Since the registered name can only 88 | * be set on initialization of the endpoint provider, this directive actually controls the initialization of the 89 | * provider. Note that the endpoint provider must be initialized before any sessions can be created or received. 90 | */ 91 | rtcommRegister.$inject=['RtcommService', '$log']; 92 | function rtcommRegister(RtcommService, $log) { 93 | return { 94 | restrict: 'E', 95 | templateUrl: 'templates/rtcomm/rtcomm-register.html', 96 | controller: function ($scope) { 97 | 98 | $scope.nextAction = 'Register'; 99 | 100 | $scope.reguserid = ''; 101 | 102 | $scope.invalid = false; 103 | 104 | var invalidCharacters = /(\$|#|\+|\/|\\)+/i; //Invalid characters for MQTT Topic Path 105 | 106 | //Watch for changes in reguserid 107 | $scope.$watch('reguserid', function(){ 108 | 109 | if($scope.reguserid.length < 1 || invalidCharacters.test($scope.reguserid)){ 110 | 111 | $scope.invalid = true; 112 | } 113 | else{ 114 | $scope.invalid = false; 115 | } 116 | }); 117 | 118 | 119 | $scope.onRegClick = function() { 120 | if ($scope.nextAction === 'Register' && !invalidCharacters.test($scope.reguserid)){ 121 | 122 | $log.debug('Register: reguserid =' + $scope.reguserid); 123 | RtcommService.register($scope.reguserid); 124 | } 125 | else { 126 | $log.debug('Unregister: reguserid =' + $scope.reguserid); 127 | RtcommService.unregister(); 128 | } 129 | }; 130 | 131 | $scope.$on('rtcomm::init', function (event, success, details) { 132 | 133 | if (success == true){ 134 | $scope.nextAction = 'Unregister'; 135 | $scope.reguserid = details.userid; 136 | } 137 | else{ 138 | $scope.nextAction = 'Register'; 139 | 140 | if (details == 'destroyed') 141 | $scope.reguserid = ''; 142 | else 143 | $scope.reguserid = 'Init failed:' + details; 144 | } 145 | }); 146 | }, 147 | controllerAs: 'register' 148 | }; 149 | }; 150 | 151 | /** 152 | * This directive manages call queues. It provides the ability to display all the available queues 153 | * (along with their descriptions) and by clicking on a queue, allows an agent (or any type of user) 154 | * to subscribe on that queue. 155 | */ 156 | rtcommQueues.$inject = ['RtcommService', '$log']; 157 | function rtcommQueues(RtcommService, $log) { 158 | return { 159 | restrict : 'E', 160 | templateUrl : 'templates/rtcomm/rtcomm-queues.html', 161 | controller : function($scope) { 162 | $scope.rQueues = []; 163 | $scope.autoJoinQueues = false; 164 | $scope.queuePresenceData = []; 165 | $scope.queuePublishPresence = false; 166 | $scope.queueFilter = null; 167 | 168 | /** 169 | * autoJoinQueues - automatically join any queues that are not filtered out 170 | * queuePublishedPresence - will add to the presence document information about what queues this person joins. 171 | * queueFilter - If defined, this specifies which queues should be joined. All others will be ignored. 172 | */ 173 | $scope.init = function(autoJoinQueues, queuePublishPresence, queueFilter) { 174 | $log.debug('rtcommQueues: autoJoinQueues = ' + autoJoinQueues); 175 | $scope.autoJoinQueues = autoJoinQueues; 176 | $scope.queuePublishPresence = queuePublishPresence; 177 | 178 | if (typeof queueFilter !== "undefined") 179 | $scope.queueFilter = queueFilter; 180 | }; 181 | 182 | $scope.$on('queueupdate', function(event, queues) { 183 | $log.debug('rtcommQueues: scope queues', $scope.rQueues); 184 | 185 | Object.keys(queues).forEach(function(key) { 186 | $log.debug('rtcommQueues: Push queue: ' + queues[key]); 187 | $log.debug('rtcommQueues: autoJoinQueues: ' + $scope.autoJoinQueues); 188 | 189 | // Check to make sure queue is not filteres out before adding it. 190 | if ($scope.filterOutQueue(queues[key]) == false){ 191 | $scope.rQueues.push(queues[key]); 192 | 193 | // If autoJoin we go ahead and join the queue as soon as we get the queue update. 194 | if ($scope.autoJoinQueues == true){ 195 | $scope.onQueueClick(queues[key]); 196 | } 197 | } 198 | }); 199 | 200 | $scope.updateQueuePresence(); 201 | }); 202 | 203 | $scope.$on('rtcomm::init', function (event, success, details) { 204 | if (success == false){ 205 | $log.debug('rtcommQueues: init: clear queues'); 206 | $scope.rQueues = []; 207 | } 208 | }); 209 | 210 | // 211 | $scope.filterOutQueue = function(queue){ 212 | var returnValue = true; 213 | 214 | if ($scope.queueFilter != null){ 215 | 216 | for (var index = 0; index < $scope.queueFilter.length; ++index) { 217 | var entry = $scope.queueFilter[index]; 218 | if (entry == queue.endpointID) { 219 | returnValue = false; 220 | break; 221 | } 222 | } 223 | } 224 | else 225 | returnValue = false; 226 | 227 | return (returnValue); 228 | }; 229 | 230 | $scope.onQueueClick = function(queue){ 231 | $log.debug('rtcommQueues: onClick: TOP'); 232 | for (var index = 0; index < $scope.rQueues.length; index++) { 233 | if($scope.rQueues[index].endpointID === queue.endpointID) 234 | { 235 | $log.debug('rtcommQueues: onClick: queue.endpointID = ' + queue.endpointID); 236 | 237 | if (queue.active == false){ 238 | RtcommService.joinQueue(queue.endpointID); 239 | $scope.rQueues[index].active = true; 240 | } 241 | else{ 242 | RtcommService.leaveQueue(queue.endpointID); 243 | $scope.rQueues[index].active = false; 244 | } 245 | } 246 | else if (index == ($scope.rQueues.length - 1)){ 247 | $log.debug('rtcommQueues: ERROR: queue.endpointID: ' + queue.endpointID + ' not found in list of queues'); 248 | 249 | } 250 | } 251 | 252 | $scope.updateQueuePresence(); 253 | }; 254 | 255 | $scope.updateQueuePresence = function(){ 256 | // Update the presence record if enabled 257 | if ($scope.queuePublishPresence == true){ 258 | RtcommService.removeFromPresenceRecord ($scope.queuePresenceData, false); 259 | 260 | $scope.queuePresenceData = []; 261 | 262 | for (var index = 0; index < $scope.rQueues.length; index++) { 263 | if($scope.rQueues[index].active === true){ 264 | $scope.queuePresenceData.push ( 265 | { 266 | 'name' : "queue", 267 | 'value' : $scope.rQueues[index].endpointID 268 | }); 269 | } 270 | } 271 | 272 | RtcommService.addToPresenceRecord ($scope.queuePresenceData); 273 | } 274 | }; 275 | }, 276 | controllerAs : 'queues' 277 | }; 278 | }; 279 | 280 | //rtcommModule.controller('RtcommAlertController', ['$scope', '$log', function($scope, $log){ 281 | rtcommAlert.$inject = ['$log']; 282 | function rtcommAlert($log) { 283 | return { 284 | restrict: 'E', 285 | templateUrl: "templates/rtcomm/rtcomm-alert.html", 286 | controller: function ($scope) { 287 | $scope.alerts = []; 288 | $scope.addAlert = function(alert) { 289 | $scope.alerts.push(alert); 290 | }; 291 | $scope.closeAlert = function(index) { 292 | $scope.alerts.splice(index, 1); 293 | }; 294 | $scope.$on('rtcomm::alert', function(event, eventObject) { 295 | $scope.addAlert(eventObject); 296 | }); 297 | } 298 | } 299 | }; 300 | 301 | /********************** Endpoint Directives *******************************/ 302 | 303 | /** 304 | * This endpoint status controller only shows the active endpoint. The $scope.sessionState always contains the 305 | * state of the active endpoint if one exist. It will be one of the following states: 306 | * 307 | * 'session:alerting' 308 | * 'session:trying' 309 | * 'session:ringing' 310 | * 'session:queued' - for this one $scope.queueCount will tell you where you are in the queue. 311 | * 'session:failed' - for this one $scope.reason will tell you why the call failed. 312 | * 'session:started' 313 | * 'session:stopped' 314 | * 315 | * You can bind to $scope.sessionState to track state in the view. 316 | */ 317 | rtcommEndpointStatus.$inject = ['RtcommService', '$log']; 318 | function rtcommEndpointStatus(RtcommService, $log){ 319 | return { 320 | restrict: 'E', 321 | templateUrl: 'templates/rtcomm/rtcomm-endpoint-status.html', 322 | controller: function ($scope) { 323 | 324 | // Session states. 325 | $scope.epCtrlActiveEndpointUUID = RtcommService.getActiveEndpoint(); 326 | $scope.epCtrlRemoteEndpointID = RtcommService.getRemoteEndpoint($scope.epCtrlActiveEndpointUUID); 327 | $scope.sessionState = RtcommService.getSessionState($scope.epCtrlActiveEndpointUUID); 328 | $scope.failureReason = ''; 329 | $scope.queueCount = 0; // FIX: Currently not implemented! 330 | 331 | $scope.$on('session:started', function (event, eventObject) { 332 | $log.debug('session:started received: endpointID = ' + eventObject.endpoint.id); 333 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 334 | $scope.sessionState = 'session:started'; 335 | $scope.epCtrlRemoteEndpointID = eventObject.endpoint.getRemoteEndpointID(); 336 | } 337 | }); 338 | 339 | $scope.$on('session:stopped', function (event, eventObject) { 340 | $log.debug('session:stopped received: endpointID = ' + eventObject.endpoint.id); 341 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 342 | $scope.sessionState = 'session:stopped'; 343 | $scope.epCtrlRemoteEndpointID = null; 344 | } 345 | }); 346 | 347 | $scope.$on('session:failed', function (event, eventObject) { 348 | $log.debug('session:failed received: endpointID = ' + eventObject.endpoint.id); 349 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 350 | $scope.sessionState = 'session:failed'; 351 | $scope.failureReason = eventObject.reason; 352 | $scope.epCtrlRemoteEndpointID = eventObject.endpoint.getRemoteEndpointID(); 353 | } 354 | }); 355 | 356 | $scope.$on('session:alerting', function (event, eventObject) { 357 | $log.debug('session:alerting received: endpointID = ' + eventObject.endpoint.id); 358 | if ($scope.epCtrlActiveEndpointUUID != eventObject.endpoint.id){ 359 | $scope.sessionState = 'session:alerting'; 360 | $scope.epCtrlRemoteEndpointID = eventObject.endpoint.getRemoteEndpointID(); 361 | } 362 | }); 363 | 364 | $scope.$on('session:queued', function (event, eventObject) { 365 | $log.debug('session:queued received: endpointID = ' + eventObject.endpoint.id); 366 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 367 | $scope.sessionState = 'session:queued'; 368 | $scope.epCtrlRemoteEndpointID = eventObject.endpoint.getRemoteEndpointID(); 369 | } 370 | }); 371 | 372 | $scope.$on('session:trying', function (event, eventObject) { 373 | $log.debug('session:trying received: endpointID = ' + eventObject.endpoint.id); 374 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 375 | $scope.sessionState = 'session:trying'; 376 | $scope.epCtrlRemoteEndpointID = eventObject.endpoint.getRemoteEndpointID(); 377 | } 378 | }); 379 | 380 | $scope.$on('session:ringing', function (event, eventObject) { 381 | $log.debug('session:ringing received: endpointID = ' + eventObject.endpoint.id); 382 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 383 | $scope.sessionState = 'session:ringing'; 384 | $scope.epCtrlRemoteEndpointID = eventObject.endpoint.getRemoteEndpointID(); 385 | } 386 | }); 387 | 388 | $scope.$on('endpointActivated', function (event, endpointUUID) { 389 | $scope.epCtrlActiveEndpointUUID = endpointUUID; 390 | $scope.epCtrlRemoteEndpointID = RtcommService.getEndpoint(endpointUUID).getRemoteEndpointID(); 391 | $scope.sessionState = RtcommService.getSessionState(endpointUUID); 392 | }); 393 | 394 | $scope.$on('noEndpointActivated', function (event) { 395 | $scope.epCtrlRemoteEndpointID = null; 396 | $scope.sessionState = 'session:stopped'; 397 | }); 398 | 399 | $scope.$on('rtcomm::init', function(event, success, details){ 400 | 401 | if(success == false){ 402 | $scope.sessionState = 'session:stopped'; 403 | $scope.epCtrlRemoteEndpointID = null; 404 | } 405 | }); 406 | 407 | 408 | 409 | } 410 | }; 411 | }; 412 | 413 | /** 414 | * This directive manages the WebRTC video screen, including both the self view and the remote view. It 415 | * also takes care of switching state between endpoints based on which endpoint is "actively" being viewed. 416 | */ 417 | rtcommVideo.$inject = ['RtcommService', '$log']; 418 | function rtcommVideo(RtcommService, $log) { 419 | return { 420 | restrict: 'E', 421 | templateUrl: 'templates/rtcomm/rtcomm-video.html', 422 | controller: 'RtcommVideoController' 423 | }; 424 | }; 425 | 426 | /** 427 | * This directive manages the chat portion of a session. The data model for chat 428 | * is maintained in the RtcommService. This directive handles switching between 429 | * active endpoints. 430 | */ 431 | rtcommChat.$inject = ['RtcommService', '$log']; 432 | function rtcommChat(RtcommService, $log) { 433 | return { 434 | restrict: 'E', 435 | templateUrl: "templates/rtcomm/rtcomm-chat.html", 436 | controller: function ($scope) { 437 | $scope.chatActiveEndpointUUID = RtcommService.getActiveEndpoint(); 438 | $scope.chats = RtcommService.getChats($scope.chatActiveEndpointUUID); 439 | // This forces the scroll bar to the bottom and watches the $location.hash 440 | //$anchorScroll(); 441 | 442 | $scope.$on('endpointActivated', function (event, endpointUUID) { 443 | $log.debug('rtcommChat: endpointActivated =' + endpointUUID); 444 | 445 | // The data model for the chat is maintained in the RtcommService. 446 | $scope.chats = RtcommService.getChats(endpointUUID); 447 | $scope.chatActiveEndpointUUID = endpointUUID; 448 | }); 449 | 450 | $scope.$on('noEndpointActivated', function (event) { 451 | $scope.chats = []; 452 | $scope.chatActiveEndpointUUID = null; 453 | }); 454 | 455 | $scope.keySendMessage = function(keyEvent){ 456 | if (keyEvent.which === 13) 457 | $scope.sendMessage(); 458 | }; 459 | 460 | $scope.sendMessage = function() { 461 | var chat = { 462 | time : new Date(), 463 | name : RtcommService.getEndpoint($scope.chatActiveEndpointUUID).getLocalEndpointID(), 464 | message : angular.copy($scope.message) 465 | }; 466 | 467 | $scope.message = ''; 468 | $scope.scrollToBottom(true); 469 | RtcommService.sendChatMessage(chat, $scope.chatActiveEndpointUUID); 470 | }; 471 | 472 | }, 473 | controllerAs: 'chat', 474 | link: function(scope, element){ 475 | var chatPanel = angular.element(element.find('.panel-body')[0]); 476 | 477 | var bottom = true; 478 | 479 | //Chooses if the scrollbar should be forced to the bottom on the next lifecycle 480 | scope.scrollToBottom = function(flag){ 481 | bottom = flag; 482 | } 483 | 484 | if (chatPanel.length > 0) { 485 | //Watch scroll events 486 | chatPanel.bind('scroll', function(){ 487 | if(chatPanel.prop('scrollTop') + chatPanel.prop('clientHeight') == chatPanel.prop('scrollHeight')){ 488 | scope.scrollToBottom(true); 489 | } 490 | else { 491 | scope.scrollToBottom(false); 492 | } 493 | }); 494 | //Watch the chat messages, if the scroll bar is in the bottom keep it on the bottom so the user can view incoming chat messages, else possibly send a notification and don't scroll down 495 | scope.$watch('chats', function(){ 496 | if(bottom){ 497 | chatPanel.scrollTop(chatPanel.prop('scrollHeight')); 498 | } 499 | else { 500 | //In this else, a notification could be sent 501 | } 502 | },true); 503 | } 504 | else { 505 | $log.warn('chatPanel not found: most likely you need to load jquery prior to angular'); 506 | } 507 | } 508 | }; 509 | 510 | }; 511 | 512 | /** 513 | * This directive manages the shared iFrame. 514 | */ 515 | rtcommIframe.$inject = ['RtcommService', '$log', '$sce', '$location', '$window']; 516 | function rtcommIframe(RtcommService, $log, $sce, $location, $window) { 517 | return { 518 | restrict: 'E', 519 | templateUrl: "templates/rtcomm/rtcomm-iframe.html", 520 | controller: ["$scope", function ($scope) { 521 | $scope.iframeActiveEndpointUUID = RtcommService.getActiveEndpoint(); 522 | $scope.iframeURL = null; 523 | $scope.initiframeURL = null; 524 | $scope.syncSource = false; 525 | 526 | /* 527 | * syncSourcing means you a providing the URL source but no UI. Typically used in 528 | * customer/agent scenarios. 529 | */ 530 | $scope.init = function(syncSource) { 531 | if (syncSource == true){ 532 | $scope.syncSource = true; 533 | $scope.initiframeURL = $location.absUrl(); // init to current URL 534 | } 535 | }; 536 | 537 | $scope.$on('session:started', function (event, eventObject) { 538 | $log.debug('session:started received: endpointID = ' + eventObject.endpoint.id); 539 | 540 | if ($scope.syncSource == true){ 541 | RtcommService.putIframeURL(eventObject.endpoint.id,$scope.initiframeURL); //Update on the current or next endpoint to be activated. 542 | } 543 | }); 544 | 545 | $scope.$on('endpointActivated', function (event, endpointUUID) { 546 | $log.debug('rtcommIframe: endpointActivated =' + endpointUUID); 547 | 548 | if ($scope.syncSource == false){ 549 | $scope.iframeURL = $sce.trustAsResourceUrl(RtcommService.getIframeURL(endpointUUID)); 550 | $scope.iframeActiveEndpointUUID = endpointUUID; 551 | } 552 | }); 553 | 554 | $scope.$on('noEndpointActivated', function (event) { 555 | if ($scope.syncSource == false){ 556 | $scope.iframeURL = $sce.trustAsResourceUrl('about:blank'); 557 | $scope.iframeActiveEndpointUUID = null; 558 | } 559 | }); 560 | 561 | $scope.$on('rtcomm::iframeUpdate', function (eventType, endpointUUID, url) { 562 | if ($scope.syncSource == false){ 563 | $log.debug('rtcomm::iframeUpdate: ' + url); 564 | // This is needed to prevent rtcomm from logging in when the page is loaded in the iFrame. 565 | url = url + "?disableRtcomm=true"; 566 | $scope.iframeURL = $sce.trustAsResourceUrl(url); 567 | } 568 | else{ 569 | $log.debug('rtcomm::iframeUpdate: load this url in a new tab: ' + url); 570 | // In this case we'll open the pushed URL in a new tab. 571 | $window.open($sce.trustAsResourceUrl(url), '_blank'); 572 | } 573 | }); 574 | 575 | $scope.setURL = function(newURL){ 576 | $log.debug('rtcommIframe: setURL: newURL: ' + newURL); 577 | RtcommService.putIframeURL($scope.iframeActiveEndpointUUID, newURL); 578 | $scope.iframeURL = $sce.trustAsResourceUrl(newURL); 579 | }; 580 | 581 | $scope.forward = function() { 582 | }; 583 | 584 | $scope.backward = function() { 585 | }; 586 | }], 587 | controllerAs: 'rtcommiframe' 588 | }; 589 | }; 590 | 591 | 592 | 593 | /******************************** Rtcomm Modals ************************************************/ 594 | 595 | /** 596 | * This modal is displayed on receiving an inbound call. It handles the alerting event. 597 | * Note that it can also auto accept requests for enabling A/V. 598 | */ 599 | 600 | RtcommAlertModalController.$inject=['$rootScope', '$scope', 'RtcommService', '$modal', '$log']; 601 | function RtcommAlertModalController($rootScope, $scope, RtcommService, $modal, $log) { 602 | 603 | $scope.alertingEndpointUUID = null; 604 | $scope.autoAnswerNewMedia = false; 605 | $scope.alertActiveEndpointUUID = RtcommService.getActiveEndpoint(); 606 | $scope.caller = null; 607 | 608 | $scope.init = function(autoAnswerNewMedia) { 609 | $log.debug('rtcommAlert: autoAnswerNewMedia = ' + autoAnswerNewMedia); 610 | $scope.autoAnswerNewMedia = autoAnswerNewMedia; 611 | }; 612 | 613 | $scope.$on('endpointActivated', function (event, endpointUUID) { 614 | $scope.alertActiveEndpointUUID = endpointUUID; 615 | }); 616 | 617 | $scope.$on('session:alerting', function (event, eventObject) { 618 | 619 | if (($scope.alertActiveEndpointUUID == eventObject.endpoint.id && $scope.autoAnswerNewMedia == false) || 620 | ($scope.alertActiveEndpointUUID != eventObject.endpoint.id)) 621 | { 622 | $log.debug('rtcommAlert: display alterting model: alertActiveEndpointUUID = ' + eventObject.endpoint + ' autoAnswerNewMedia = ' + $scope.autoAnswerNewMedia); 623 | $scope.caller = eventObject.endpoint.getRemoteEndpointID(); 624 | $scope.alertingEndpointUUID = eventObject.endpoint.id; 625 | $scope.showAlerting(); 626 | } 627 | else{ 628 | $log.debug('Accepting media from: ' + eventObject.endpoint.getRemoteEndpointID() + ' for endpoint: ' + eventObject.endpoint.id); 629 | eventObject.endpoint.accept(); 630 | } 631 | }); 632 | 633 | $scope.showAlerting = function (size) { 634 | 635 | var modalInstance = $modal.open({ 636 | templateUrl: 'templates/rtcomm/rtcomm-modal-alert.html', 637 | controller: 'RtcommAlertModalInstanceController', 638 | size: size, 639 | backdrop: 'static', 640 | resolve: { 641 | caller: function () { 642 | return $scope.caller; 643 | }} 644 | }); 645 | 646 | modalInstance.result.then( 647 | function() { 648 | var alertingEndpointObject = RtcommService.getEndpoint($scope.alertingEndpointUUID); 649 | 650 | if(alertingEndpointObject){ 651 | $log.debug('Accepting call from: ' + $scope.caller + ' for endpoint: ' + $scope.alertingEndpointUUID); 652 | alertingEndpointObject.accept(); 653 | $rootScope.$broadcast('rtcomm::alert-success'); 654 | alertingEndpointObject = null; 655 | } 656 | }, 657 | function () { 658 | var alertingEndpointObject = RtcommService.getEndpoint($scope.alertingEndpointUUID); 659 | if(alertingEndpointObject){ 660 | $log.debug('Rejecting call from: ' + $scope.caller + ' for endpoint: ' + $scope.alertingEndpointUUID); 661 | alertingEndpointObject.reject(); 662 | alertingEndpointObject = null; 663 | } 664 | }); 665 | }; 666 | }; 667 | 668 | RtcommAlertModalInstanceController.$inject = ['$scope', '$modalInstance', '$log', 'caller']; 669 | 670 | function RtcommAlertModalInstanceController($scope, $modalInstance, $log, caller) { 671 | $scope.caller = caller; 672 | $scope.ok = function () { 673 | $log.debug('Accepting alerting call'); 674 | $modalInstance.close(); 675 | }; 676 | 677 | $scope.cancel = function () { 678 | $log.debug('Rejecting alerting call'); 679 | $modalInstance.dismiss('cancel'); 680 | }; 681 | }; 682 | 683 | /** 684 | * This is a modal controller for placing an outbound call to a static callee such as a queue. 685 | */ 686 | RtcommCallModalController.$inject = ['$scope', 'RtcommService', '$modal', '$log']; 687 | function RtcommCallModalController($scope, RtcommService, $modal, $log) { 688 | $scope.calleeID = null; 689 | $scope.callerID = null; 690 | 691 | $scope.enableCallModel = false; 692 | $scope.mediaToEnable = ['chat']; 693 | 694 | $scope.init = function(calleeID, mediaToEnable) { 695 | $scope.calleeID = calleeID; 696 | 697 | if (typeof mediaToEnable !== "undefined") 698 | $scope.mediaToEnable = mediaToEnable; 699 | }; 700 | 701 | $scope.$on('rtcomm::init', function (event, success, details) { 702 | $log.debug('RtcommCallModalController: rtcomm::init: success = ' + success); 703 | if (success == true) 704 | $scope.enableCallModel = true; 705 | else 706 | $scope.enableCallModel = false; 707 | }); 708 | 709 | $scope.$on('session:started', function (event, eventObject) { 710 | $scope.enableCallModel = false; 711 | }); 712 | 713 | $scope.$on('session:stopped', function (event, eventObject) { 714 | $scope.enableCallModel = true; 715 | }); 716 | 717 | $scope.placeCall = function (size) { 718 | 719 | var modalInstance = $modal.open({ 720 | templateUrl: 'templates/rtcomm/rtcomm-modal-call.html', 721 | controller: 'RtcommCallModalInstanceController', 722 | size: size, 723 | resolve: {} 724 | }); 725 | 726 | modalInstance.result.then( 727 | function (resultName) { 728 | $log.debug('rtcommCallModal: Calling calleeID: ' + $scope.calleeID); 729 | $log.debug('rtcommCallModal: CallerID: ' + resultName); 730 | 731 | // This is used to set an alias when the endoint is not defined. 732 | if ($scope.callerID == null && (typeof resultName !== "undefined") && resultName != ''){ 733 | $scope.callerID = resultName; 734 | RtcommService.setAlias(resultName); 735 | } 736 | 737 | RtcommService.placeCall($scope.calleeID, $scope.mediaToEnable); 738 | }, 739 | function () { 740 | $log.info('Modal dismissed at: ' + new Date()); 741 | }); 742 | }; 743 | }; 744 | 745 | RtcommCallModalInstanceController.$inject = ['$scope', '$modalInstance', 'RtcommService']; 746 | function RtcommCallModalInstanceController($scope, $modalInstance, RtcommService) { 747 | $scope.endpointAlias = ''; 748 | $scope.ok = function () { 749 | $modalInstance.close($scope.endpointAlias); 750 | }; 751 | $scope.cancel = function () { 752 | $modalInstance.dismiss('cancel'); 753 | }; 754 | }; 755 | 756 | /********************************************* Rtcomm Controllers ******************************************************/ 757 | 758 | /** 759 | * This is the controller for config loader. It reads a JSON object and utilizes the RtcommService to set the configuration. 760 | * This can also result in the initialization of the endpoint provider if the config JSON object includes a registration name. 761 | * 762 | * Here is an example of the config object: 763 | * 764 | * { 765 | * "server" : "server address", 766 | * "port" : 1883, 767 | * "rtcommTopicPath" : "/rtcomm-helpdesk/", 768 | * "createEndpoint" : false, 769 | * "userid" : "registration name", 770 | * "broadcastAudio" : true, 771 | * "broadcastVideo" : true 772 | * } 773 | * 774 | * NOTE: If the user does not specify a userid, that says one will never be specified so go ahead 775 | * and initialize the endpoint provider and let the provider assign a name. If a defined empty 776 | * string is passed in, that means to wait until the end user registers a name before initializing 777 | * the endpoint provider. 778 | */ 779 | 780 | RtcommConfigController.$inject = ['$scope','$http', 'RtcommService', '$log']; 781 | function RtcommConfigController($scope, $http, RtcommService, $log) { 782 | $scope.extendedConfig = null; 783 | 784 | $log.debug('RtcommConfigController: configURL = ' + $scope.configURL); 785 | 786 | $scope.setConfig = function(data) { 787 | $log.debug('RtcommConfigController: setting config data:' + data); 788 | RtcommService.setConfig(data); 789 | }; 790 | 791 | $scope.init = function(configURL,extendedConfig) { 792 | $log.debug('RtcommConfigController: initing configURL = ' + configURL); 793 | $scope.configURL = configURL; 794 | 795 | if (typeof extendedConfig !== "undefined") 796 | $scope.extendedConfig = extendedConfig; 797 | 798 | $scope.getConfig(); 799 | }; 800 | 801 | $scope.getConfig = function() { 802 | $http.get($scope.configURL).success (function(config){ 803 | 804 | // Now we need to update the config with any extensions passed in on init. 805 | if ($scope.extendedConfig != null){ 806 | angular.extend(config, $scope.extendedConfig); 807 | $log.debug('RtcommConfigController: extended config object: ' + config); 808 | } 809 | 810 | RtcommService.setConfig(config); 811 | }).error(function(data, status, headers, config) { 812 | $log.debug('RtcommConfigController: error accessing config: ' + status); 813 | }); 814 | }; 815 | }; 816 | 817 | 818 | RtcommVideoController.$inject= ['$scope','$http', 'RtcommService', '$log']; 819 | function RtcommVideoController($scope, $http, RtcommService, $log) { 820 | $scope.avConnected = RtcommService.isWebrtcConnected(RtcommService.getActiveEndpoint()); 821 | $scope.init = function(selfView,remoteView) { 822 | RtcommService.setViewSelector(selfView,remoteView); 823 | 824 | var videoActiveEndpointUUID = RtcommService.getActiveEndpoint(); 825 | if (typeof videoActiveEndpointUUID !== "undefined" && videoActiveEndpointUUID != null) 826 | RtcommService.setVideoView(videoActiveEndpointUUID); 827 | }; 828 | 829 | // Go ahead and initialize the local media here if an endpoint already exist. 830 | var videoActiveEndpointUUID = RtcommService.getActiveEndpoint(); 831 | if (typeof videoActiveEndpointUUID !== "undefined" && videoActiveEndpointUUID != null) 832 | RtcommService.setVideoView(videoActiveEndpointUUID); 833 | 834 | $scope.$on('endpointActivated', function (event, endpointUUID) { 835 | // Not to do something here to show that this button is live. 836 | $log.debug('rtcommVideo: endpointActivated =' + endpointUUID); 837 | RtcommService.setVideoView(endpointUUID); 838 | $scope.avConnected = RtcommService.isWebrtcConnected(RtcommService.getActiveEndpoint()); 839 | }); 840 | 841 | $scope.$on('noEndpointActivated', function (event) { 842 | $scope.avConnected = false; 843 | }); 844 | 845 | $scope.$on('webrtc:connected', function (event, eventObject) { 846 | if (RtcommService.getActiveEndpoint() == eventObject.endpoint.id) 847 | $scope.avConnected = true; 848 | }); 849 | 850 | $scope.$on('webrtc:disconnected', function (event, eventObject) { 851 | if (RtcommService.getActiveEndpoint() == eventObject.endpoint.id) 852 | $scope.avConnected = false; 853 | }); 854 | }; 855 | 856 | 857 | RtcommEndpointController.$inject = ['$scope', '$rootScope', '$http', 'RtcommService', '$log']; 858 | function RtcommEndpointController($scope, $rootScope, $http, RtcommService, $log) { 859 | // Session states. 860 | $scope.epCtrlActiveEndpointUUID = RtcommService.getActiveEndpoint(); 861 | $scope.epCtrlAVConnected = RtcommService.isWebrtcConnected($scope.epCtrlActiveEndpointUUID); 862 | $scope.sessionState = RtcommService.getSessionState($scope.epCtrlActiveEndpointUUID); 863 | 864 | $scope.disconnect = function() { 865 | $log.debug('Disconnecting call for endpoint: ' + $scope.epCtrlActiveEndpointUUID); 866 | RtcommService.getEndpoint($scope.epCtrlActiveEndpointUUID).disconnect(); 867 | }; 868 | 869 | $scope.toggleAV = function() { 870 | $log.debug('Enable AV for endpoint: ' + $scope.epCtrlActiveEndpointUUID); 871 | 872 | if ($scope.epCtrlAVConnected == false){ 873 | RtcommService.getEndpoint($scope.epCtrlActiveEndpointUUID).webrtc.enable(function(value, message) { 874 | if (!value) { 875 | $log.debug('Enable failed: ',message); 876 | RtcommService.alert({type: 'danger', msg: message}); 877 | } 878 | }); 879 | } 880 | else{ 881 | $log.debug('Disable AV for endpoint: ' + $scope.epCtrlActiveEndpointUUID); 882 | RtcommService.getEndpoint($scope.epCtrlActiveEndpointUUID).webrtc.disable(); 883 | } 884 | }; 885 | 886 | $scope.$on('session:started', function (event, eventObject) { 887 | $log.debug('session:started received: endpointID = ' + eventObject.endpoint.id); 888 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 889 | $scope.sessionState = 'session:started'; 890 | } 891 | }); 892 | 893 | $scope.$on('session:stopped', function (event, eventObject) { 894 | $log.debug('session:stopped received: endpointID = ' + eventObject.endpoint.id); 895 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 896 | $scope.sessionState = 'session:stopped'; 897 | } 898 | }); 899 | 900 | $scope.$on('session:failed', function (event, eventObject) { 901 | $log.debug('session:failed received: endpointID = ' + eventObject.endpoint.id); 902 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id){ 903 | $scope.sessionState = 'session:failed'; 904 | } 905 | }); 906 | 907 | $scope.$on('webrtc:connected', function (event, eventObject) { 908 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id) 909 | $scope.epCtrlAVConnected = true; 910 | }); 911 | 912 | $scope.$on('webrtc:disconnected', function (event, eventObject) { 913 | if ($scope.epCtrlActiveEndpointUUID == eventObject.endpoint.id) 914 | $scope.epCtrlAVConnected = false; 915 | }); 916 | 917 | 918 | $scope.$on('endpointActivated', function (event, endpointUUID) { 919 | $scope.epCtrlActiveEndpointUUID = endpointUUID; 920 | $scope.epCtrlAVConnected = RtcommService.isWebrtcConnected(endpointUUID); 921 | }); 922 | 923 | $scope.$on('noEndpointActivated', function (event) { 924 | $scope.epCtrlAVConnected = false; 925 | }); 926 | }; 927 | 928 | })(); 929 | -------------------------------------------------------------------------------- /src/js/rtcomm-presence.js: -------------------------------------------------------------------------------- 1 | /* 2 | * The angular-rtcomm-presence module 3 | * This has controllers and directives in it. 4 | */ 5 | (function(){ 6 | angular 7 | .module('angular-rtcomm-presence', [ 8 | 'ui.bootstrap', 9 | 'treeControl', 10 | 'angular-rtcomm-service']) 11 | .directive('rtcommPresence', rtcommPresence); 12 | 13 | /** 14 | * This directive manages the chat portion of a session. The data model for chat 15 | * is maintained in the RtcommService. This directive handles switching between 16 | * active endpoints. 17 | * 18 | * Here is the formate of the presenceData: 19 | * 20 | * This is a Node: 21 | * { 22 | * "name" : "agents", 23 | * "record" : false, 24 | * "nodes" : [] 25 | * } 26 | * 27 | * This is a record with a set of user defines: 28 | * { 29 | * "name" : "Brian Pulito", 30 | * "record" : true, 31 | * "nodes" : [ 32 | * { 33 | * "name" : "queue", 34 | * "value" : "appliances" 35 | * }, 36 | * { 37 | * "name" : "sessions", 38 | * "value" : "3" 39 | * } 40 | * ] 41 | */ 42 | rtcommPresence.$inject=['RtcommService', '$log']; 43 | function rtcommPresence(RtcommService, $log) { 44 | return { 45 | restrict: 'E', 46 | templateUrl: "templates/rtcomm/rtcomm-presence.html", 47 | controller: function ($scope, $rootScope) { 48 | 49 | $scope.monitorTopics = []; 50 | $scope.presenceData = []; 51 | $scope.expandedNodes = []; 52 | 53 | // Default protocol list initiated from presence. Start with chat only. 54 | $scope.protocolList = { 55 | chat : true, 56 | webrtc : false}; 57 | 58 | // use a tree view or flatten. 59 | $scope.flatten = false; 60 | $scope.treeOptions = { 61 | nodeChildren: "nodes", 62 | dirSelectable: true, 63 | injectClasses: { 64 | ul: "a1", 65 | li: "a2", 66 | liSelected: "a7", 67 | iExpanded: "a3", 68 | iCollapsed: "a4", 69 | iLeaf: "a5", 70 | label: "a6", 71 | labelSelected: "a8" 72 | } 73 | }; 74 | 75 | $scope.init = function(options) { 76 | $scope.protocolList.chat = (typeof options.chat === 'boolean') ? options.chat : $scope.protocolList.chat; 77 | $scope.protocolList.webrtc = (typeof options.webrtc === 'boolean') ? options.webrtc : $scope.protocolList.webrtc; 78 | $scope.flatten = (typeof options.flatten === 'boolean') ? options.flatten: $scope.flatten; 79 | }; 80 | 81 | $scope.onCallClick = function(calleeEndpointID){ 82 | var endpoint = RtcommService.getEndpoint(); 83 | RtcommService.setActiveEndpoint(endpoint.id); 84 | 85 | if ($scope.protocolList.chat == true) 86 | endpoint.chat.enable(); 87 | 88 | if ($scope.protocolList.webrtc == true){ 89 | endpoint.webrtc.enable(function(value, message) { 90 | if (!value) { 91 | RtcommService.alert({type: 'danger', msg: message}); 92 | } 93 | }); 94 | } 95 | 96 | endpoint.connect(calleeEndpointID); 97 | $rootScope.$broadcast('rtcomm::presence-click'); 98 | }; 99 | 100 | $scope.$on('rtcomm::init', function (event, success, details) { 101 | RtcommService.publishPresence(); 102 | var presenceMonitor = RtcommService.getPresenceMonitor(); 103 | 104 | presenceMonitor.on('updated', function(presenceData){ 105 | $log.debug('<<------rtcommPresence: updated------>>'); 106 | if ($scope.flatten) { 107 | $log.debug('<<------rtcommPresence: updated using flattened data ------>>'); 108 | $scope.presenceData = presenceData[0].flatten(); 109 | } 110 | $scope.$apply(); 111 | }); 112 | 113 | // Binding data if we are going to flatten causes a flash in the UI when it changes. 114 | if (!$scope.flatten) { 115 | $scope.presenceData = presenceMonitor.getPresenceData(); 116 | } 117 | 118 | if ($scope.presenceData.length >= 1) 119 | $scope.expandedNodes.push($scope.presenceData[0]); 120 | 121 | for (var index = 0; index < $scope.monitorTopics.length; index++) { 122 | $log.debug('rtcommPresence: monitorTopic: ' + $scope.monitorTopics[index]); 123 | presenceMonitor.add($scope.monitorTopics[index]); 124 | } 125 | }); 126 | 127 | }, 128 | controllerAs: 'presence' 129 | }; 130 | }; 131 | })(); 132 | -------------------------------------------------------------------------------- /src/js/rtcomm-services.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for the rtcommModule 3 | */ 4 | 5 | (function() { 6 | angular.module('angular-rtcomm-service', []) 7 | /** 8 | * Set debugEnabled to true to enable the debug messages in this rtcomm angular module. 9 | */ 10 | .config(function($logProvider){ 11 | $logProvider.debugEnabled(true); 12 | }) 13 | /* This causes a problem in ionic/iosrtc 14 | .config(function($locationProvider) { 15 | $locationProvider.html5Mode( {enabled: true, 16 | requireBase: false}); 17 | }) */ 18 | .factory('RtcommConfigService', RtcommConfigService) 19 | .factory('RtcommService', RtcommService); 20 | /** 21 | * 22 | */ 23 | RtcommConfigService.$inject = ['$location', '$log', '$window']; 24 | function RtcommConfigService($location, $log, $window) { 25 | // First we check to see if the URL includes the query string disableRtcomm=true. 26 | // This is typically done when a URL is being shared vian an iFrame that includes Rtcomm directives. 27 | // If it is set we just return without setting up Rtcomm. 28 | $log.debug('RtcommConfigService: Abs URL: ' + $location.absUrl()); 29 | var _disableRtcomm = $location.search().disableRtcomm; 30 | if (typeof _disableRtcomm === "undefined" || _disableRtcomm === null) { 31 | _disableRtcomm = false; 32 | } else if (_disableRtcomm === "true") { 33 | _disableRtcomm = true; 34 | } else { 35 | _disableRtcomm = false; 36 | } 37 | 38 | $log.debug('RtcommConfigService: _disableRtcomm = ' + _disableRtcomm); 39 | 40 | var providerConfig = { 41 | server : $location.host(), 42 | port : $location.port(), 43 | rtcommTopicPath : "/rtcomm/", 44 | createEndpoint : false, 45 | appContext: 'default', 46 | userid: "", 47 | presence : {topic : ""} 48 | }; 49 | 50 | $log.debug('providerConfig.server: ' + providerConfig.server); 51 | $log.debug('providerConfig.port: ' + providerConfig.port); 52 | 53 | var endpointConfig = { 54 | chat: true, 55 | webrtc: true 56 | }; 57 | 58 | // Default to enabling audio and video. It must be disabled through config. 59 | var broadcastAudio = true; 60 | var broadcastVideo = true; 61 | var rtcommDebug = "DEBUG"; 62 | var ringtone = null; 63 | var ringbacktone = null; 64 | 65 | var setConfig = function(config){ 66 | providerConfig.server = (typeof config.server !== "undefined")? config.server : providerConfig.server; 67 | providerConfig.port = (typeof config.port !== "undefined")? config.port : providerConfig.port; 68 | providerConfig.rtcommTopicPath = (typeof config.rtcommTopicPath !== "undefined")? config.rtcommTopicPath : providerConfig.rtcommTopicPath; 69 | providerConfig.createEndpoint = (typeof config.createEndpoint !== "undefined")? config.createEndpoint : providerConfig.createEndpoint; 70 | providerConfig.appContext = (typeof config.appContext !== "undefined")? config.appContext : providerConfig.appContext; 71 | providerConfig.presence.topic = (typeof config.presenceTopic !== "undefined")? config.presenceTopic : providerConfig.presence.topic; 72 | 73 | // We no longer need to set 'useSSL' This will be set based on how page is served. 74 | // providerConfig.useSSL = (typeof config.useSSL !== "undefined")? config.useSSL : providerConfig.useSSL; 75 | // Protocol related booleans 76 | endpointConfig.chat= (typeof config.chat!== "undefined")? config.chat: endpointConfig.chat; 77 | endpointConfig.webrtc = (typeof config.webrtc!== "undefined")? config.webrtc: endpointConfig.webrtc; 78 | 79 | broadcastAudio = (typeof config.broadcastAudio !== "undefined")? config.broadcastAudio: broadcastAudio; 80 | broadcastVideo = (typeof config.broadcastVideo !== "undefined")? config.broadcastVideo: broadcastVideo; 81 | 82 | ringbacktone = (typeof config.ringbacktone !== "undefined")? config.ringbacktone: ringbacktone; 83 | ringtone = (typeof config.ringtone !== "undefined")? config.ringtone : ringtone; 84 | 85 | rtcommDebug = (typeof config.rtcommDebug !== "undefined")? config.rtcommDebug: rtcommDebug; 86 | 87 | $log.debug('rtcommDebug from config is: ' + config.rtcommDebug); 88 | 89 | if (typeof config.userid !== "undefined") 90 | providerConfig.userid = config.userid; 91 | 92 | $log.debug('providerConfig is now: ', providerConfig); 93 | 94 | }; 95 | 96 | return { 97 | setProviderConfig : function(config){setConfig(config);}, 98 | 99 | getProviderConfig : function(){return providerConfig;}, 100 | 101 | getWebRTCEnabled : function(){return endpointConfig.webrtc;}, 102 | 103 | getChatEnabled : function(){return endpointConfig.chat;}, 104 | 105 | getBroadcastAudio : function(){return broadcastAudio;}, 106 | 107 | getBroadcastVideo : function(){return broadcastVideo;}, 108 | 109 | getRingTone : function(){return ringtone;}, 110 | 111 | getRingBackTone : function(){return ringbacktone;}, 112 | 113 | getRtcommDebug: function(){return rtcommDebug;}, 114 | 115 | isRtcommDisabled : function(){return _disableRtcomm;} 116 | }; 117 | }; 118 | 119 | RtcommService.$inject=['$rootScope', '$log', '$http', 'RtcommConfigService']; 120 | function RtcommService($rootScope, $log, $http, RtcommConfigService) { 121 | /** Setup the endpoint provider first **/ 122 | var myEndpointProvider = new rtcomm.EndpointProvider(); 123 | var endpointProviderInitialized = false; 124 | var queueList = null; 125 | var sessions = []; 126 | var presenceRecord = null; 127 | var karmaTesting = false; 128 | var _selfView = "selfView"; // Default self view 129 | var _remoteView = "remoteView"; // Default remote view 130 | 131 | myEndpointProvider.setLogLevel(RtcommConfigService.getRtcommDebug()); 132 | $log.debug('rtcomm-service - endpointProvider log level is: '+myEndpointProvider.getLogLevel()); 133 | $log.debug('rtcomm-service - endpointProvider log level should be: '+RtcommConfigService.getRtcommDebug()); 134 | myEndpointProvider.setAppContext(RtcommConfigService.getProviderConfig().appContext); 135 | 136 | var getPresenceRecord = function(){ 137 | if (presenceRecord == null) 138 | presenceRecord = {'state': 'available', userDefines: []}; 139 | 140 | return (presenceRecord); 141 | }; 142 | 143 | // This defines all the media related configuration and is controlled through external config. 144 | var getMediaConfig = function() { 145 | 146 | var mediaConfig = { 147 | ringbacktone: RtcommConfigService.getRingBackTone(), 148 | ringtone: RtcommConfigService.getRingTone(), 149 | webrtcConfig: { 150 | broadcast : { 151 | audio : RtcommConfigService.getBroadcastAudio(), 152 | video : RtcommConfigService.getBroadcastVideo() 153 | } 154 | }, 155 | webrtc : RtcommConfigService.getWebRTCEnabled(), 156 | chat : RtcommConfigService.getChatEnabled(), 157 | }; 158 | 159 | return (mediaConfig); 160 | }; 161 | 162 | myEndpointProvider.on('reset', function(event_object) { 163 | // Should have a reason. 164 | _alert({type:'danger', msg: event_object.reason}); 165 | }); 166 | 167 | 168 | myEndpointProvider.on('queueupdate', function(queuelist) { 169 | $log.debug('<<------rtcomm-service------>> - Event: queueupdate'); 170 | $log.debug('queueupdate', queuelist); 171 | $rootScope.$evalAsync( 172 | function () { 173 | $rootScope.$broadcast('queueupdate', queuelist); 174 | } 175 | ); 176 | }); 177 | 178 | myEndpointProvider.on('newendpoint', function(endpoint) { 179 | $log.debug('<<------rtcomm-service------>> - Event: newendpoint remoteEndpointID: ' + endpoint.getRemoteEndpointID()); 180 | 181 | endpoint.on('onetimemessage',function(event){ 182 | $log.debug('<<------rtcomm-onetimemessage------>> - Event: ', event); 183 | if (event.onetimemessage.type != "undefined" && event.onetimemessage.type == 'iFrameURL'){ 184 | var session = _createSession(event.endpoint.id); 185 | session.iFrameURL = event.onetimemessage.iFrameURL; 186 | $rootScope.$evalAsync( 187 | function () { 188 | $rootScope.$broadcast('rtcomm::iframeUpdate', event.endpoint.id, event.onetimemessage.iFrameURL); 189 | } 190 | ); 191 | } 192 | }); 193 | 194 | $rootScope.$evalAsync( 195 | function () { 196 | $rootScope.$broadcast('newendpoint', endpoint); 197 | } 198 | ); 199 | }); 200 | 201 | var callback = function(eventObject) { 202 | $log.debug('<<------rtcomm-service------>> - Event: ' + eventObject.eventName + ' remoteEndpointID: ' + eventObject.endpoint.getRemoteEndpointID()); 203 | $rootScope.$evalAsync( 204 | function () { 205 | if (eventObject.eventName.indexOf("session:") > -1){ 206 | var session = _createSession(eventObject.endpoint.id); 207 | session.sessionState = eventObject.eventName; 208 | } 209 | $rootScope.$broadcast(eventObject.eventName, eventObject); 210 | } 211 | ); 212 | 213 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 214 | if (karmaTesting == true) 215 | $rootScope.$digest(); 216 | 217 | }; 218 | 219 | // Setup all the callbacks here because they are all static. 220 | myEndpointProvider.setRtcommEndpointConfig ({ 221 | ringtone: RtcommConfigService.getRingTone(), 222 | ringbacktone: RtcommConfigService.getRingBackTone(), 223 | // These are all the session related events. 224 | 'session:started' : function(eventObject) { 225 | $log.debug('<<------rtcomm-service------>> - Event: ' + eventObject.eventName + ' remoteEndpointID: ' + eventObject.endpoint.getRemoteEndpointID()); 226 | $rootScope.$evalAsync( 227 | function () { 228 | var session = _createSession(eventObject.endpoint.id); 229 | _setActiveEndpoint(eventObject.endpoint.id); 230 | 231 | session.sessionStarted = true; 232 | session.remoteEndpointID = eventObject.endpoint.getRemoteEndpointID(); 233 | $rootScope.$broadcast(eventObject.eventName, eventObject); 234 | } 235 | ); 236 | 237 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 238 | if (karmaTesting == true) 239 | $rootScope.$digest(); 240 | 241 | }, 242 | 243 | 'session:alerting' : callback, 244 | 'session:trying' : callback, 245 | 'session:ringing' : callback, 246 | 'session:queued' : callback, 247 | 248 | 'session:failed' : function(eventObject) { 249 | $log.debug('<<------rtcomm-service------>> - Event: ' + eventObject.eventName + ' remoteEndpointID: ' + eventObject.endpoint.getRemoteEndpointID()); 250 | $rootScope.$evalAsync( 251 | function () { 252 | _removeSession(eventObject.endpoint.id); 253 | $rootScope.$broadcast(eventObject.eventName, eventObject); 254 | } 255 | ); 256 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 257 | if (karmaTesting == true) 258 | $rootScope.$digest(); 259 | 260 | }, 261 | 262 | 'session:stopped' : function(eventObject) { 263 | $log.debug('<<------rtcomm-service------>> - Event: ' + eventObject.eventName + ' remoteEndpointID: ' + eventObject.endpoint.getRemoteEndpointID()); 264 | $rootScope.$evalAsync( 265 | function () { 266 | _removeSession(eventObject.endpoint.id); 267 | $rootScope.$broadcast(eventObject.eventName, eventObject); 268 | } 269 | ); 270 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 271 | if (karmaTesting == true) 272 | $rootScope.$digest(); 273 | 274 | }, 275 | 276 | // These are all the WebRTC related events. 277 | 'webrtc:connected' : function(eventObject) { 278 | $log.debug('<<------rtcomm-service------>> - Event: ' + eventObject.eventName + ' remoteEndpointID: ' + eventObject.endpoint.getRemoteEndpointID()); 279 | 280 | $rootScope.$evalAsync( 281 | function () { 282 | _createSession(eventObject.endpoint.id).webrtcConnected = true; 283 | $rootScope.$broadcast(eventObject.eventName, eventObject); 284 | } 285 | ); 286 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 287 | if (karmaTesting == true) 288 | $rootScope.$digest(); 289 | }, 290 | // These are all the WebRTC related events. 291 | 'webrtc:remotemuted' : function(eventObject) { 292 | $log.debug('<<------rtcomm-service------>> - Event: ' + eventObject.eventName + ' remoteEndpointID: ' + eventObject.endpoint.getRemoteEndpointID()); 293 | $rootScope.$evalAsync( 294 | function () { 295 | $rootScope.$broadcast(eventObject.eventName, eventObject); 296 | } 297 | ); 298 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 299 | if (karmaTesting == true) 300 | $rootScope.$digest(); 301 | }, 302 | 303 | 'webrtc:disconnected' : function(eventObject) { 304 | $log.debug('<<------rtcomm-service------>> - Event: ' + eventObject.eventName + ' remoteEndpointID: ' + eventObject.endpoint.getRemoteEndpointID()); 305 | 306 | $rootScope.$evalAsync( 307 | function () { 308 | var session = _getSession(eventObject.endpoint.id); 309 | if (session != null) 310 | session.webrtcConnected = false; 311 | $rootScope.$broadcast(eventObject.eventName, eventObject); 312 | } 313 | ); 314 | 315 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 316 | if (karmaTesting == true) 317 | $rootScope.$digest(); 318 | }, 319 | 320 | // These are all the chat related events. 321 | 'chat:connected' : callback, 322 | 'chat:disconnected' : callback, 323 | 324 | 'chat:message' : function(eventObject) { 325 | $log.debug('<<------rtcomm-service------>> - Event: ' + eventObject.eventName + ' remoteEndpointID: ' + eventObject.endpoint.getRemoteEndpointID()); 326 | $rootScope.$evalAsync( 327 | function () { 328 | var chat = { 329 | time : new Date(), 330 | name : eventObject.message.from, 331 | message : angular.copy(eventObject.message.message) 332 | }; 333 | 334 | _createSession(eventObject.endpoint.id).chats.push(chat); 335 | $rootScope.$broadcast(eventObject.eventName, eventObject); 336 | } 337 | ); 338 | 339 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 340 | if (karmaTesting == true) 341 | $rootScope.$digest(); 342 | }, 343 | 344 | // Endpoint destroyed 345 | 'destroyed' : callback 346 | }); 347 | 348 | var initSuccess = function(event) { 349 | $log.debug('<<------rtcomm-service------>> - Event: Provider init succeeded'); 350 | 351 | if (presenceRecord != null){ 352 | $log.debug('RtcommService: initSuccess: updating presence record'); 353 | myEndpointProvider.publishPresence(presenceRecord); 354 | } 355 | 356 | $rootScope.$evalAsync( 357 | function () { 358 | var broadcastEvent = { 359 | 'ready': event.ready, 360 | 'registered': event.registered, 361 | 'endpoint': event.endpoint, 362 | 'userid' : RtcommConfigService.getProviderConfig().userid 363 | }; 364 | 365 | $rootScope.$broadcast('rtcomm::init', true, broadcastEvent); 366 | } 367 | ); 368 | 369 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 370 | if (karmaTesting == true) 371 | $rootScope.$digest(); 372 | }; 373 | 374 | var initFailure = function(error) { 375 | $log.debug('<<------rtcomm-service------>> - Event: Provider init failed: error: ',error); 376 | $rootScope.$evalAsync( 377 | function () { 378 | $rootScope.$broadcast('rtcomm::init', false, error); 379 | } 380 | ); 381 | // This is required in karma to get the evalAsync to fire. Ugly but necessary... 382 | if (karmaTesting == true) 383 | $rootScope.$digest(); 384 | }; 385 | 386 | /* 387 | * Get session from local endpoint ID 388 | */ 389 | var _getSession = function(endpointUUID){ 390 | 391 | var session = null; 392 | 393 | for (var index = 0; index < sessions.length; index++) { 394 | if(sessions[index].endpointUUID === endpointUUID){ 395 | session = sessions[index]; 396 | break; 397 | } 398 | } 399 | 400 | return (session); 401 | }; 402 | 403 | /* 404 | * Get session from local endpoint ID 405 | */ 406 | var _createSession = function(endpointUUID){ 407 | 408 | var session = null; 409 | 410 | for (var index = 0; index < sessions.length; index++) { 411 | if(sessions[index].endpointUUID === endpointUUID){ 412 | session = sessions[index]; 413 | break; 414 | } 415 | } 416 | 417 | if (session == null){ 418 | session = { 419 | endpointUUID : endpointUUID, 420 | chats : [], 421 | webrtcConnected : false, 422 | sessionStarted : false, 423 | iFrameURL : 'about:blank', 424 | remoteEndpointID : null, 425 | activated : true, 426 | sessionState : 'session:stopped' 427 | }; 428 | sessions[sessions.length] = session; 429 | } 430 | 431 | return (session); 432 | }; 433 | 434 | var _removeSession = function(endpointUUID){ 435 | 436 | for (var index = 0; index < sessions.length; index++) { 437 | if(sessions[index].endpointUUID === endpointUUID){ 438 | 439 | _getEndpoint(endpointUUID).destroy(); 440 | 441 | // Remove the disconnected endpoint from the list. 442 | sessions.splice(index, 1); 443 | 444 | // Now we need to set the active endpoint to someone else or to no endpoint if none are left. 445 | if (sessions.length == 0){ 446 | $rootScope.$broadcast('noEndpointActivated'); 447 | } 448 | else{ 449 | _setActiveEndpoint(sessions[0].endpointUUID); 450 | } 451 | break; 452 | } 453 | } 454 | }; 455 | 456 | 457 | var _getEndpoint = function(uuid) { 458 | var endpoint = null; 459 | 460 | if ((typeof uuid === "undefined") || uuid == null){ 461 | $log.debug('getEndpoint: create new endpoint and setup onetimemessage event'); 462 | endpoint = myEndpointProvider.createRtcommEndpoint(); 463 | endpoint.on('onetimemessage',function(event){ 464 | $log.debug('<<------rtcomm-onetimemessage------>> - Event: ', event); 465 | if (event.onetimemessage.type != "undefined" && event.onetimemessage.type == 'iFrameURL'){ 466 | var session = _createSession(event.endpoint.id); 467 | 468 | session.iFrameURL = event.onetimemessage.iFrameURL; 469 | 470 | $rootScope.$evalAsync( 471 | function () { 472 | $rootScope.$broadcast('rtcomm::iframeUpdate', event.endpoint.id, event.onetimemessage.iFrameURL); 473 | } 474 | ); 475 | } 476 | }); 477 | } 478 | else 479 | endpoint = myEndpointProvider.getRtcommEndpoint(uuid); 480 | 481 | return (endpoint); 482 | }; 483 | 484 | var _setActiveEndpoint = function(endpointID){ 485 | 486 | // First get the old active endpoint 487 | var activeEndpoint = _getActiveEndpointUUID(); 488 | if ((activeEndpoint != null) && (activeEndpoint != endpointID)){ 489 | var session = _getSession(activeEndpoint); 490 | if (session != null) 491 | session.activated = false; 492 | } 493 | 494 | var session = _createSession(endpointID); 495 | session.activated = true; 496 | 497 | $rootScope.$broadcast('endpointActivated', endpointID); 498 | }; 499 | 500 | var _getActiveEndpointUUID = function(){ 501 | var activeEndpoint = null; 502 | 503 | for (var index = 0; index < sessions.length; index++) { 504 | if(sessions[index].activated == true){ 505 | activeEndpoint = sessions[index].endpointUUID; 506 | break; 507 | } 508 | } 509 | return (activeEndpoint); 510 | }; 511 | var _alert = function _alert(alertObject) { 512 | var a = { type: 'info', 513 | msg: 'default message'}; 514 | if (typeof alertObject === 'string') { 515 | a.msg = alertObject; 516 | } else { 517 | a = alertObject; 518 | } 519 | $rootScope.$evalAsync( 520 | function () { 521 | $rootScope.$broadcast('rtcomm::alert', a); 522 | } 523 | ); 524 | }; 525 | 526 | 527 | return { 528 | 529 | alert: _alert, 530 | 531 | setKarmaTesting : function(){ 532 | karmaTesting = true; 533 | }, 534 | 535 | isInitialized : function(){ 536 | return(endpointProviderInitialized); 537 | }, 538 | 539 | setConfig : function(config){ 540 | if (RtcommConfigService.isRtcommDisabled() == true){ 541 | $log.debug('RtcommService:setConfig: isRtcommDisabled = true; return with no setup'); 542 | return; 543 | } 544 | 545 | 546 | $log.debug('rtcomm-services: setConfig: config: ', config); 547 | 548 | RtcommConfigService.setProviderConfig(config); 549 | myEndpointProvider.setRtcommEndpointConfig(getMediaConfig()); 550 | 551 | if (endpointProviderInitialized == false){ 552 | // If an identityServlet is defined we will get the User ID from the servlet. 553 | // This is used when the user ID needs to be derived from an SSO token like LTPA. 554 | if (typeof config.identityServlet !== "undefined" && config.identityServlet != null){ 555 | $http.get(config.identityServlet).success (function(data){ 556 | 557 | if (typeof data.userid !== "undefined"){ 558 | RtcommConfigService.setProviderConfig(data); 559 | myEndpointProvider.init(RtcommConfigService.getProviderConfig(), initSuccess, initFailure); 560 | endpointProviderInitialized = true; 561 | } 562 | else 563 | $log.error('RtcommService: setConfig promise: Invalid JSON object return from identityServlet: ', data); 564 | }).error(function(data, status, headers, config) { 565 | $log.debug('RtcommService: setConfig promise: error accessing userid from identityServlet: ' + status); 566 | }); 567 | } 568 | else{ 569 | // If the user does not specify a userid, that says one will never be specified so go ahead 570 | // and initialize the endpoint provider and let the provider assign a name. If a defined empty 571 | // string is passed in, that means to wait until the end user registers a name. 572 | if (typeof config.userid == "undefined" || RtcommConfigService.getProviderConfig().userid != ''){ 573 | myEndpointProvider.init(RtcommConfigService.getProviderConfig(), initSuccess, initFailure); 574 | endpointProviderInitialized = true; 575 | } 576 | } 577 | } 578 | }, 579 | 580 | // Presence related methods 581 | getPresenceMonitor:function(topic) { 582 | return myEndpointProvider.getPresenceMonitor(topic); 583 | }, 584 | 585 | publishPresence:function() { 586 | if (endpointProviderInitialized == true) 587 | myEndpointProvider.publishPresence(getPresenceRecord()); 588 | }, 589 | 590 | /** 591 | * userDefines is an array of JSON objects that look like: 592 | * 593 | * { 594 | * name : "some name", 595 | * value : "some value" 596 | * } 597 | * 598 | * The only rule is that some name and some value have to both be strings. 599 | */ 600 | addToPresenceRecord:function(userDefines) { 601 | 602 | for (var index = 0; index < userDefines.length; index++) { 603 | getPresenceRecord().userDefines.push(userDefines[index]); 604 | } 605 | 606 | if (endpointProviderInitialized == true){ 607 | $log.debug('RtcommService: addToPresenceRecord: updating presence record to: ', getPresenceRecord()); 608 | myEndpointProvider.publishPresence(getPresenceRecord()); 609 | } 610 | }, 611 | 612 | /** 613 | * userDefines is an array of JSON objects that look like: 614 | * 615 | * { 616 | * name : "some name", 617 | * value : "some value" 618 | * } 619 | * 620 | * The only rule is that some name and some value have to both be strings. 621 | */ 622 | removeFromPresenceRecord:function(userDefines, doPublish) { 623 | 624 | for (var i = 0; i < userDefines.length; i++) { 625 | for (var j = 0; j < getPresenceRecord().userDefines.length; j++) { 626 | 627 | if (getPresenceRecord().userDefines[j].name == userDefines[i].name){ 628 | getPresenceRecord().userDefines.splice(j,1); 629 | break; 630 | } 631 | } 632 | } 633 | 634 | if ((endpointProviderInitialized == true) && doPublish){ 635 | $log.debug('RtcommService: removeFromPresenceRecord: updating presence record to: ', getPresenceRecord()); 636 | myEndpointProvider.publishPresence(getPresenceRecord()); 637 | } 638 | }, 639 | 640 | setPresenceRecordState:function(state) { 641 | getPresenceRecord().state = state; 642 | return myEndpointProvider.publishPresence(getPresenceRecord()); 643 | }, 644 | 645 | // Endpoint related methods 646 | getEndpoint : function(uuid) { 647 | return(_getEndpoint(uuid)); 648 | }, 649 | 650 | destroyEndpoint : function(uuid) { 651 | myEndpointProvider.getRtcommEndpoint(uuid).destroy(); 652 | }, 653 | 654 | // Registration related methods. 655 | register : function(userid) { 656 | if (endpointProviderInitialized == false){ 657 | RtcommConfigService.getProviderConfig().userid = userid; 658 | 659 | myEndpointProvider.init(RtcommConfigService.getProviderConfig(), initSuccess, initFailure); 660 | endpointProviderInitialized = true; 661 | } 662 | else 663 | $log.error('rtcomm-services: register: ERROR: endpoint provider already initialized'); 664 | }, 665 | 666 | unregister : function() { 667 | if (endpointProviderInitialized == true){ 668 | myEndpointProvider.destroy(); 669 | endpointProviderInitialized = false; 670 | initFailure("destroyed"); 671 | } 672 | else 673 | $log.error('rtcomm-services: unregister: ERROR: endpoint provider not initialized'); 674 | }, 675 | 676 | // Queue related methods 677 | joinQueue : function(queueID) { 678 | myEndpointProvider.joinQueue(queueID); 679 | }, 680 | 681 | leaveQueue : function(queueID) { 682 | myEndpointProvider.leaveQueue(queueID); 683 | }, 684 | 685 | getQueues : function() { 686 | return(queueList); 687 | }, 688 | 689 | /** 690 | * Chat related methods 691 | */ 692 | sendChatMessage : function(chat, endpointUUID){ 693 | // Save this chat in the local session store 694 | var session = _createSession(endpointUUID); 695 | session.chats.push(chat); 696 | 697 | myEndpointProvider.getRtcommEndpoint(endpointUUID).chat.send(chat.message); 698 | }, 699 | 700 | getChats : function(endpointUUID) { 701 | if (typeof endpointUUID !== "undefined" && endpointUUID != null){ 702 | var session = _getSession(endpointUUID); 703 | if (session != null) 704 | return (session.chats); 705 | else 706 | return(null); 707 | } 708 | else 709 | return(null); 710 | }, 711 | 712 | isWebrtcConnected : function(endpointUUID) { 713 | if (typeof endpointUUID !== 'undefined' && endpointUUID != null){ 714 | var session = _getSession(endpointUUID); 715 | if (session != null) 716 | return (session.webrtcConnected); 717 | else 718 | return(false); 719 | } 720 | else 721 | return(false); 722 | }, 723 | 724 | getSessionState : function(endpointUUID) { 725 | if (typeof endpointUUID !== "undefined" && endpointUUID != null) 726 | return (myEndpointProvider.getRtcommEndpoint(endpointUUID).getState()); 727 | else 728 | return ("session:stopped"); 729 | }, 730 | 731 | setAlias : function(aliasID) { 732 | if ((typeof aliasID !== "undefined") && aliasID != '') 733 | myEndpointProvider.setUserID(aliasID); 734 | }, 735 | 736 | setUserID : function(userID) { 737 | if ((typeof userID !== "undefined") && userID != ''){ 738 | RtcommConfigService.setProviderConfig({userid: userID}); 739 | myEndpointProvider.init(RtcommConfigService.getProviderConfig(), initSuccess, initFailure); 740 | } 741 | }, 742 | 743 | setPresenceTopic : function(presenceTopic) { 744 | if ((typeof presenceTopic !== "undefined") && presenceTopic != ''){ 745 | RtcommConfigService.setProviderConfig({presenceTopic : presenceTopic}); 746 | myEndpointProvider.init(RtcommConfigService.getProviderConfig(), initSuccess, initFailure); 747 | } 748 | }, 749 | 750 | getIframeURL : function(endpointUUID){ 751 | if (typeof endpointUUID !== "undefined" && endpointUUID != null){ 752 | var session = _getSession(endpointUUID); 753 | if (session != null) 754 | return (session.iFrameURL); 755 | else 756 | return(null); 757 | } 758 | else 759 | return(null); 760 | }, 761 | 762 | putIframeURL : function(endpointUUID, newUrl){ 763 | $log.debug('RtcommService: putIframeURL: endpointUUID: ' + endpointUUID + ' newURL: ' + newUrl); 764 | var endpoint = myEndpointProvider.getRtcommEndpoint(endpointUUID); 765 | 766 | if (endpoint != null){ 767 | var session = _createSession(endpointUUID); 768 | session.iFrameURL = newUrl; 769 | 770 | var message = { type : 'iFrameURL', 771 | iFrameURL : newUrl}; 772 | 773 | $log.debug('RtcommService: putIframeURL: sending new iFrame URL'); 774 | endpoint.sendOneTimeMessage(message); 775 | } 776 | }, 777 | 778 | placeCall : function(calleeID, mediaToEnable){ 779 | var endpoint = _getEndpoint(); 780 | 781 | if (mediaToEnable.indexOf('chat') > -1) 782 | endpoint.chat.enable(); 783 | 784 | if (mediaToEnable.indexOf('webrtc') > -1) { 785 | // Support turning off trickle ICE 786 | var trickleICE = true; 787 | if (mediaToEnable.indexOf('disableTrickleICE') > -1) { 788 | trickleICE = false; 789 | } 790 | endpoint.webrtc.enable({'trickleICE': trickleICE}); 791 | } 792 | _setActiveEndpoint(endpoint.id); 793 | 794 | endpoint.connect(calleeID); 795 | return(endpoint.id); 796 | }, 797 | 798 | getSessions : function(){ 799 | return(sessions); 800 | }, 801 | 802 | endCall : function(endpoint) { 803 | endpoint.disconnect(); 804 | }, 805 | 806 | setActiveEndpoint : function(endpointID){ 807 | _setActiveEndpoint(endpointID); 808 | }, 809 | 810 | getActiveEndpoint : function(){ 811 | return(_getActiveEndpointUUID()); 812 | }, 813 | 814 | getRemoteEndpoint : function(localEndpointID){ 815 | var remoteEndpointID = null; 816 | 817 | if (localEndpointID != null){ 818 | var session = _getSession(localEndpointID); 819 | 820 | if (session != null){ 821 | remoteEndpointID = session.remoteEndpointID; 822 | } 823 | } 824 | 825 | return (remoteEndpointID); 826 | }, 827 | 828 | setDefaultViewSelector : function() { 829 | _selfView = "selfView"; 830 | _remoteView = "remoteView"; 831 | }, 832 | 833 | setViewSelector : function(selfView, remoteView) { 834 | _selfView = selfView; 835 | _remoteView = remoteView; 836 | }, 837 | 838 | setVideoView : function(endpointUUID){ 839 | $log.debug('rtcommVideo: setting local media'); 840 | var endpoint = null; 841 | 842 | if (typeof endpointUUID != "undefined" && endpointUUID != null) 843 | endpoint = _getEndpoint(endpointUUID); 844 | else if (_getActiveEndpointUUID() != null) 845 | endpoint = _getEndpoint(_getActiveEndpointUUID()); 846 | 847 | if (endpoint != null){ 848 | 849 | endpoint.webrtc.setLocalMedia( 850 | { 851 | mediaOut: document.querySelector('#' + _selfView), 852 | mediaIn: document.querySelector('#' + _remoteView) 853 | }); 854 | } 855 | }, 856 | }; 857 | }; 858 | 859 | })(); 860 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-alert.html: -------------------------------------------------------------------------------- 1 |
2 | {{alert.msg}} 3 |
4 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-chat.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | Chat 5 |
6 | 7 |
8 |
    9 |
  • 10 |
    11 | {{chat.name}} 12 | 13 | {{chat.time | date:'HH:mm:ss'}} 14 | 15 |
    16 |

    {{chat.message}}

    17 |
  • 18 |
19 |
20 | 29 |
30 |
31 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-endpoint-status.html: -------------------------------------------------------------------------------- 1 |
2 | 11 |
12 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-iframe.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | URL Sharing 5 |
6 |
7 | 8 |
9 |
10 |
11 | 15 |
16 |
17 | 21 |
22 |
23 |
24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 |
32 |
-------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-modal-alert.html: -------------------------------------------------------------------------------- 1 | 5 | 8 | 12 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-modal-call.html: -------------------------------------------------------------------------------- 1 | 5 | 16 | 20 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-presence.html: -------------------------------------------------------------------------------- 1 |
6 | 9 | {{node.name}} {{node.value ? ': ' + node.value : ''}} 10 |
11 | 12 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-queues.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | Queues 5 |
6 |
7 | 8 |
9 |
10 |
11 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-register.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 6 | 7 | 8 | 9 |
10 |
11 |
12 | -------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-sessionmgr.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 9 |
10 |
11 | 12 |
-------------------------------------------------------------------------------- /src/templates/rtcomm/rtcomm-video.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 | 7 |
8 | 9 | 10 | -------------------------------------------------------------------------------- /test/sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | angular-rtcomm Sample Page 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 52 | 53 | 54 | 55 | 68 | 69 |
70 |
71 | 72 |
73 |
74 |
75 | 76 | 77 |
78 |
79 | 80 |
81 |
82 |
83 |
84 |
85 | 86 | 87 |
88 |
89 | 90 | 91 |
92 |
93 |
94 |
95 | Video 96 |
97 |
98 | 99 |
100 |
101 |
102 |
103 | Presence 104 |
105 |
106 | 107 |
108 |
109 | 110 |
111 |
112 | 116 | 120 |
121 |
122 |
123 |
124 |
125 | 126 | 127 | -------------------------------------------------------------------------------- /test/sampleConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "server" : "messagesight.demos.ibm.com", 3 | "port" : 1884, 4 | "rtcommTopicPath" : "/rtcommAngularSample/", 5 | "userid" : "", 6 | "broadcastAudio" : true, 7 | "broadcastVideo" : true, 8 | "presenceTopic" : "sampleRoom" 9 | } 10 | -------------------------------------------------------------------------------- /test/testChat.js: -------------------------------------------------------------------------------- 1 | describe('Unit testing angular-rtcomm chat', function() { 2 | var $compile, 3 | $rootScope; 4 | 5 | // Load the myApp module, which contains the directive 6 | beforeEach(module('angular-rtcomm')); 7 | 8 | // Store references to $rootScope and $compile 9 | // so they are available to all tests in this describe block 10 | beforeEach(inject(function(_$compile_, _$rootScope_){ 11 | // The injector unwraps the underscores (_) from around the parameter names when matching 12 | $compile = _$compile_; 13 | $rootScope = _$rootScope_; 14 | })); 15 | 16 | angular.mock.module('RtcommService', { 17 | widgetStorage: self.widgetStorage, 18 | widgetEditor: self.widgetEditor 19 | }); 20 | 21 | it('Replaces the element with the appropriate content', function() { 22 | // Compile a piece of HTML containing the directive 23 | var element = $compile("")($rootScope); 24 | // fire all the watches, so the scope expression {{1 + 1}} will be evaluated 25 | $rootScope.$digest(); 26 | // Check that the compiled element contains the templated content 27 | expect(element.html()).toContain("lidless, wreathed in flame, 2 times"); 28 | }); 29 | }); -------------------------------------------------------------------------------- /test/testRtcommServiceSpec.js: -------------------------------------------------------------------------------- 1 | describe('Unit testing angular-rtcomm service', function() { 2 | var $rootScope, $log; 3 | 4 | // Load the myApp module, which contains the directive 5 | var RtcommService; 6 | 7 | var rtcommTopicPath = "/testTopic/"; 8 | //var rtcommTopicPath = "/rtcomm-karma-test-" + Math.floor((Math.random() * 1000000) + 1) + "/"; 9 | 10 | var testUserID = "TestID " + Math.floor((Math.random() * 1000000) + 1); 11 | 12 | beforeEach(module('angular-rtcomm')); 13 | 14 | beforeEach(module('angular-rtcomm', function($provide) { 15 | // Output messages 16 | $provide.value('$log', console); 17 | })); 18 | 19 | beforeEach(inject(function (_RtcommService_,_$rootScope_,_$log_) { 20 | RtcommService = _RtcommService_; 21 | $rootScope = _$rootScope_; 22 | $log = _$log_; 23 | 24 | // Required to get evalAsync to fire so that broadcasted messages are received by test code. 25 | RtcommService.setKarmaTesting(); 26 | } 27 | )); 28 | 29 | describe('initialization - no user ID', function () { 30 | 31 | // Before init'ing, 32 | it('check state before init', function () { 33 | expect(RtcommService.isInitialized()).toEqual(false); 34 | }); 35 | 36 | // When init'ing with no user ID, rtcomm.js should not be init'd 37 | it('initialize with no user ID', function () { 38 | var config = { 39 | "server" : "localhost", 40 | "port" : 9080, 41 | "rtcommTopicPath" : "/rtcomm/", 42 | "userid" : "", 43 | "broadcastAudio" : true, 44 | "broadcastVideo" : true, 45 | "presenceTopic" : "karmaPresence" 46 | }; 47 | 48 | RtcommService.setConfig(config); 49 | 50 | expect(RtcommService.isInitialized()).toEqual(false); 51 | }); 52 | }); 53 | 54 | describe('Run test after initialization with user ID', function () { 55 | 56 | var presenceData = null; 57 | 58 | // When init'ing with user ID, rtcomm.js should be init'd 59 | it('initialize with user ID', function (done) { 60 | $log.debug('Karma: initialize with user ID: top: $rootScope: ',$rootScope); 61 | 62 | // spyOn($rootScope, '$broadcast').and.callThrough(); 63 | 64 | $rootScope.$on('rtcomm::init', function (event, success, details) { 65 | $log.debug('Karma: initialize with user ID: rtcomm::init received'); 66 | expect(RtcommService.isInitialized()).toEqual(true); 67 | done(); 68 | }); 69 | 70 | var config = { 71 | "server" : "localhost", 72 | "port" : 9080, 73 | "rtcommTopicPath" : "/rtcomm/", 74 | "userid" : "testUserID", 75 | "broadcastAudio" : true, 76 | "broadcastVideo" : true, 77 | "presenceTopic" : "karmaPresence" 78 | }; 79 | 80 | RtcommService.setConfig(config); 81 | }); 82 | 83 | // Here we publish presence and wait for the result to come in through a notification. 84 | it('test pubishing presence', function (done) { 85 | 86 | $rootScope.$on('rtcomm::init', function (event, success, details) { 87 | $log.debug('Karma: test pubishing presence: rtcomm::init received'); 88 | var presenceMonitor = RtcommService.getPresenceMonitor(); 89 | 90 | presenceMonitor.on('updated', function(){ 91 | 92 | presenceData = presenceMonitor.getPresenceData(); 93 | 94 | $log.debug('Karma: test pubishing presence: presenceData: ',presenceData); 95 | 96 | assert.isArray(presenceData); 97 | assert.lengthOf(presenceData, 1); 98 | assert.deepProperty(presenceData[0], "name"); 99 | assert.deepProperty(presenceData[0], "record"); 100 | assert.deepProperty(presenceData[0], "nodes"); 101 | assert.deepPropertyVal(presenceData[0], "name", "karmaPresence"); 102 | 103 | assert.isArray(presenceData[0].nodes); 104 | assert.lengthOf(presenceData[0].nodes, 1); 105 | assert.deepProperty(presenceData[0].nodes[0], "name"); 106 | assert.deepPropertyVal(presenceData[0].nodes[0], "name", "testUserID"); 107 | done(); 108 | }); 109 | 110 | presenceMonitor.add("karmaPresence"); 111 | RtcommService.publishPresence(); 112 | }); 113 | 114 | var config = { 115 | "server" : "localhost", 116 | "port" : 9080, 117 | "rtcommTopicPath" : "/rtcomm/", 118 | "userid" : "testUserID", 119 | "broadcastAudio" : true, 120 | "broadcastVideo" : true, 121 | "presenceTopic" : "karmaPresence" 122 | }; 123 | 124 | RtcommService.setConfig(config); 125 | }); 126 | }); 127 | }); --------------------------------------------------------------------------------