-
Notifications
You must be signed in to change notification settings - Fork 8
/
crd_event_handlers.js
97 lines (94 loc) · 4.13 KB
/
crd_event_handlers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
96
97
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
remoting.initElementEventHandlers = function() {
var goHome = function() {
remoting.setMode(remoting.AppMode.HOME);
};
var goEnterAccessCode = function() {
// We don't need a token until we authenticate, but asking for one here
// handles the token-expired case earlier, avoiding asking the user for
// the access code both before and after re-authentication.
remoting.identity.callWithToken(
/** @param {string} token */
function(token) {
remoting.setMode(remoting.AppMode.CLIENT_UNCONNECTED);
},
remoting.showErrorMessage);
};
var goFinishedIT2Me = function() {
if (remoting.currentMode == remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME) {
remoting.setMode(remoting.AppMode.CLIENT_UNCONNECTED);
} else {
goHome();
}
};
/** @param {Event} event The event. */
var sendAccessCode = function(event) {
remoting.connectIT2Me();
event.preventDefault();
};
var reconnect = function() {
remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
remoting.app.getSessionConnector().reconnect();
};
/** @param {Event} event The event. */
var stopDaemon = function(event) {
remoting.hostSetupDialog.showForStop();
event.stopPropagation();
};
var cancelAccessCode = function() {
remoting.setMode(remoting.AppMode.HOME);
document.getElementById('access-code-entry').value = '';
};
/** @type {Array<{event: string, id: string, fn: function(Event):void}>} */
var it2me_actions = [
{ event: 'click', id: 'access-mode-button', fn: goEnterAccessCode },
{ event: 'submit', id: 'access-code-form', fn: sendAccessCode },
{ event: 'click', id: 'cancel-access-code-button', fn: cancelAccessCode},
{ event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare },
{ event: 'click', id: 'client-finished-it2me-button', fn: goHome },
{ event: 'click', id: 'get-started-it2me',
fn: remoting.showIT2MeUiAndSave },
{ event: 'click', id: 'host-finished-button', fn: goHome },
{ event: 'click', id: 'share-button', fn: remoting.tryShare }
];
/** @type {Array<{event: string, id: string, fn: function(Event):void}>} */
var me2me_actions = [
{ event: 'click', id: 'change-daemon-pin',
fn: function() { remoting.hostSetupDialog.showForPin(); } },
{ event: 'click', id: 'client-finished-me2me-button', fn: goHome },
{ event: 'click', id: 'client-reconnect-button', fn: reconnect },
{ event: 'click', id: 'daemon-pin-cancel', fn: goHome },
{ event: 'click', id: 'get-started-me2me',
fn: remoting.showMe2MeUiAndSave },
{ event: 'click', id: 'start-daemon',
fn: function() { remoting.hostSetupDialog.showForStart(); } },
{ event: 'click', id: 'stop-daemon', fn: stopDaemon }
];
/** @type {Array<{event: string, id: string, fn: function(Event):void}>} */
var host_actions = [
{ event: 'click', id: 'close-paired-client-manager-dialog', fn: goHome },
{ event: 'click', id: 'host-config-done-dismiss', fn: goHome },
{ event: 'click', id: 'host-config-error-dismiss', fn: goHome },
{ event: 'click', id: 'open-paired-client-manager-dialog',
fn: remoting.setMode.bind(null,
remoting.AppMode.HOME_MANAGE_PAIRINGS) },
{ event: 'click', id: 'stop-sharing-button', fn: remoting.cancelShare }
];
/** @type {Array<{event: string, id: string, fn: function(Event):void}>} */
var auth_actions = [
{ event: 'click', id: 'cancel-connect-button', fn: goHome },
{ event: 'click', id: 'sign-out', fn:remoting.signOut },
{ event: 'click', id: 'token-refresh-error-ok', fn: goHome },
{ event: 'click', id: 'token-refresh-error-sign-in',
fn: remoting.handleAuthFailureAndRelaunch }
];
registerEventListeners(it2me_actions);
registerEventListeners(me2me_actions);
registerEventListeners(host_actions);
registerEventListeners(auth_actions);
}