Skip to content

Commit fd1564a

Browse files
committed
Updated readme
1 parent d7d70f3 commit fd1564a

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

README.md

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ See [example](https://github.com/cybex-dev/twilio_voice/blob/master/example/andr
166166
There are 4 important files for Twilio incoming/missed call notifications to work:
167167

168168
- `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.
170170

171171
Also, the twilio javascript SDK itself, `twilio.min.js` is needed.
172172

173-
To ensure proper/as intended setup:
173+
### To ensure proper/as intended setup:
174174

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.
180180

181181
Finally, add the following code to your `index.html` file, **at the end of body tag**:
182182

@@ -186,25 +186,16 @@ Finally, add the following code to your `index.html` file, **at the end of body
186186
<!--twilio native js library-->
187187
<script type="text/javascript" src="./twilio.min.js"></script>
188188
<!--End Twilio Voice impl-->
189-
189+
190190
<script>
191-
if ('serviceWorker' in navigator) {
192-
window.addEventListener('load', async () => {
193-
await navigator.serviceWorker.register('twilio-sw.js').then(value => {
194-
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+
...
201194
</body>
202195
```
203196
204197
#### Web Considerations
205198
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-
208199
_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.
209200
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)_
210201

0 commit comments

Comments
 (0)