@@ -11,6 +11,7 @@ import 'package:twilio_voice_example/screens/ui_call_screen.dart';
1111import 'package:twilio_voice_example/screens/ui_registration_screen.dart' ;
1212
1313import 'api.dart' ;
14+ import 'utils.dart' ;
1415
1516extension IterableExtension <E > on Iterable <E > {
1617 /// Extension on [Iterable] 's [firstWhere] that returns null if no element is found instead of throwing an exception.
@@ -42,7 +43,7 @@ void main() async {
4243 WidgetsFlutterBinding .ensureInitialized ();
4344 if (kIsWeb) {
4445 // Add firebase config here
45- final options = const FirebaseOptions (
46+ const options = FirebaseOptions (
4647 apiKey: '' ,
4748 appId: '' ,
4849 messagingSenderId: '' ,
@@ -86,7 +87,7 @@ class _AppState extends State<App> {
8687
8788 //#region #region Register with Twilio
8889 void register () async {
89- print ("voip-service registration" );
90+ printDebug ("voip-service registration" );
9091
9192 // Use for locally provided token generator e.g. Twilio's quickstarter project: https://github.com/twilio/voice-quickstart-server-node
9293 if (! kIsWeb) {
@@ -116,12 +117,12 @@ class _AppState extends State<App> {
116117
117118 /// Registers [accessToken] with TwilioVoice plugin, acquires a device token from FirebaseMessaging and registers with TwilioVoice plugin.
118119 Future <bool > _registerAccessToken (String accessToken) async {
119- print ("voip-registering access token" );
120+ printDebug ("voip-registering access token" );
120121
121122 String ? androidToken;
122123 if (Platform .isAndroid || kIsWeb) {
123124 androidToken = await FirebaseMessaging .instance.getToken ();
124- print ("androidToken is " + androidToken! );
125+ printDebug ("androidToken is ${ androidToken !}" );
125126 }
126127 final result = await TwilioVoice .instance.setTokens (accessToken: accessToken, deviceToken: androidToken);
127128 return result ?? false ;
@@ -141,9 +142,9 @@ class _AppState extends State<App> {
141142 if (myId.isEmpty) myId = null ;
142143 if (myToken.isEmpty) myToken = null ;
143144
144- print ("voip-registering with environment variables" );
145+ printDebug ("voip-registering with environment variables" );
145146 if (myId == null || myToken == null ) {
146- print ("Failed to register with environment variables, please provide ID and TOKEN" );
147+ printDebug ("Failed to register with environment variables, please provide ID and TOKEN" );
147148 return false ;
148149 }
149150 userId = myId;
@@ -165,10 +166,10 @@ class _AppState extends State<App> {
165166 /// Use this method to register with a local token generator
166167 /// To access this, run with `--dart-define=REGISTRATION_METHOD=local`
167168 Future <bool > _registerLocal () async {
168- print ("voip-registering with local token generator" );
169+ printDebug ("voip-registering with local token generator" );
169170 final result = await generateLocalAccessToken ();
170171 if (result == null ) {
171- print ("Failed to register with local token generator" );
172+ printDebug ("Failed to register with local token generator" );
172173 return false ;
173174 }
174175 userId = result.identity;
@@ -181,9 +182,9 @@ class _AppState extends State<App> {
181182 void _listenForFirebaseLogin () {
182183 final auth = FirebaseAuth .instance;
183184 auth.authStateChanges ().listen ((user) async {
184- // print ("authStateChanges $user");
185+ // printDebug ("authStateChanges $user");
185186 if (user == null ) {
186- print ("user is anonomous" );
187+ printDebug ("user is anonomous" );
187188 await auth.signInAnonymously ();
188189 } else if (! authRegistered) {
189190 authRegistered = true ;
@@ -192,7 +193,7 @@ class _AppState extends State<App> {
192193 if (userId.isEmpty) {
193194 userId = user.uid;
194195 }
195- print ("registering client $userId [firebase id ${user .uid }]" );
196+ printDebug ("registering client $userId [firebase id ${user .uid }]" );
196197 _registerFirebase ();
197198 }
198199 });
@@ -205,10 +206,10 @@ class _AppState extends State<App> {
205206 _listenForFirebaseLogin ();
206207 return false ;
207208 }
208- print ("voip-registering with firebase token generator" );
209+ printDebug ("voip-registering with firebase token generator" );
209210 final result = await generateFirebaseAccessToken ();
210211 if (result == null ) {
211- print ("Failed to register with firebase token generator" );
212+ printDebug ("Failed to register with firebase token generator" );
212213 return false ;
213214 }
214215 userId = result.identity;
@@ -224,7 +225,7 @@ class _AppState extends State<App> {
224225 super .initState ();
225226
226227 TwilioVoice .instance.setOnDeviceTokenChanged ((token) {
227- print ("voip-device token changed" );
228+ printDebug ("voip-device token changed" );
228229 if (! kIsWeb) {
229230 register ();
230231 }
@@ -233,7 +234,7 @@ class _AppState extends State<App> {
233234 listenForEvents ();
234235 register ();
235236
236- final partnerId = "alicesId" ;
237+ const partnerId = "alicesId" ;
237238 TwilioVoice .instance.registerClient (partnerId, "Alice" );
238239 // TwilioVoice.instance.requestReadPhoneStatePermission();
239240 // TwilioVoice.instance.requestMicAccess();
@@ -243,7 +244,7 @@ class _AppState extends State<App> {
243244 /// Listen for call events
244245 void listenForEvents () {
245246 TwilioVoice .instance.callEventsListener.listen ((event) {
246- print ("voip-onCallStateChanged $event " );
247+ printDebug ("voip-onCallStateChanged $event " );
247248
248249 switch (event) {
249250 case CallEvent .incoming:
@@ -260,7 +261,7 @@ class _AppState extends State<App> {
260261 if (activeCall != null ) {
261262 final customData = activeCall.customParams;
262263 if (customData != null ) {
263- print ("voip-customData $customData " );
264+ printDebug ("voip-customData $customData " );
264265 }
265266 }
266267 break ;
@@ -285,11 +286,11 @@ class _AppState extends State<App> {
285286 /// Place a call to [clientIdentifier]
286287 Future <void > _onPerformCall (String clientIdentifier) async {
287288 if (! await (TwilioVoice .instance.hasMicAccess ())) {
288- print ("request mic access" );
289+ printDebug ("request mic access" );
289290 TwilioVoice .instance.requestMicAccess ();
290291 return ;
291292 }
292- print ("starting call to $clientIdentifier " );
293+ printDebug ("starting call to $clientIdentifier " );
293294 TwilioVoice .instance.call.place (to: clientIdentifier, from: userId, extraOptions: {"_TWI_SUBJECT" : "Company Name" });
294295 }
295296
@@ -341,19 +342,19 @@ class _AppState extends State<App> {
341342 final activeCall = TwilioVoice .instance.call.activeCall! ;
342343 final action = await showIncomingCallScreen (context, activeCall);
343344 if (action == true ) {
344- print ("accepting call" );
345+ printDebug ("accepting call" );
345346 TwilioVoice .instance.call.answer ();
346347 } else if (action == false ) {
347- print ("rejecting call" );
348+ printDebug ("rejecting call" );
348349 TwilioVoice .instance.call.hangUp ();
349350 } else {
350- print ("no action" );
351+ printDebug ("no action" );
351352 }
352353 }
353354
354355 Future <bool ?> showIncomingCallScreen (BuildContext context, ActiveCall activeCall) async {
355356 if (! kIsWeb && ! Platform .isAndroid) {
356- print ("showIncomingCallScreen only for web" );
357+ printDebug ("showIncomingCallScreen only for web" );
357358 return false ;
358359 }
359360
0 commit comments