You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-20Lines changed: 11 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -166,17 +166,17 @@ See [example](https://github.com/cybex-dev/twilio_voice/blob/master/example/andr
166
166
There are 4 important files for Twilio incoming/missed call notifications to work:
167
167
168
168
-`notifications.js` is the main file, it handles the notifications and the service worker.
169
-
-`twilio-sw.js` is the service worker _content_ used to work with the default flutter service worker (this can be found in `build/web/flutter_service_worker.js`). This file's contents are copied into the flutter service worker.
169
+
-`twilio-sw.js` is the service worker _content_ used to work with the default `flutter_service_worker.js`(this can be found in `build/web/flutter_service_worker.js` after calling `flutter build web`). This file's contents are to be copied into the `flutter_service_worker.js` file after you've built your application.
170
170
171
171
Also, the twilio javascript SDK itself, `twilio.min.js` is needed.
172
172
173
-
To ensure proper/as intended setup:
173
+
### To ensure proper/as intended setup:
174
174
175
-
1.Locate 3 files (`twilio.min.js`, `notifications.js` and `twilio-sw.js`) from `example/web` folder
176
-
2.Copy all 3 files into your own project,
177
-
3. (optional) Review & change the `notifications.js`, `twilio-sw.js`files to match your needs.
178
-
4. Build your application with `flutter build web` (or `flutter run -d chrome` to test locally), this will create a `build/web` folder.
179
-
5. Copy the content of `example/web/twilio-sw.js` into your `build/web/flutter_service_worker.js` file, **at the end of the file**.
175
+
1.Copy files `example/web/notifications.js` and `example/web/twilio.min.js` into your application's `web` folder.
176
+
2.This step should be done AFTER you've built your application, every time the `flutter_service_worker.js` changes (this includes hot reloads on your local machine unfortunately)
177
+
1. Copy the contents of `example/web/twilio-sw.js` into your `build/web/flutter_service_worker.js`file, **at the end of the file**. See [service-worker](#service-worker) for more information.
178
+
179
+
Note, these files can be changed to suite your needs - however the core functionality should remain the same: responding to `notificationclick`, `notificationclose`, `message` events and associated sub-functions.
180
180
181
181
Finally, add the following code to your `index.html` file, **at the end of body tag**:
182
182
@@ -186,25 +186,16 @@ Finally, add the following code to your `index.html` file, **at the end of body
console.log('Twilio Voice Service worker registered successfully.');
195
-
}).catch((error) => {
196
-
console.warn('Error registering Twilio Service Worker: '+error.message+'. This prevents notifications from working natively');
197
-
});
198
-
});
199
-
}
200
-
</script>
191
+
window.addEventListener('load', function(ev) {
192
+
// Download main.dart.js
193
+
...
201
194
</body>
202
195
```
203
196
204
197
#### Web Considerations
205
198
206
-
Notice should be given to using `firebase-messaging-sw.js` in addition to `twilio-sw.js` since these may cause conflict in service worker events being handled. Until such a time Flutter provides an appropriate mechanism to integrate with service workers, the suggested solution of post compilation merging of service workers is the best solution.
207
-
208
199
_If you need to debug the service worker, open up Chrome Devtools, go to Application tab, and select Service Workers from the left menu. There you can see the service workers and their status.
209
200
To review service worker `notificationclick`, `notificationclose`, `message`, etc events - do this using Chrome Devtools (Sources tab, left panel below 'site code' the service workers are listed)_
0 commit comments