connectivity.js
6.31 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2015 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
define('screens/player/ui/connectivity', [
'jquery',
'./tooltip',
'screens/player/firmware/core/bridge'
], function($, Tooltip, Bridge) {
'use strict';
/**
* Default options for the component.
*
* @typedef {Object} Connectivity.ConnectivityOptions
* @type {Object}
* @property {Object} [tooltip] Options for the tooltip.
* @property {String} [tooltip.title] Title to add to the tooltip.
* @property {String} [tooltip.content] Text to add to the tooltip.
* @property {String} [tooltip.css] A css class to add to the tooltip.
* @property {Object} [displayLayout] The display configuration
* @property {Number} [displayLayout.numRows] Number of rows of displays
* @property {Number} [displayLayout.numCols] Number of columns of displays
* @property {String} [type] Connectivity indicator type ('disabled', 'spinner*, 'minimal')
* @property {String} [typeDefault] Connectivity default indicator type ('disabled', 'spinner'*, 'minimal')
*/
var DEFAULTS = {
tooltip: {
title: 'AEM',
content: 'Screens',
css: 'aem-ScreensPlayer-tooltip--loading'
},
displayLayout: {
numRows: 1,
numCols: 1
},
type: '',
typeDefault: 'spinner',
bridge: null
};
/**
* Get the overlay for the component.
*
* @return {Overlay|null} The initialized overlay, or null
*/
var getOverlay = function() {
if (!this.overlay) {
this.overlay = this.options.overlay;
}
return this.overlay || null;
};
/**
* Gets the tooltip for the player if it exists.
*
* @return {Tooltip|null} The initialised tooltip
*/
var getTooltip = function() {
if (!this.tooltip) {
this.tooltip = Tooltip && new Tooltip({
title: this.options.tooltip.title,
content: this.options.tooltip.content,
css: this.options.tooltip.css,
displayLayout: this.options.displayLayout
});
}
return this.tooltip || null;
};
var getMinimalIndicator = function() {
if (!this.$mini) {
this.$mini = $('<div/>').addClass('aem-ScreensPlayer-mini-indicator').appendTo($('body'));
}
return this.$mini;
};
var handleBridgeLinkUp = function() {
this.hideLoadingIndicator();
};
var handleBridgeLinkDown = function() {
switch (this.type) {
case 'spinner':
this.showLoadingIndicator();
break;
case 'minimal':
this.showMinimalIndicator();
break;
}
};
var handleBridgeData = function(data) {
try {
this.type = data.device ? data.device.offlineIndicator : this.options.typeDefault;
console.log('Offline indicator type set to: ' + this.type);
} catch (e) {
console.error(e);
}
};
/**
* Connectivity checker for the player.
*
* @class Connectivity
*
* @param {Connectivity.ConnectivityOptions} [options] Options for the component.
*/
var Connectivity = function(options) {
this.options = $.extend({}, DEFAULTS, options);
// FIXME: need to rework the connectivity state display. we should only show the spinner:
// - during startup until the handshake is done
// - if a online channel is selected, but the link is down
this.options.bridge.on(Bridge.events.STARTED, handleBridgeLinkDown.bind(this));
this.options.bridge.on(Bridge.events.HANDSHAKE_COMPLETED, handleBridgeLinkUp.bind(this));
// this.options.bridge.on('bridge-fallback', handleBridgeLinkUp.bind(this));
// this.options.bridge.on('bridge-link-up', handleBridgeLinkUp.bind(this));
// this.options.bridge.on('bridge-link-down', handleBridgeLinkDown.bind(this));
this.options.bridge.on(Bridge.events.DATA, handleBridgeData.bind(this));
this.type = this.options.type || this.options.typeDefault;
};
/**
* Show the loading indicator.
* @memberof Connectivity
*
* @param {Function} [cb] Callback function
*/
Connectivity.prototype.showLoadingIndicator = function(cb) {
var overlay = getOverlay.call(this);
if (overlay) {
overlay.show();
} else {
console.warn('Overlay module not loaded');
}
var tooltip = getTooltip.call(this);
if (tooltip) {
tooltip.show(false, cb);
} else {
console.warn('Tooltip module not loaded');
}
};
/**
* Show the loading indicator.
* @memberof Connectivity
*/
Connectivity.prototype.showMinimalIndicator = function() {
var $mini = getMinimalIndicator.call(this);
$mini.show();
};
/**
* Hide the loading indicator.
* @memberof Connectivity
*/
Connectivity.prototype.hideLoadingIndicator = function() {
if (this.tooltip) {
this.tooltip.hide();
}
if (this.overlay) {
this.overlay.hide();
}
if (this.$mini) {
this.$mini.hide();
}
};
/**
* Destroy the connectivity checker.
* @memberof Connectivity
*/
Connectivity.prototype.destroy = function() {
if (this.tooltip) {
this.tooltip.destroy();
this.tooltip = null;
}
if (this.overlay) {
this.overlay = null;
}
};
return Connectivity;
});