Skip to content

Commit 9fdd508

Browse files
committed
Merge branch 'feat_webcallkit'
2 parents 392e1c5 + d1c7288 commit 9fdd508

File tree

9 files changed

+385
-475
lines changed

9 files changed

+385
-475
lines changed

.github/workflows/flutter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ jobs:
6161
- run: flutter config --enable-web
6262
- run: cd ./example; flutter build web --release --target=lib/main.dart --output=build/web
6363

64-
- name: Update service worker
65-
run: cat ./example/service-worker/twilio-sw.js >> ./example/build/web/flutter_service_worker.js
64+
# - name: Update service worker
65+
# run: cat ./example/service-worker/twilio-sw.js >> ./example/build/web/flutter_service_worker.js
6666

6767
- name: Archive Production Artifact
6868
uses: actions/upload-artifact@master

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Next Release
22

3+
* Docs: update README, NOTES & CHANGELOG
4+
* Feat: [Web] Add [web_callkit](https://pub.dev/packages/web_callkit) support.
35
* Feat: [Web] Update example with custom incoming ringtone field.
46
* Feat: [Web] Add custom sounds for Twilio Device using `updateSound(SoundName, String?)` or `updateSounds(Map<String, String>)` methods.
57
* Fix: [Android] `call.isOnCall()` returns true when call is declined
@@ -9,7 +11,6 @@
911
* Fix: [macOS] Remove deprecated `.alert` presentation option. [@AndreiMisiukevich](https://github.com/AndreiMisiukevich)
1012
* Feat: [macOS] Add native microphone permission with `AVCaptureDevice` (this replaces `getUserMedia()` from js interop available on localhost/https only). [@AndreiMisiukevich](https://github.com/AndreiMisiukevich)
1113
* Fix/Update: [macOS] correct runtime entitlement for `audio-input` permission. [@AndreiMisiukevich](https://github.com/AndreiMisiukevich)
12-
* Update Readme
1314

1415
## 0.2.2
1516

NOTES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11

22
# Notes
33

4+
### Web
5+
6+
Web implementation relies on the [js_notifications](https://pub.dev/packages/js_notifications) package for browser notifications. These notifications including Call functionality is used by a middleware package [web_callkit](https://pub.dev/packages/web_callkit) which provides boilerplate for call management and browser notification integration.
7+
8+
- `js_notifications` requires the service worker file `js_notifications-sw.js` to be copied to your web directory. This file is used for handling notifications in the background.
9+
- `web_callkit` provides the boilerplate for call management and browser notification integration, however this package requires both files used in `js_notifications` package.
10+
11+
Further, and most importantly the `twilio_voice` package makes use of custom [twilio_voice.js](https://github.com/twilio/twilio-voice.js/) implementation (these changes are purely to provided Flutter status outputs allowing Flutter to monitor the status of the Twilio Device).
12+
13+
The javascript files required by `twilio_voice` is `twilio.min.js`, which is found in the `example/web` folder. This may in future be loaded dynamically, but for now is required to be provided in the `web/` folder.
14+
415
### Android
516

617
**Package Information:**

README.md

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,32 @@ See [example](https://github.com/cybex-dev/twilio_voice/blob/master/example/andr
185185
- Callback action on post dialer screen may not work as expected - this is platform and manufacturer specific. PRs are welcome here.
186186
- Complete integration with showing missed calls. This is a work in progress.
187187

188-
### Web Setup:
189188

190-
There are 4 important files for Twilio incoming/missed call notifications to work:
189+
Web requires 2 files to be copied over/provided for web implementation to work correctly. These files are:
190+
1. `twilio.min.js`
191+
2. `js_notifications-sw.js`
191192

192-
- `notifications.js` is the main file, it handles the notifications and the service worker.
193-
- `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.
193+
Both of these files need to be copied over to the `web/` directory of your project. See [[Notes]](https://github.com/cybex-dev/twilio_voice/blob/master/NOTES.md#ios--macos)
194194

195-
Also, the twilio javascript SDK itself, `twilio.min.js` is needed.
195+
_The names of these files are very important, so make sure to have the file names exactly as described above._
196196

197-
### To ensure proper/as intended setup:
197+
The folder structure should look like this:
198198

199-
1. Copy files `example/web/notifications.js` and `example/web/twilio.min.js` into your application's `web` folder.
200-
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)
201-
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.
199+
```
200+
your_project/
201+
├── ...
202+
├── lib/
203+
├── web/
204+
│ ├── ...
205+
│ ├── index.html
206+
│ ├── twilio.min.js
207+
│ ├── js_notifications-sw.js
208+
│ ├── ...
209+
├── ...
210+
```
202211

203-
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.
212+
**Note:** This is required for the browser to handle notifications in the background. The service
213+
worker will handle incoming call notifications and display them even when the app is not in focus.
204214

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

@@ -221,32 +231,11 @@ Finally, add the following code to your `index.html` file, **at the end of body
221231
#### Web Considerations
222232

223233
_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.
224-
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)_
225-
226-
##### Service Worker
227-
228-
Unifying the service worker(s) is best done via post-compilation tools or a CI/CD pipeline (suggested).
229-
230-
A snippet of the suggested service worker integration is as follows:
231-
232-
```yaml
233-
#...
234-
- run: cd ./example; flutter build web --release --target=lib/main.dart --output=build/web
235-
236-
- name: Update service worker
237-
run: cat ./example/web/twilio-sw.js >> ./example/build/web/flutter_service_worker.js
238-
#...
239-
```
240-
241-
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).
234+
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)_
242235

243236
##### Web Notifications
244237

245-
2 types of notifications are shown:
246-
- Incoming call notifications with 2 buttons: `Answer` and `Reject`,
247-
- Missed call notifications with 1 button: `Call back`.
248-
249-
Notifications are presented as **alerts**. These notifications may not always been shown, check:
238+
Notifications are presented as **alerts**. If you notifications aren't shown or visible, check:
250239
- if the browser supports notifications,
251240
- if the user has granted permissions to show notifications,
252241
- if the notifications display method / notifications is enabled by the system (e.g. macOS notifications are disabled, or Windows notifications are disabled, etc).

example/service-worker/twilio-sw.js

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)