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

Optimize iOS sharing #281

Merged
merged 2 commits into from
Jan 30, 2023
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
4 changes: 2 additions & 2 deletions ios/MOSIPResidentApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MOSIPResidentApp/MOSIPResidentApp.entitlements;
CURRENT_PROJECT_VERSION = 14;
CURRENT_PROJECT_VERSION = 15;
DEVELOPMENT_TEAM = 9L83VVTX8B;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand Down Expand Up @@ -335,7 +335,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MOSIPResidentApp/MOSIPResidentApp.entitlements;
CURRENT_PROJECT_VERSION = 14;
CURRENT_PROJECT_VERSION = 15;
DEVELOPMENT_TEAM = 9L83VVTX8B;
INFOPLIST_FILE = MOSIPResidentApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
Expand Down
83 changes: 55 additions & 28 deletions machines/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export const requestMachine =
actions: 'switchProtocol',
},
],

OFFLINE: 'offline',
},
states: {
inactive: {
Expand Down Expand Up @@ -173,10 +175,6 @@ export const requestMachine =
},
},
},

on: {
APP_ACTIVE: 'checkingNetwork',
},
},

bluetoothDenied: {
Expand Down Expand Up @@ -221,10 +219,16 @@ export const requestMachine =
preparingToExchangeInfo: {
entry: 'requestReceiverInfo',
on: {
RECEIVE_DEVICE_INFO: {
target: 'exchangingDeviceInfo',
actions: 'setReceiverInfo',
},
RECEIVE_DEVICE_INFO: [
{
cond: 'isModeOnline',
target: 'waitingForVc',
},
{
target: 'exchangingDeviceInfo',
actions: 'setReceiverInfo',
},
],
},
},

Expand Down Expand Up @@ -473,9 +477,15 @@ export const requestMachine =

offline: {
on: {
ONLINE: 'checkingBluetoothService',
OFFLINE: {
internal: true,
},
SCREEN_FOCUS: 'checkingNetwork',
APP_ACTIVE: 'checkingNetwork',
},
after: {
500: 'checkingNetwork',
},
},
},
},
Expand Down Expand Up @@ -519,14 +529,16 @@ export const requestMachine =
},

generateConnectionParams: assign({
connectionParams: (context) => {
if (context.sharingProtocol === 'OFFLINE') {
connectionParams: ({ sharingProtocol }) => {
if (sharingProtocol === 'OFFLINE') {
return IdpassSmartshare.getConnectionParameters();
} else {
const cid = uuid.v4();
return JSON.stringify({
pk: '',
cid,
cid: uuid.v4(),
receiverInfo: {
deviceName: getDeviceNameSync(),
},
});
}
},
Expand All @@ -546,6 +558,9 @@ export const requestMachine =
}
: event.vc;
},
senderInfo: (context, event) => {
return event.vc.senderInfo ?? context.senderInfo;
},
}),

registerLoggers: assign({
Expand Down Expand Up @@ -734,7 +749,7 @@ export const requestMachine =
if (scannedQrParams.cid === generatedParams.cid) {
const event: PairingResponseEvent = {
type: 'pairing:response',
data: scannedQrParams.cid,
data: scannedQrParams,
};
await onlineSend(event, scannedQrParams.cid);
callback({
Expand Down Expand Up @@ -764,6 +779,15 @@ export const requestMachine =
);

return () => subscription.remove();
} else {
return NetInfo.addEventListener((state) => {
callback({
type:
state.isConnected && state.isInternetReachable
? 'ONLINE'
: 'OFFLINE',
});
});
}
},

Expand All @@ -785,16 +809,16 @@ export const requestMachine =

return () => subscription.remove();
} else {
onlineSubscribe(
'exchange-sender-info',
async (senderInfo) => {
await GoogleNearbyMessages.unpublish();
await onlineSend(event, context.pairId);
callback({ type: 'EXCHANGE_DONE', senderInfo });
},
null,
{ pairId: context.pairId }
);
// onlineSubscribe(
// 'exchange-sender-info',
// async (senderInfo) => {
// await GoogleNearbyMessages.unpublish();
// await onlineSend(event, context.pairId);
// callback({ type: 'EXCHANGE_DONE', senderInfo });
// },
// null,
// { pairId: context.pairId }
// );
}
},

Expand Down Expand Up @@ -882,10 +906,13 @@ export const requestMachine =
return receivedVcs.includes(vcKey);
},

isModeOnline: (context, event) =>
event.type === 'SCREEN_FOCUS'
? context.sharingProtocol === 'ONLINE'
: event.value,
isModeOnline: (context, event) => {
if (event.type === 'SWITCH_PROTOCOL') {
return event.value;
} else {
return context.sharingProtocol === 'ONLINE';
}
},
},

delays: {
Expand Down
20 changes: 15 additions & 5 deletions machines/request.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export interface Typegen0 {
data: unknown;
__tip: 'See the XState TS docs to learn how to strongly type this.';
};
'xstate.after(500)#request.offline': {
type: 'xstate.after(500)#request.offline';
};
'xstate.after(CANCEL_TIMEOUT)#request.cancelling': {
type: 'xstate.after(CANCEL_TIMEOUT)#request.cancelling';
};
Expand Down Expand Up @@ -50,6 +53,7 @@ export interface Typegen0 {
| 'CANCEL'
| 'FACE_INVALID'
| 'FACE_VALID'
| 'OFFLINE'
| 'REJECT'
| 'SCREEN_BLUR'
| 'SCREEN_FOCUS'
Expand All @@ -59,6 +63,7 @@ export interface Typegen0 {
| ''
| 'DISCONNECT'
| 'DISMISS'
| 'OFFLINE'
| 'SCREEN_BLUR'
| 'SCREEN_FOCUS'
| 'SWITCH_PROTOCOL'
Expand All @@ -76,6 +81,7 @@ export interface Typegen0 {
| 'xstate.after(CLEAR_DELAY)#request.clearingConnection';
removeLoggers:
| 'DISMISS'
| 'OFFLINE'
| 'SCREEN_BLUR'
| 'xstate.after(CLEAR_DELAY)#request.clearingConnection'
| 'xstate.init';
Expand All @@ -102,11 +108,11 @@ export interface Typegen0 {
CANCEL_TIMEOUT: 'CANCEL';
CLEAR_DELAY: '';
CONNECTION_TIMEOUT: 'RECEIVE_DEVICE_INFO';
SHARING_TIMEOUT: 'EXCHANGE_DONE';
SHARING_TIMEOUT: 'EXCHANGE_DONE' | 'RECEIVE_DEVICE_INFO';
};
'eventsCausingGuards': {
hasExistingVc: 'VC_RESPONSE';
isModeOnline: 'SCREEN_FOCUS' | 'SWITCH_PROTOCOL';
isModeOnline: 'RECEIVE_DEVICE_INFO' | 'SCREEN_FOCUS' | 'SWITCH_PROTOCOL';
};
'eventsCausingServices': {
advertiseDevice:
Expand All @@ -117,10 +123,14 @@ export interface Typegen0 {
| 'SCREEN_FOCUS'
| 'SWITCH_PROTOCOL'
| 'xstate.after(CANCEL_TIMEOUT)#request.cancelling';
checkNetwork: 'APP_ACTIVE' | 'SCREEN_FOCUS' | 'SWITCH_PROTOCOL';
checkNetwork:
| 'APP_ACTIVE'
| 'SCREEN_FOCUS'
| 'SWITCH_PROTOCOL'
| 'xstate.after(500)#request.offline';
exchangeDeviceInfo: 'RECEIVE_DEVICE_INFO';
monitorConnection: 'xstate.init';
receiveVc: 'EXCHANGE_DONE';
monitorConnection: 'OFFLINE' | 'xstate.init';
receiveVc: 'EXCHANGE_DONE' | 'RECEIVE_DEVICE_INFO';
requestBluetooth: 'BLUETOOTH_DISABLED';
sendDisconnect: 'CANCEL';
sendVcResponse: 'CANCEL' | 'REJECT' | 'STORE_RESPONSE';
Expand Down
Loading