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

[ICA-208] Sharing device remains in sharing state when Requesting phone gets disconnected (like network issue) #214

Merged
merged 3 commits into from
Jul 29, 2022
Merged
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
18 changes: 14 additions & 4 deletions machines/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export const requestMachine = model.createMachine(
},
id: 'request',
initial: 'inactive',
invoke: {
src: 'checkConnection',
},
on: {
SCREEN_BLUR: 'inactive',
SCREEN_FOCUS: 'checkingBluetoothService',
Expand Down Expand Up @@ -225,6 +228,7 @@ export const requestMachine = model.createMachine(
exit: ['disconnect'],
},
disconnected: {
entry: ['disconnect'],
on: {
DISMISS: 'waitingForConnection',
},
Expand Down Expand Up @@ -370,6 +374,16 @@ export const requestMachine = model.createMachine(
.catch(() => callback(model.events.BLUETOOTH_DISABLED()));
},

checkConnection: () => (callback) => {
const subscription = SmartShare.handleNearbyEvents((event) => {
if (event.type === 'onDisconnected') {
callback({ type: 'DISCONNECT' });
}
});

return () => subscription.remove();
},

advertiseDevice: () => (callback) => {
SmartShare.createConnection('advertiser', () => {
callback({ type: 'CONNECTED' });
Expand All @@ -378,10 +392,6 @@ export const requestMachine = model.createMachine(

exchangeDeviceInfo: (context) => (callback) => {
const subscription = SmartShare.handleNearbyEvents((event) => {
if (event.type === 'onDisconnected') {
callback({ type: 'DISCONNECT' });
}

if (event.type !== 'msg') return;

const message = Message.fromString<DeviceInfo>(event.data);
Expand Down
8 changes: 5 additions & 3 deletions machines/request.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export interface Typegen0 {
| 'SCREEN_BLUR'
| 'xstate.after(CLEAR_DELAY)#clearingConnection'
| 'DISMISS';
disconnect: '';
disconnect: '' | 'DISCONNECT';
registerLoggers: 'xstate.after(CLEAR_DELAY)#clearingConnection' | 'DISMISS';
generateConnectionParams:
| 'xstate.after(CLEAR_DELAY)#clearingConnection'
| 'DISMISS';
requestReceiverInfo: 'CONNECTED';
requestReceivedVcs: 'xstate.init';
requestReceivedVcs: 'ACCEPT';
requestExistingVc: 'VC_RESPONSE';
mergeIncomingVc: 'STORE_RESPONSE';
prependReceivedVc: 'VC_RESPONSE';
Expand All @@ -32,6 +32,7 @@ export interface Typegen0 {
'xstate.init': { type: 'xstate.init' };
};
'invokeSrcNameMap': {
checkConnection: 'done.invoke.request:invocation[0]';
checkBluetoothService: 'done.invoke.request.checkingBluetoothService.checking:invocation[0]';
requestBluetooth: 'done.invoke.request.checkingBluetoothService.requesting:invocation[0]';
advertiseDevice: 'done.invoke.waitingForConnection:invocation[0]';
Expand All @@ -48,7 +49,8 @@ export interface Typegen0 {
delays: never;
};
'eventsCausingServices': {
checkBluetoothService: 'xstate.init';
checkConnection: 'xstate.init';
checkBluetoothService: 'SCREEN_FOCUS';
requestBluetooth: 'BLUETOOTH_DISABLED';
advertiseDevice: 'xstate.after(CLEAR_DELAY)#clearingConnection' | 'DISMISS';
exchangeDeviceInfo: 'RECEIVE_DEVICE_INFO';
Expand Down
22 changes: 17 additions & 5 deletions machines/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { VC_ITEM_STORE_KEY } from '../shared/constants';

const checkingAirplaneMode = '#checkingAirplaneMode';
const checkingLocationService = '#checkingLocationService';
const findingConnection = '#scan.findingConnection';

const model = createModel(
{
Expand Down Expand Up @@ -70,6 +71,9 @@ export const scanMachine = model.createMachine(
},
id: 'scan',
initial: 'inactive',
invoke: {
src: 'checkConnection',
},
on: {
SCREEN_BLUR: 'inactive',
SCREEN_FOCUS: 'checkingAirplaneMode',
Expand Down Expand Up @@ -218,10 +222,12 @@ export const scanMachine = model.createMachine(
idle: {
on: {
ACCEPT_REQUEST: 'selectingVc',
DISCONNECT: findingConnection,
},
},
selectingVc: {
on: {
DISCONNECT: findingConnection,
SELECT_VC: {
target: 'sendingVc',
actions: ['setSelectedVc'],
Expand All @@ -234,7 +240,7 @@ export const scanMachine = model.createMachine(
src: 'sendVc',
},
on: {
DISCONNECT: '#scan.disconnected',
DISCONNECT: findingConnection,
VC_ACCEPTED: 'accepted',
VC_REJECTED: 'rejected',
},
Expand Down Expand Up @@ -362,6 +368,16 @@ export const scanMachine = model.createMachine(
},

services: {
checkConnection: () => (callback) => {
const subscription = SmartShare.handleNearbyEvents((event) => {
if (event.type === 'onDisconnected') {
callback({ type: 'DISCONNECT' });
}
});

return () => subscription.remove();
},

checkLocationPermission: () => async (callback) => {
try {
// wait a bit for animation to finish when app becomes active
Expand Down Expand Up @@ -424,10 +440,6 @@ export const scanMachine = model.createMachine(
const message = new Message('exchange:sender-info', context.senderInfo);
SmartShare.send(message.toString(), () => {
subscription = SmartShare.handleNearbyEvents((event) => {
if (event.type === 'onDisconnected') {
callback({ type: 'DISCONNECT' });
}

if (event.type !== 'msg') return;
const response = Message.fromString<DeviceInfo>(event.data);
if (response.type === 'exchange:receiver-info') {
Expand Down
10 changes: 7 additions & 3 deletions machines/scan.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ export interface Typegen0 {
| 'SCREEN_BLUR'
| 'xstate.after(CLEAR_DELAY)#clearingConnection'
| 'CANCEL'
| 'DISMISS';
| 'DISMISS'
| 'DISCONNECT';
requestToDisableFlightMode: 'FLIGHT_REQUEST';
requestToEnableLocation: 'LOCATION_DISABLED' | 'LOCATION_REQUEST';
disconnect: 'LOCATION_ENABLED';
registerLoggers:
| 'xstate.after(CLEAR_DELAY)#clearingConnection'
| 'CANCEL'
| 'DISMISS';
| 'DISMISS'
| 'DISCONNECT';
requestSenderInfo: 'SCAN';
clearReason: 'xstate.init';
logShared: 'VC_ACCEPTED';
Expand All @@ -32,6 +34,7 @@ export interface Typegen0 {
'xstate.init': { type: 'xstate.init' };
};
'invokeSrcNameMap': {
checkConnection: 'done.invoke.scan:invocation[0]';
checkAirplaneMode: 'done.invoke.scan.checkingAirplaneMode.checkingStatus:invocation[0]';
checkLocationStatus: 'done.invoke.checkingLocationService:invocation[0]';
checkLocationPermission: 'done.invoke.scan.checkingLocationService.checkingPermission:invocation[0]';
Expand All @@ -46,7 +49,8 @@ export interface Typegen0 {
delays: never;
};
'eventsCausingServices': {
checkAirplaneMode: 'APP_ACTIVE';
checkConnection: 'xstate.init';
checkAirplaneMode: 'SCREEN_FOCUS' | 'APP_ACTIVE' | 'FLIGHT_ENABLED';
checkLocationStatus: 'FLIGHT_DISABLED';
checkLocationPermission: 'LOCATION_ENABLED' | 'APP_ACTIVE';
discoverDevice: 'RECEIVE_DEVICE_INFO';
Expand Down
5 changes: 3 additions & 2 deletions screens/Profile/ProfileScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { View } from 'react-native';
import { getVersion } from 'react-native-device-info';
import { ListItem, Switch } from 'react-native-elements';
import { Column, Text } from '../../components/ui';
Expand Down Expand Up @@ -90,7 +91,7 @@ export const ProfileScreen: React.FC<MainRouteProps> = (props) => {
Version: {getVersion()}
</Text>
{controller.backendInfo.application.name !== '' ? (
<div>
<View>
<Text
weight="semibold"
align="center"
Expand All @@ -106,7 +107,7 @@ export const ProfileScreen: React.FC<MainRouteProps> = (props) => {
color={Colors.Grey}>
MOSIP: {controller.backendInfo.config['mosip.host']}
</Text>
</div>
</View>
) : null}
</Column>
);
Expand Down