-
Notifications
You must be signed in to change notification settings - Fork 9
/
preload.js
80 lines (77 loc) · 2.19 KB
/
preload.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
const { ipcRenderer } = require('electron');
// listen message from Embeddable widget
window.addEventListener('message', function (event) {
const data = event.data;
if (!data) {
return;
}
let notification;
switch (data.type) {
case 'rc-call-ring-notify':
// get call on ring event
ipcRenderer.send('show-main-window');
const call = data.call;
notification = new Notification('New Call', {
body: `Incoming Call from ${call.fromUserName || call.from}`
});
notification.onclick = () => {
// answer the call directly
// dispatchMessage({
// type: 'rc-adapter-control-call',
// callAction: 'answer',
// callId: call.id,
// });
ipcRenderer.send('show-main-window');
};
// notification.onclose = () => {
// dispatchMessage({
// type: 'rc-adapter-control-call',
// callAction: 'reject',
// callId: call.id,
// });
// }
break;
case 'rc-inbound-message-notify':
const message = data.message;
notification = new Notification('New Message', {
body: `Message from: ${message.from && (message.from.phoneNumber || message.from.extensionNumber)}`,
});
notification.onclick = () => {
ipcRenderer.send('show-main-window');
};
break
case 'rc-dialer-status-notify':
if (data.ready) {
ipcRenderer.send('dialer-ready');
}
default:
break;
}
});
function sendMessageToEmbeddableWidget(message) {
window.postMessage(message, window.origin);
}
// listen message from main process
ipcRenderer.on('main-message', function (e, message) {
switch (message.type) {
case 'click-to-dial':
sendMessageToEmbeddableWidget({
type: 'rc-adapter-new-call',
phoneNumber: message.phoneNumber,
toCall: true,
});
break;
case 'click-to-sms':
sendMessageToEmbeddableWidget({
type: 'rc-adapter-new-sms',
phoneNumber: message.phoneNumber,
});
break;
case 'rc-adapter-set-environment':
sendMessageToEmbeddableWidget({
type: 'rc-adapter-set-environment',
});
default:
break;
}
});