Chromium Code Reviews| 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 if (!this.session_connector_) { | |
| 117 this.session_connector_ = remoting.SessionConnector.factory.createConnector( | |
|
Jamie
2014/12/06 01:57:59
Optional: You could just do this in the ctor.
garykac
2014/12/06 02:15:49
I don't want to change behavior (by moving when th
| |
| 118 document.getElementById('video-container'), | |
| 119 this.onConnected.bind(this), | |
| 120 this.onError.bind(this), | |
| 121 this.onExtensionMessage.bind(this)); | |
| 122 } | |
| 123 return this.session_connector_; | |
| 124 }; | |
| 125 | |
| 126 | |
| 127 /** | |
| 128 * @interface | |
| 129 */ | |
| 130 remoting.Application.Delegate = function() {}; | |
| 131 | |
| 132 /** | |
| 133 * Initialize the application and register all event handlers. After this | |
| 134 * is called, the app is running and waiting for user events. | |
| 135 * | |
| 136 * @return {void} Nothing. | |
| 137 */ | |
| 138 remoting.Application.Delegate.prototype.init = function() {}; | |
| 139 | |
| 140 /** | |
| 141 * Called when a new session has been connected. | |
| 142 * | |
| 143 * @param {remoting.ClientSession} clientSession | |
| 144 * @return {void} Nothing. | |
| 145 */ | |
| 146 remoting.Application.Delegate.prototype.onConnected = function(clientSession) { | |
| 147 }; | |
| 148 | |
| 149 /** | |
| 150 * Called when the current session has been disconnected. | |
| 151 * | |
| 152 * @return {void} Nothing. | |
| 153 */ | |
| 154 remoting.Application.Delegate.prototype.onDisconnected = function() {}; | |
| 155 | |
| 156 /** | |
| 157 * Called when the current session has reached the point where the host has | |
| 158 * started streaming video frames to the client. | |
| 159 * | |
| 160 * @return {void} Nothing. | |
| 161 */ | |
| 162 remoting.Application.Delegate.prototype.onVideoStreamingStarted = function() {}; | |
| 163 | |
| 164 /** | |
| 165 * Called when an extension message needs to be handled. | |
| 166 * | |
| 167 * @param {string} type The type of the extension message. | |
| 168 * @param {string} data The payload of the extension message. | |
| 169 * @return {boolean} Return true if the extension message was recognized. | |
| 170 */ | |
| 171 remoting.Application.Delegate.prototype.onExtensionMessage = function( | |
| 172 type, data) {}; | |
| 173 | |
| 174 /** | |
| 175 * Called when an error needs to be displayed to the user. | |
| 176 * | |
| 177 * @param {remoting.Error} errorTag The error to be localized and displayed. | |
| 178 * @return {void} Nothing. | |
| 179 */ | |
| 180 remoting.Application.Delegate.prototype.onError = function(errorTag) {}; | |
| 181 | |
| 182 | |
| 183 /** @type {remoting.Application} */ | |
| 184 remoting.app = null; | |
| OLD | NEW |