-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.js
109 lines (103 loc) · 3.8 KB
/
webapp.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
98
99
100
101
102
103
104
105
106
107
108
109
var SDK = require("./bin/retrieveSDKInfo");
module.exports = {
// mongoose schema, if you need project-specific config
config: {
"template": {
environment: {type: String, default: 'Hi from `environment`'},
prepare: {type: String, default: 'Hi from `prepare`'},
test: {type: String, default: 'Hi from `test`'},
deploy: {type: String, default: 'Hi from `deploy`'},
cleanup: {type: String, default: 'Hi from `cleanup`'},
device: {type: String, default: ''}
}
},
// Define project-specific routes
// all routes created here are namespaced within /:org/:repo/api/:pluginid
// req.project is the current project
// req.accessLevel is the current user's access level for the project
// 0 - anonymous, 1 - authed, 2 - admin / collaborator
// req.user is the current user
// req.pluginConfig() -> get the config for this plugin
// req.pluginConfig(config, cb(err)) -> set the config for this plugin
routes: function (app, context) {
/*app.get('/devices', function(req, res) {
SDK.getDeviceList( function (result) {
res.json(result);
});
});*/
},
/*
if project specific, try api/:pluginid
global, try /ext/pluginid/myroute
*/
// Define global routes
// all routes namespaced within /ext/:pluginid
// req.user is the current user
// req.user.account_level can be used for authorization
// 0 - anonymous, 1 - authed, 2 - admin / collaborator
globalRoutes: function (app, context) {
app.get('/devices', function(req, res) {
var sdkLocation = req.param('sdk');
SDK.getDeviceList(sdkLocation, function (err, emulators, physicals) {
var data = {
error: err,
result: {
emulators: emulators,
physicals: physicals,
}
}
res.json(data);
});
});
app.get('/targets', function(req, res) {
var sdkLocation = req.param('sdk');
SDK.getTargetList(sdkLocation, function (err, result) {
var data = {
error: err,
result: result
}
res.json(data);
});
});
app.post('/devices', function(req, res) {
//prepare to add the device
SDK.addDevice(req.body, function (err, result) {
var data = {
error: err,
result: result
}
res.send(data);
});
});
app.put('/devices', function(req, res) {
SDK.deleteDevice(req.body, function (err, result) {
var data = {
error: err,
result: result
}
res.send(data);
});
});
app.put('/stop', function(req, res) {
SDK.stopEmulator(req.body, function (err, result) {
var data = {
error: err,
result: result
}
res.send(data);
});
});
},
// Listen for global events
// all job-local events that begin with `plugin.` are proxied to
// the main strider eventemitter, so you can listen for them here.
// Other events include `job.new`, `job.done` and `browser.update`.
listen: function (emitter, context) {
emitter.on('branch.plugin_config', function (project, branch, plugin, body) {
//update android device list when any changes occur
/*SDK.getDeviceList( function (result) {
console.log(result);
});*/
});
}
};