Skip to content

Commit 001dd89

Browse files
committed
Refactor twilio-sw
1 parent 14a0972 commit 001dd89

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

example/web/twilio-sw.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const _error = (...message) => {
1414
_log('Started');
1515

1616
self.addEventListener('message', (event) => {
17-
handleMessage(event);
17+
_handleMessage(event);
1818
});
1919

2020
self.addEventListener('messageerror', (event) => {
@@ -24,39 +24,38 @@ self.addEventListener('messageerror', (event) => {
2424
self.addEventListener('notificationclick', (event) => {
2525
_log(`notificationclick event [${event.action}]`, event);
2626
event.notification.close();
27-
handleNotificationEvent(event.action, event.notification, event.notification.tag);
27+
_handleNotificationEvent(event.action, event.notification, event.notification.tag);
2828
});
2929

3030
self.addEventListener('notificationclose', (event) => {
3131
_log('notificationclose event', event);
3232
event.notification.close();
33-
handleNotificationEvent(null, event.data, event.tag);
33+
_handleNotificationEvent(null, event.data, event.tag);
3434
});
3535

3636
function _handleNotificationEvent(action, payload, tag) {
37-
function handleNotificationEvent(action, payload, tag) {
3837
const message = {
3938
tag: tag,
4039
}
4140
switch (action) {
4241
case 'answer': {
43-
focusClientWindow();
44-
sendToClient(action, message);
42+
_focusClientWindow();
43+
_sendToClient(action, message);
4544
break;
4645
}
4746
case 'hangup':
4847
case 'reject': {
49-
sendToClient(action, message);
48+
_sendToClient(action, message);
5049
break;
5150
}
5251
default: {
53-
focusClientWindow();
52+
_focusClientWindow();
5453
break;
5554
}
5655
}
5756
}
5857

59-
function sendToClient(action, payload) {
58+
function _sendToClient(action, payload) {
6059
const message = {
6160
action: action,
6261
payload: payload
@@ -68,7 +67,7 @@ function sendToClient(action, payload) {
6867
});
6968
}
7069

71-
function focusClientWindow() {
70+
function _focusClientWindow() {
7271
self.clients.matchAll({
7372
type: "window",
7473
}).then((clients) => {
@@ -81,7 +80,7 @@ function focusClientWindow() {
8180
});
8281
}
8382

84-
function handleMessage(event) {
83+
function _handleMessage(event) {
8584
if (!event) {
8685
_error('No event');
8786
return;

0 commit comments

Comments
 (0)