-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathandroidcontroller-onx.js
96 lines (83 loc) · 3.06 KB
/
androidcontroller-onx.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
var originalCallVolume,
originalRingerMode,
currentPhoneNumber,
textMessageRequested = false;
device.telephony.on('incomingCall', function (signal) {
//device.notifications.createNotification("INCOMING! " + signal.phoneNumber).show();
originalCallVolume = device.audio.ringerVolume,
originalRingerMode = device.audio.ringerMode;
console.info(signal);
currentPhoneNumber = signal.phoneNumber;
device.scheduler.setTimer({
name: "checkingForInCallInputs",
time: 0,
interval: 5*1000,
exact: false
},
function () {
checkIfPhoneShouldBeSilent();
}
);
});
device.telephony.on('idle', function () {
//device.notifications.createNotification("No longer in a call, I'll stop asking.").show();
device.scheduler.removeTimer("checkingForInCallInputs");
returnToPhoneDefaults();
});
function checkIfPhoneShouldBeSilent() {
//device.notifications.createNotification('Asking if I should be silent...').show();
device.ajax({
url: 'http://androidcontroller.herokuapp.com/shouldibesilent',
type: 'POST',
dataType: 'json',
data: '{"call":"incoming"}',
headers: {'Content-Type':'application/json'}
}, function onSuccess(body, textStatus, response) {
var JSONResponse = JSON.parse(body);
console.info('successfully received http response!');
//device.notifications.createNotification('Got a response from server').show();
console.info(JSON.stringify(JSONResponse));
//device.notifications.createNotification('It said ' + JSONResponse.callSound).show();
if (JSONResponse.callSound === false) {
device.notifications.createNotification('Busy request sent, sending a text').show();
device.audio.ringerVolume = 0;
if (!textMessageRequested) {
textMessageRequested = true;
device.messaging.sendSms({
to: currentPhoneNumber,
body: 'Sorry! In the middle of a technological breakthrough. I\'ll call you back!'
},
function (err) {
console.log(err || 'sms was sent successfully');
});
}
}
}, function onError(textStatus, response) {
var error = {};
error.message = textStatus;
error.statusCode = response.status;
console.error('error: ',error);
});
}
function returnToPhoneDefaults() {
device.audio.ringerVolume = originalCallVolume;
device.audio.ringerMode = originalRingerMode;
textMessageRequested = false;
device.ajax({
url: 'http://yourappurlhere.com/call',
type: 'POST',
dataType: 'json',
data: '{"action":"reset"}',
headers: {'Content-Type':'application/json'}
}, function onSuccess(body, textStatus, response) {
var JSONResponse = JSON.parse(body);
console.info('Successfully got a response after asking to reset the call state');
//device.notifications.createNotification('Successfully got a response after asking to reset the call state').show();
console.info(JSON.stringify(JSONResponse));
}, function onError(textStatus, response) {
var error = {};
error.message = textStatus;
error.statusCode = response.status;
console.error('error: ',error);
});
}