|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +import 'package:web_callkit/web_callkit.dart'; |
| 4 | + |
| 5 | +import 'screens/home_screen.dart'; |
| 6 | +import 'theme.dart'; |
| 7 | + |
| 8 | +void main() { |
| 9 | + runApp(const MyApp()); |
| 10 | +} |
| 11 | + |
| 12 | +class MyApp extends StatefulWidget { |
| 13 | + const MyApp({super.key}); |
| 14 | + |
| 15 | + @override |
| 16 | + State<MyApp> createState() => _MyAppState(); |
| 17 | +} |
| 18 | + |
| 19 | +class _MyAppState extends State<MyApp> { |
| 20 | + @override |
| 21 | + void initState() { |
| 22 | + super.initState(); |
| 23 | + final webCallkitPlugin = WebCallkit.instance; |
| 24 | + webCallkitPlugin.setConfiguration(const CKConfiguration()); |
| 25 | + webCallkitPlugin.setOnCallActionHandler((uuid, action, source) { |
| 26 | + // ignore: avoid_print |
| 27 | + print("onCallActionHandler: $uuid, $action, $source"); |
| 28 | + if (action == CKCallAction.answer) { |
| 29 | + webCallkitPlugin.updateCallStatus(uuid, callStatus: CallState.active); |
| 30 | + } else if (action == CKCallAction.decline) { |
| 31 | + webCallkitPlugin.reportCallDisconnected(uuid, |
| 32 | + response: DisconnectResponse.declined); |
| 33 | + } |
| 34 | + }); |
| 35 | + webCallkitPlugin.setOnCallEventListener((event, source) { |
| 36 | + // ignore: avoid_print |
| 37 | + print("onCallEventListener: $event, $source"); |
| 38 | + }); |
| 39 | + webCallkitPlugin.setOnCallTypeChangeListener((event, callType, source) { |
| 40 | + // ignore: avoid_print |
| 41 | + webCallkitPlugin.updateCallType(event.uuid, callType: callType); |
| 42 | + }); |
| 43 | + webCallkitPlugin.setOnDisconnectListener((uuid, response, source) { |
| 44 | + // ignore: avoid_print |
| 45 | + webCallkitPlugin.reportCallDisconnected(uuid, response: response); |
| 46 | + // webCallkitPlugin.updateCallStatus(uuid, callStatus: CallState.disconnected); |
| 47 | + }); |
| 48 | + webCallkitPlugin.setOnDismissedListener((uuid, source) { |
| 49 | + final call = webCallkitPlugin.getCall(uuid); |
| 50 | + if (call != null) { |
| 51 | + webCallkitPlugin.renotify(call.uuid, silent: true); |
| 52 | + } |
| 53 | + }); |
| 54 | + // webCallkitPlugin.setOnActionAnswered((uuid, call, source) { |
| 55 | + // printDebug("onActionAnswered: $uuid, $call, $source"); |
| 56 | + // webCallkitPlugin.updateCallStatus(uuid, callStatus: CallState.active); |
| 57 | + // }); |
| 58 | + // webCallkitPlugin.setOnActionHangup((uuid, call, source, response) { |
| 59 | + // printDebug("onActionHangup: $uuid, $call, $source, $response"); |
| 60 | + // webCallkitPlugin.reportCallDisconnected(uuid, response: response); |
| 61 | + // }); |
| 62 | + // webCallkitPlugin.setOnActionDecline((uuid, call, source, response) { |
| 63 | + // printDebug("onActionDecline: $uuid, $call, $source, $response"); |
| 64 | + // webCallkitPlugin.reportCallDisconnected(uuid, response: response); |
| 65 | + // }); |
| 66 | + // webCallkitPlugin.setOnActionCallback((uuid, call, source) { |
| 67 | + // printDebug("onActionCallback: $uuid, $call, $source"); |
| 68 | + // webCallkitPlugin.reportNewCall( |
| 69 | + // uuid: uuid, |
| 70 | + // handle: call.localizedName, |
| 71 | + // data: call.data, |
| 72 | + // attributes: call.attributes, |
| 73 | + // capabilities: call.capabilities, |
| 74 | + // ); |
| 75 | + // }); |
| 76 | + // webCallkitPlugin.setOnActionDismiss((uuid, call, source) { |
| 77 | + // printDebug("onActionDismiss: $uuid, $call, $source"); |
| 78 | + // }); |
| 79 | + } |
| 80 | + |
| 81 | + @override |
| 82 | + Widget build(BuildContext context) { |
| 83 | + return MaterialApp( |
| 84 | + theme: getThemeData(context), |
| 85 | + home: const HomeScreen(), |
| 86 | + ); |
| 87 | + } |
| 88 | +} |
0 commit comments