Skip to content

Commit

Permalink
Fix Show incoming call for Attach
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacakakpo1 committed Nov 7, 2024
1 parent c06e5e3 commit 31c92b6
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
Binary file modified .DS_Store
Binary file not shown.
18 changes: 18 additions & 0 deletions .lh/lib/view/screen/home_screen.dart.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"sourceFile": "lib/view/screen/home_screen.dart",
"activeCommit": 0,
"commits": [
{
"activePatchIndex": 0,
"patches": [
{
"date": 1730906592729,
"content": "Index: \n===================================================================\n--- \n+++ \n"
}
],
"date": 1730906592729,
"name": "Commit-0",
"content": "import 'package:flutter/material.dart';\nimport 'package:telnyx_flutter_webrtc/main_view_model.dart';\nimport 'package:provider/provider.dart';\nimport 'package:logger/logger.dart';\nimport 'package:telnyx_flutter_webrtc/view/screen/call_screen.dart';\nimport 'package:telnyx_flutter_webrtc/view/widgets/invitation_widget.dart';\n\nclass HomeScreen extends StatefulWidget {\n const HomeScreen({Key? key, required this.title}) : super(key: key);\n final String title;\n\n @override\n State<HomeScreen> createState() => _HomeScreenState();\n}\n\nclass _HomeScreenState extends State<HomeScreen> {\n final logger = Logger();\n TextEditingController destinationController = TextEditingController();\n\n bool invitation = false;\n bool ongoingCall = false;\n\n @override\n void initState() {\n super.initState();\n destinationController.text = 'isaac33882';\n }\n\n void _observeResponses() {\n Provider.of<MainViewModel>(context, listen: true).observeResponses();\n invitation =\n Provider.of<MainViewModel>(context, listen: true).ongoingInvitation;\n ongoingCall = Provider.of<MainViewModel>(context, listen: true).ongoingCall;\n }\n\n\n void _callDestination() {\n Provider.of<MainViewModel>(context, listen: false)\n .call(destinationController.text);\n logger.i('Calling!');\n }\n\n void _endCall() {\n Provider.of<MainViewModel>(context, listen: false)\n .endCall();\n logger.i('Calling!');\n }\n\n void handleOptionClick(String value) {\n switch (value) {\n case 'Logout':\n Provider.of<MainViewModel>(context, listen: false).disconnect();\n WidgetsBinding.instance.addPostFrameCallback((_) {\n Navigator.of(context).pushReplacementNamed('/');\n });\n logger.i('Disconnecting!');\n break;\n }\n }\n\n @override\n Widget build(BuildContext context) {\n _observeResponses();\n if (invitation) {\n return InvitationWidget(\n title: 'Home',\n invitation: Provider.of<MainViewModel>(context, listen: false)\n .incomingInvitation);\n } else if (ongoingCall) {\n return CallScreen(\n title: \"Ongoing Call\",\n call: Provider.of<MainViewModel>(context, listen: false).currentCall);\n } else {\n return Scaffold(\n appBar: AppBar(\n title: Text(widget.title),\n actions: <Widget>[\n PopupMenuButton<String>(\n onSelected: handleOptionClick,\n itemBuilder: (BuildContext context) {\n return {'Logout'}.map((String choice) {\n return PopupMenuItem<String>(\n value: choice,\n child: Text(choice),\n );\n }).toList();\n },\n ),\n ],\n ),\n body: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n children: <Widget>[\n Padding(\n padding: const EdgeInsets.all(8.0),\n child: TextFormField(\n controller: destinationController,\n decoration: const InputDecoration(\n border: OutlineInputBorder(),\n labelText: 'Destination',\n ),\n ),\n ),\n Padding(\n padding: const EdgeInsets.all(8.0),\n child: TextButton(\n style: TextButton.styleFrom(\n foregroundColor: Colors.blue,\n ),\n onPressed: () {\n _callDestination();\n },\n child: const Text('Call'),\n ),\n )\n ],\n ),\n ),\n );\n }\n }\n}\n"
}
]
}
3 changes: 3 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ android {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
lintOptions {
abortOnError false
}
}
}
}
Expand Down
Binary file added android/app/release/app-release.apk
Binary file not shown.
20 changes: 20 additions & 0 deletions android/app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.telnyx.telnyx_flutter_webrtc",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0.0",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}
5 changes: 2 additions & 3 deletions lib/view/screen/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class _HomeScreenState extends State<HomeScreen> {
@override
void initState() {
super.initState();
destinationController.text = 'isaac33882';
}

void _observeResponses() {
Expand All @@ -32,16 +33,14 @@ class _HomeScreenState extends State<HomeScreen> {
ongoingCall = Provider.of<MainViewModel>(context, listen: true).ongoingCall;
}


void _callDestination() {
Provider.of<MainViewModel>(context, listen: false)
.call(destinationController.text);
logger.i('Calling!');
}

void _endCall() {
Provider.of<MainViewModel>(context, listen: false)
.endCall();
Provider.of<MainViewModel>(context, listen: false).endCall();
logger.i('Calling!');
}

Expand Down
9 changes: 5 additions & 4 deletions packages/telnyx_webrtc/lib/telnyx_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,10 @@ class TelnyxClient {
case SocketMethod.ATTACH:
{
_logger.i('ATTACH RECEIVED :: $messageJson');
_logger.i('INCOMING INVITATION :: $messageJson');
ReceivedMessage invite =
ReceivedMessage.fromJson(jsonDecode(data.toString()));
var message = TelnyxMessage(
socketMethod: SocketMethod.INVITE, message: invite);
socketMethod: SocketMethod.ATTACH, message: invite);
//play ringtone for web
Call offerCall = _createCall();
offerCall.callId = invite.inviteParams?.callID;
Expand All @@ -943,8 +942,6 @@ class TelnyxClient {
"State",
isAttach: true);
_pendingAnswerFromPush = false;
// offerCall.callHandler.changeState(CallState.active, offerCall);

break;
}
case SocketMethod.MEDIA:
Expand Down Expand Up @@ -980,6 +977,10 @@ class TelnyxClient {
}
var message = TelnyxMessage(
socketMethod: SocketMethod.ANSWER, message: inviteAnswer);
answerCall.callState = CallState.active;

updateCall(answerCall);

if (inviteAnswer.inviteParams?.sdp != null) {
answerCall
?.onRemoteSessionReceived(inviteAnswer.inviteParams?.sdp);
Expand Down

0 comments on commit 31c92b6

Please sign in to comment.