Test all mobile app callbacks and web app actions
Mobile app can call these functions to pass data to web app
Mobile app calls: window.receiveAccessToken("Bearer $token")
Note: "Bearer " prefix is automatically removed
Mobile app calls: window.receiveTokenUpdate("Bearer $newToken")
Note: "Bearer " prefix is automatically removed
Web app can call these functions to notify mobile app
Web calls: window.mobileNotify("REQUEST_TOKEN", null)
Web calls: window.mobileNotify("BACK", null)
Web calls: window.mobileNotify("LOGOUT", null)
Web calls: window.mobileNotify("INVALID_TOKEN", null)
Web calls: window.mobileNotify("SESSION_EXPIRED", null)
Web calls: window.mobileNotify("TOKEN_UPDATED", newToken)
Web calls: window.mobileNotify("PAGE_READY", null)
Web calls: window.mobileNotify("TOKEN_RECEIVED", data)
Web calls: window.mobileNotify("TOKEN_FAILED", {reason})
No logs yet. Perform actions to see logs.
1. To pass token to web app:
_controller.runJavaScript(
'window.receiveAccessToken("Bearer $token");',
)Note: Web app automatically removes "Bearer " prefix
2. To update token:
_controller.runJavaScript(
'window.receiveTokenUpdate("Bearer $newToken");',
)Note: Web app automatically removes "Bearer " prefix
3. Handle web app notifications (Flutter side):
JavascriptChannel(
name: "MobileApp",
onMessageReceived: (message) {
final data = jsonDecode(message.message);
switch (data['action']) {
case "REQUEST_TOKEN":
controller.runJavascript('window.receiveAccessToken("$token");');
break;
case "INVALID_TOKEN":
refreshTokenOrLogout();
break;
case "LOGOUT":
logoutUser();
break;
case "BACK":
Navigator.pop(context);
break;
case "TOKEN_UPDATED":
saveNewToken(data['data']);
break;
}
}
)