OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview |
| 7 * Interface abstracting the Application functionality. |
| 8 */ |
| 9 |
| 10 'use strict'; |
| 11 |
| 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; |
| 14 |
| 15 /** |
| 16 * @constructor |
| 17 */ |
| 18 remoting.Application = function() { |
| 19 /** |
| 20 * @type {remoting.Application.Delegate} |
| 21 * @private |
| 22 */ |
| 23 this.delegate_ = null; |
| 24 |
| 25 /** |
| 26 * @type {remoting.SessionConnector} |
| 27 * @private |
| 28 */ |
| 29 this.session_connector_ = null; |
| 30 }; |
| 31 |
| 32 /** |
| 33 * @param {remoting.Application.Delegate} appDelegate The delegate that |
| 34 * contains the app-specific functionality. |
| 35 */ |
| 36 remoting.Application.prototype.setDelegate = function(appDelegate) { |
| 37 this.delegate_ = appDelegate; |
| 38 }; |
| 39 |
| 40 /** |
| 41 * Initialize the application and register all event handlers. After this |
| 42 * is called, the app is running and waiting for user events. |
| 43 * |
| 44 * @return {void} Nothing. |
| 45 */ |
| 46 remoting.Application.prototype.init = function() { |
| 47 this.delegate_.init(); |
| 48 }; |
| 49 |
| 50 /** |
| 51 * Called when a new session has been connected. |
| 52 * |
| 53 * @param {remoting.ClientSession} clientSession |
| 54 * @return {void} Nothing. |
| 55 */ |
| 56 remoting.Application.prototype.onConnected = function(clientSession) { |
| 57 // TODO(garykac): Make clientSession a member var of Application. |
| 58 remoting.clientSession = clientSession; |
| 59 remoting.clientSession.addEventListener('stateChanged', onClientStateChange_); |
| 60 |
| 61 remoting.clipboard.startSession(); |
| 62 updateStatistics_(); |
| 63 remoting.hangoutSessionEvents.raiseEvent( |
| 64 remoting.hangoutSessionEvents.sessionStateChanged, |
| 65 remoting.ClientSession.State.CONNECTED |
| 66 ); |
| 67 |
| 68 this.delegate_.onConnected(clientSession); |
| 69 }; |
| 70 |
| 71 /** |
| 72 * Called when the current session has been disconnected. |
| 73 * |
| 74 * @return {void} Nothing. |
| 75 */ |
| 76 remoting.Application.prototype.onDisconnected = function() { |
| 77 this.delegate_.onDisconnected(); |
| 78 }; |
| 79 |
| 80 /** |
| 81 * Called when the current session has reached the point where the host has |
| 82 * started streaming video frames to the client. |
| 83 * |
| 84 * @return {void} Nothing. |
| 85 */ |
| 86 remoting.Application.prototype.onVideoStreamingStarted = function() { |
| 87 this.delegate_.onVideoStreamingStarted(); |
| 88 }; |
| 89 |
| 90 /** |
| 91 * Called when an extension message needs to be handled. |
| 92 * |
| 93 * @param {string} type The type of the extension message. |
| 94 * @param {string} data The payload of the extension message. |
| 95 * @return {boolean} Return true if the extension message was recognized. |
| 96 */ |
| 97 remoting.Application.prototype.onExtensionMessage = function(type, data) { |
| 98 return this.delegate_.onExtensionMessage(type, data); |
| 99 }; |
| 100 |
| 101 /** |
| 102 * Called when an error needs to be displayed to the user. |
| 103 * |
| 104 * @param {remoting.Error} errorTag The error to be localized and displayed. |
| 105 * @return {void} Nothing. |
| 106 */ |
| 107 remoting.Application.prototype.onError = function(errorTag) { |
| 108 this.delegate_.onError(errorTag); |
| 109 }; |
| 110 |
| 111 /** |
| 112 * @return {remoting.SessionConnector} A session connector, creating a new one |
| 113 * if necessary. |
| 114 */ |
| 115 remoting.Application.prototype.getSessionConnector = function() { |
| 116 // TODO(garykac): Check if this can be initialized in the ctor. |
| 117 if (!this.session_connector_) { |
| 118 this.session_connector_ = remoting.SessionConnector.factory.createConnector( |
| 119 document.getElementById('video-container'), |
| 120 this.onConnected.bind(this), |
| 121 this.onError.bind(this), |
| 122 this.onExtensionMessage.bind(this)); |
| 123 } |
| 124 return this.session_connector_; |
| 125 }; |
| 126 |
| 127 |
| 128 /** |
| 129 * @interface |
| 130 */ |
| 131 remoting.Application.Delegate = function() {}; |
| 132 |
| 133 /** |
| 134 * Initialize the application and register all event handlers. After this |
| 135 * is called, the app is running and waiting for user events. |
| 136 * |
| 137 * @return {void} Nothing. |
| 138 */ |
| 139 remoting.Application.Delegate.prototype.init = function() {}; |
| 140 |
| 141 /** |
| 142 * Called when a new session has been connected. |
| 143 * |
| 144 * @param {remoting.ClientSession} clientSession |
| 145 * @return {void} Nothing. |
| 146 */ |
| 147 remoting.Application.Delegate.prototype.onConnected = function(clientSession) { |
| 148 }; |
| 149 |
| 150 /** |
| 151 * Called when the current session has been disconnected. |
| 152 * |
| 153 * @return {void} Nothing. |
| 154 */ |
| 155 remoting.Application.Delegate.prototype.onDisconnected = function() {}; |
| 156 |
| 157 /** |
| 158 * Called when the current session has reached the point where the host has |
| 159 * started streaming video frames to the client. |
| 160 * |
| 161 * @return {void} Nothing. |
| 162 */ |
| 163 remoting.Application.Delegate.prototype.onVideoStreamingStarted = function() {}; |
| 164 |
| 165 /** |
| 166 * Called when an extension message needs to be handled. |
| 167 * |
| 168 * @param {string} type The type of the extension message. |
| 169 * @param {string} data The payload of the extension message. |
| 170 * @return {boolean} Return true if the extension message was recognized. |
| 171 */ |
| 172 remoting.Application.Delegate.prototype.onExtensionMessage = function( |
| 173 type, data) {}; |
| 174 |
| 175 /** |
| 176 * Called when an error needs to be displayed to the user. |
| 177 * |
| 178 * @param {remoting.Error} errorTag The error to be localized and displayed. |
| 179 * @return {void} Nothing. |
| 180 */ |
| 181 remoting.Application.Delegate.prototype.onError = function(errorTag) {}; |
| 182 |
| 183 |
| 184 /** @type {remoting.Application} */ |
| 185 remoting.app = null; |
OLD | NEW |