diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index f778073..477acf8 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1,2 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-2.24.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.6/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_callkit_incoming","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_callkit_incoming-2.0.0+2/","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.2.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.4/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_apple-9.2.0/","native_build":true,"dependencies":[]}],"android":[{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-2.24.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.6/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_callkit_incoming","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_callkit_incoming-2.0.0+2/","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.2.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.4/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_android-2.2.1/","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_android-12.0.1/","native_build":true,"dependencies":[]}],"macos":[{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-2.24.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.6/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.2.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-2.24.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]},{"name":"permission_handler_windows","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_windows-0.2.0/","native_build":true,"dependencies":[]}],"web":[{"name":"firebase_core_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core_web-2.9.0/","dependencies":[]},{"name":"firebase_messaging_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging_web-3.5.15/","dependencies":["firebase_core_web"]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.4/","dependencies":[]},{"name":"permission_handler_html","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_html-0.1.0+1/","dependencies":[]}]},"dependencyGraph":[{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_messaging","dependencies":["firebase_core","firebase_messaging_web"]},{"name":"firebase_messaging_web","dependencies":["firebase_core","firebase_core_web"]},{"name":"flutter_callkit_incoming","dependencies":[]},{"name":"flutter_local_notifications","dependencies":[]},{"name":"flutter_webrtc","dependencies":["path_provider"]},{"name":"fluttertoast","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_html","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_html","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]}],"date_created":"2023-12-12 10:20:19.414819","version":"3.16.1"} - +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-2.24.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.6/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_callkit_incoming","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_callkit_incoming-2.0.0+2/","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.2.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.4/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_apple-9.2.0/","native_build":true,"dependencies":[]}],"android":[{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-2.24.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.6/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_callkit_incoming","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_callkit_incoming-2.0.0+2/","native_build":true,"dependencies":[]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.2.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.4/","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_android-2.2.1/","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_android-12.0.1/","native_build":true,"dependencies":[]}],"macos":[{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-2.24.0/","native_build":true,"dependencies":[]},{"name":"firebase_messaging","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging-14.7.6/","native_build":true,"dependencies":["firebase_core"]},{"name":"flutter_local_notifications","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_local_notifications-16.2.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_foundation-2.3.1/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_linux-2.2.1/","native_build":false,"dependencies":[]}],"windows":[{"name":"firebase_core","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core-2.24.0/","native_build":true,"dependencies":[]},{"name":"flutter_webrtc","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/flutter_webrtc-0.9.47/","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/path_provider_windows-2.2.1/","native_build":false,"dependencies":[]},{"name":"permission_handler_windows","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_windows-0.2.0/","native_build":true,"dependencies":[]}],"web":[{"name":"firebase_core_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_core_web-2.9.0/","dependencies":[]},{"name":"firebase_messaging_web","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/firebase_messaging_web-3.5.15/","dependencies":["firebase_core_web"]},{"name":"fluttertoast","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/fluttertoast-8.2.4/","dependencies":[]},{"name":"permission_handler_html","path":"/Users/isaacakakpo/.pub-cache/hosted/pub.dev/permission_handler_html-0.1.0+1/","dependencies":[]}]},"dependencyGraph":[{"name":"firebase_core","dependencies":["firebase_core_web"]},{"name":"firebase_core_web","dependencies":[]},{"name":"firebase_messaging","dependencies":["firebase_core","firebase_messaging_web"]},{"name":"firebase_messaging_web","dependencies":["firebase_core","firebase_core_web"]},{"name":"flutter_callkit_incoming","dependencies":[]},{"name":"flutter_local_notifications","dependencies":[]},{"name":"flutter_webrtc","dependencies":["path_provider"]},{"name":"fluttertoast","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_html","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_html","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]}],"date_created":"2023-12-14 10:08:39.226017","version":"3.16.1"} \ No newline at end of file diff --git a/README.md b/README.md index 87e7d72..2232eed 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,42 @@ To put a call on hold, you can simply call the .onHoldUnholdPressed() method: _telnyxClient.call.onHoldUnholdPressed(); ``` +## Custom Headers +### Passing Custom Headers +Custom headers can be passed to the SDK by passing a Map to the `call.newInvite(..)` method. These headers will be passed to the SDK and will be used for all requests made by the SDK. + +```dart + Map customHeaders = { + "X-Custom-Header": "Custom Value", + "X-Another-Header": "Another Value" + }; + _telnyxClient + .createCall().newInvite(_localName, _localNumber, destination, "Fake State",customHeaders: customHeaders); +``` +### Accessing Custom Headers +Custom headers can be accessed by listening to the `onSocketMessageReceived` callback. The `ReceivedMessage.DialogParams` object contains a `customHeaders` field which contains the headers sent by other clients. + +```dart + _telnyxClient.onSocketMessageReceived = (TelnyxMessage message) { + switch (message.socketMethod) { + + case SocketMethod.INVITE: + { + message.message.dialogParams.customHeaders; + break; + } + case SocketMethod.ANSWER: + { + message.message.dialogParams.customHeaders; + break; + } + } + ... + notifyListeners(); + }; +``` + + Questions? Comments? Building something rad? [Join our Slack channel](https://joinslack.telnyx.com/) and share. ## License diff --git a/lib/main_view_model.dart b/lib/main_view_model.dart index 80e1559..33bfcfe 100644 --- a/lib/main_view_model.dart +++ b/lib/main_view_model.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/foundation.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:logger/logger.dart'; @@ -15,6 +17,7 @@ class MainViewModel with ChangeNotifier { bool _registered = false; bool _ongoingInvitation = false; + bool _ringingCall = false; bool _ongoingCall = false; bool _speakerPhone = true; IncomingInviteParams? _incomingInvite; @@ -34,6 +37,11 @@ class MainViewModel with ChangeNotifier { return _ongoingCall; } + + bool get callRinging { + return _ringingCall; + } + Call get currentCall { return _telnyxClient.call; } @@ -60,6 +68,7 @@ class MainViewModel with ChangeNotifier { } case SocketMethod.ANSWER: { + _ringingCall = false; _ongoingCall = true; break; } @@ -67,6 +76,19 @@ class MainViewModel with ChangeNotifier { { _ongoingInvitation = false; _ongoingCall = false; + _ringingCall = false; + break; + } + case SocketMethod.RINGING: + { + logger.i("myRinging"); + _ringingCall = true; + break; + } + case SocketMethod.MEDIA: + { + logger.i("myRinging"); + _ringingCall = true; break; } } @@ -149,13 +171,14 @@ class MainViewModel with ChangeNotifier { } void endCall() { - if (_ongoingCall) { + if (_ongoingCall || _ringingCall) { _telnyxClient.call.endCall(_telnyxClient.call.callId); } else { _telnyxClient.createCall().endCall(_incomingInvite?.callID); } _ongoingInvitation = false; _ongoingCall = false; + _ringingCall = false; notifyListeners(); } diff --git a/lib/view/screen/home_screen.dart b/lib/view/screen/home_screen.dart index 46eea40..de1ca7c 100644 --- a/lib/view/screen/home_screen.dart +++ b/lib/view/screen/home_screen.dart @@ -19,6 +19,7 @@ class _HomeScreenState extends State { bool invitation = false; bool ongoingCall = false; + bool callRinging = false; @override void initState() { @@ -30,6 +31,7 @@ class _HomeScreenState extends State { invitation = Provider.of(context, listen: true).ongoingInvitation; ongoingCall = Provider.of(context, listen: true).ongoingCall; + callRinging = Provider.of(context, listen: true).callRinging; } void _callDestination() { @@ -58,7 +60,7 @@ class _HomeScreenState extends State { title: 'Home', invitation: Provider.of(context, listen: false) .incomingInvitation); - } else if (ongoingCall) { + } else if (ongoingCall || callRinging) { return CallScreen( title: "Ongoing Call", call: Provider.of(context, listen: false).currentCall); diff --git a/lib/view/screen/login_screen.dart b/lib/view/screen/login_screen.dart index e6b85c6..213a40c 100644 --- a/lib/view/screen/login_screen.dart +++ b/lib/view/screen/login_screen.dart @@ -30,6 +30,9 @@ class _LoginScreenState extends State { _checkPermissions(); } super.initState(); + sipUserController.text = "isaac47223"; + sipPasswordController.text = "gvfTRAgD"; + } Future _checkPermissions() async { diff --git a/packages/telnyx_webrtc/lib/telnyx_client.dart b/packages/telnyx_webrtc/lib/telnyx_client.dart index 011aeaf..e52c1e1 100644 --- a/packages/telnyx_webrtc/lib/telnyx_client.dart +++ b/packages/telnyx_webrtc/lib/telnyx_client.dart @@ -392,6 +392,11 @@ class TelnyxClient { if (mediaReceived.inviteParams?.sdp != null) { call.onRemoteSessionReceived(mediaReceived.inviteParams?.sdp); earlySDP = true; + ReceivedMessage ringing = + ReceivedMessage.fromJson(jsonDecode(data.toString())); + var message = TelnyxMessage( + socketMethod: SocketMethod.MEDIA, message: ringing); + onSocketMessageReceived(message); } else { _logger.d('No SDP contained within Media Message'); }