-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathclient.js
More file actions
126 lines (106 loc) · 3.28 KB
/
client.js
File metadata and controls
126 lines (106 loc) · 3.28 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
/* globals CONFIG, GC, logger */
var dispatchWindowEvent = function(eventName) {
var e = document.createEvent('Event');
e.initEvent(eventName, true, true);
window.dispatchEvent(e);
};
exports.onLaunch = function () {
var deviceId = CONFIG.simulator.deviceId;
var deviceType = CONFIG.simulator.deviceType;
var deviceInfo = CONFIG.simulator.deviceInfo;
import .simulateDevice;
simulateDevice.simulate(deviceInfo);
import devkit.debugging;
var channel = devkit.debugging.getChannel('devkit-simulator');
var _isHomeScreen = false;
channel.on('button:home', function () {
var app = GC.app;
_isHomeScreen = !_isHomeScreen;
if (_isHomeScreen) {
dispatchWindowEvent('pagehide');
app.engine.pause();
var canvas = document.getElementsByTagName('canvas');
if (canvas.length) {
canvas = canvas[0];
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#000000';
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
}
} else {
dispatchWindowEvent('pageshow');
app.engine.resume();
}
});
channel.on('button:back', function (evt) {
GLOBAL.NATIVE.onBackButton && GLOBAL.NATIVE.onBackButton(evt);
});
/** Puts preserveCache on localStorage so that jsio knows to preserve (and then request)
suggestions next load. Optionally also sets partialLoad, which causes jsio to wait for
a partialLoadContinue signal to actually load the app, after preloading suggestions. */
channel.on('reload', function (data, req) {
localStorage.setItem(jsio.__env.getNamespace('preserveCache'), true);
if (data) {
if (data.partialLoad) {
localStorage.setItem(jsio.__env.getNamespace('partialLoad'), true);
}
}
req.send(true);
});
/** partialLoadContinue is to be used in conjunction with partialLoad */
channel.on('partialLoadContinue', function (data, req) {
var cb = window._continueLoadCallback;
if (cb) {
cb();
}
req.send(true);
});
channel.on('screenshot', function (data, req) {
devkit.debugging.screenshot(function (err, res) {
if (err) {
req.error(err);
} else {
req.send(res);
}
});
});
channel.on('mute', function (evt) {
console.log('MUTE', evt.shouldMute);
import AudioManager;
AudioManager.muteAll(evt.shouldMute);
});
channel.on('pause', function () { exports.setPaused(true); });
channel.on('resume', function () { exports.setPaused(false); });
channel.on('step', function () { GC.app.engine.stepFrame(); });
logger.log('waiting for devkit simulator client...');
import device;
if (device.isMobileBrowser) {
import .mobileUI;
}
return channel.connect()
.timeout(1000)
.then(function () {
logger.log('simulator client connected!');
channel.emit('handshake', {
deviceId: deviceId,
deviceType: deviceType,
userAgent: navigator.userAgent,
screen: {
width: device.screen.width,
height: device.screen.height
}
});
});
};
var _isPaused = false;
exports.setPaused = function (isPaused) {
_isPaused = isPaused;
var app = GC.app;
if (_isPaused) {
console.log("app paused");
app.engine.pause();
} else {
app.engine.resume();
}
};