Skip to content

Commit 6691a25

Browse files
committed
Update readme
1 parent 547cac9 commit 6691a25

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,28 @@ See [example](https://github.com/cybex-dev/twilio_voice/blob/master/example/andr
165165

166166
There are 4 important files for Twilio incoming/missed call notifications to work:
167167

168-
- `twilio.min.js` is the twilio javascript SDK, it is used to handle the incoming calls.
169168
- `notifications.js` is the main file, it handles the notifications and the service worker.
170-
- `load-sw.js` is responsible for (re)loading the twilio service worker.
171-
- `twilio-sw.js` is the service worker, it is used to handle the incoming calls.
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.
172170

173171
Also, the twilio javascript SDK itself, `twilio.min.js` is needed.
174172

175173
To ensure proper/as intended setup:
176174

177-
1. Locate 4 files (`twilio.min.js`, `load-sw.js`, `notifications.js` and `twilio-sw.js`) from `example/web` folder
178-
2. Copy all 4 files into your own project,
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,
179177
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**.
180180

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

183183
```html
184184
<body>
185+
<!--Start Twilio Voice impl-->
185186
<!--twilio native js library-->
186187
<script type="text/javascript" src="./twilio.min.js"></script>
187-
188-
<!--load twilio service worker-->
189-
<script type="text/javascript" src="./load-sw.js"></script>
190-
188+
<!--End Twilio Voice impl-->
189+
191190
<script>
192191
if ('serviceWorker' in navigator) {
193192
window.addEventListener('load', async () => {
@@ -204,11 +203,28 @@ Finally, add the following code to your `index.html` file, **at the end of body
204203

205204
#### Web Considerations
206205

207-
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.
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.
208207

209208
_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.
210209
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)_
211210

211+
##### Service Worker
212+
213+
Unifying the service worker(s) is best done via post-compilation tools or a CI/CD pipeline (suggested).
214+
215+
A snippet of the suggested service worker integration is as follows:
216+
217+
```yaml
218+
#...
219+
- run: cd ./example; flutter build web --release --target=lib/main.dart --output=build/web
220+
221+
- name: Update service worker
222+
run: cat ./example/web/twilio-sw.js > ./example/build/web/flutter_service_worker.js
223+
#...
224+
```
225+
226+
A complete example could be found in the github workflows `.github/workflows/flutter.yml` file, see [here](https://github.com/cybex-dev/twilio_voice/blob/master/.github/workflows/flutter.yml).
227+
212228
##### Web Notifications
213229

214230
2 types of notifications are shown:

0 commit comments

Comments
 (0)