Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UI State with Ringing/Media States #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -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"}
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, String> 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
Expand Down
25 changes: 24 additions & 1 deletion lib/main_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math';

import 'package:flutter/foundation.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:logger/logger.dart';
Expand All @@ -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;
Expand All @@ -34,6 +37,11 @@ class MainViewModel with ChangeNotifier {
return _ongoingCall;
}


bool get callRinging {
return _ringingCall;
}

Call get currentCall {
return _telnyxClient.call;
}
Expand All @@ -60,13 +68,27 @@ class MainViewModel with ChangeNotifier {
}
case SocketMethod.ANSWER:
{
_ringingCall = false;
_ongoingCall = true;
break;
}
case SocketMethod.BYE:
{
_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;
}
}
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion lib/view/screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class _HomeScreenState extends State<HomeScreen> {

bool invitation = false;
bool ongoingCall = false;
bool callRinging = false;

@override
void initState() {
Expand All @@ -30,6 +31,7 @@ class _HomeScreenState extends State<HomeScreen> {
invitation =
Provider.of<MainViewModel>(context, listen: true).ongoingInvitation;
ongoingCall = Provider.of<MainViewModel>(context, listen: true).ongoingCall;
callRinging = Provider.of<MainViewModel>(context, listen: true).callRinging;
}

void _callDestination() {
Expand Down Expand Up @@ -58,7 +60,7 @@ class _HomeScreenState extends State<HomeScreen> {
title: 'Home',
invitation: Provider.of<MainViewModel>(context, listen: false)
.incomingInvitation);
} else if (ongoingCall) {
} else if (ongoingCall || callRinging) {
return CallScreen(
title: "Ongoing Call",
call: Provider.of<MainViewModel>(context, listen: false).currentCall);
Expand Down
3 changes: 3 additions & 0 deletions lib/view/screen/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class _LoginScreenState extends State<LoginScreen> {
_checkPermissions();
}
super.initState();
sipUserController.text = "isaac47223";
sipPasswordController.text = "gvfTRAgD";

}

Future<void> _checkPermissions() async {
Expand Down
5 changes: 5 additions & 0 deletions packages/telnyx_webrtc/lib/telnyx_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down