Skip to content

Commit fd4c307

Browse files
authored
Merge pull request #281 from idpass/fix/375-optimize-ios-sharing
Optimize iOS sharing
2 parents 0708101 + 6c7fbe0 commit fd4c307

7 files changed

Lines changed: 143 additions & 74 deletions

File tree

ios/MOSIPResidentApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
303303
CLANG_ENABLE_MODULES = YES;
304304
CODE_SIGN_ENTITLEMENTS = MOSIPResidentApp/MOSIPResidentApp.entitlements;
305-
CURRENT_PROJECT_VERSION = 14;
305+
CURRENT_PROJECT_VERSION = 15;
306306
DEVELOPMENT_TEAM = 9L83VVTX8B;
307307
ENABLE_BITCODE = NO;
308308
GCC_PREPROCESSOR_DEFINITIONS = (
@@ -335,7 +335,7 @@
335335
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
336336
CLANG_ENABLE_MODULES = YES;
337337
CODE_SIGN_ENTITLEMENTS = MOSIPResidentApp/MOSIPResidentApp.entitlements;
338-
CURRENT_PROJECT_VERSION = 14;
338+
CURRENT_PROJECT_VERSION = 15;
339339
DEVELOPMENT_TEAM = 9L83VVTX8B;
340340
INFOPLIST_FILE = MOSIPResidentApp/Info.plist;
341341
IPHONEOS_DEPLOYMENT_TARGET = 12.0;

machines/request.ts

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ export const requestMachine =
129129
actions: 'switchProtocol',
130130
},
131131
],
132+
133+
OFFLINE: 'offline',
132134
},
133135
states: {
134136
inactive: {
@@ -173,10 +175,6 @@ export const requestMachine =
173175
},
174176
},
175177
},
176-
177-
on: {
178-
APP_ACTIVE: 'checkingNetwork',
179-
},
180178
},
181179

182180
bluetoothDenied: {
@@ -221,10 +219,16 @@ export const requestMachine =
221219
preparingToExchangeInfo: {
222220
entry: 'requestReceiverInfo',
223221
on: {
224-
RECEIVE_DEVICE_INFO: {
225-
target: 'exchangingDeviceInfo',
226-
actions: 'setReceiverInfo',
227-
},
222+
RECEIVE_DEVICE_INFO: [
223+
{
224+
cond: 'isModeOnline',
225+
target: 'waitingForVc',
226+
},
227+
{
228+
target: 'exchangingDeviceInfo',
229+
actions: 'setReceiverInfo',
230+
},
231+
],
228232
},
229233
},
230234

@@ -473,9 +477,15 @@ export const requestMachine =
473477

474478
offline: {
475479
on: {
476-
ONLINE: 'checkingBluetoothService',
480+
OFFLINE: {
481+
internal: true,
482+
},
483+
SCREEN_FOCUS: 'checkingNetwork',
477484
APP_ACTIVE: 'checkingNetwork',
478485
},
486+
after: {
487+
500: 'checkingNetwork',
488+
},
479489
},
480490
},
481491
},
@@ -519,14 +529,16 @@ export const requestMachine =
519529
},
520530

521531
generateConnectionParams: assign({
522-
connectionParams: (context) => {
523-
if (context.sharingProtocol === 'OFFLINE') {
532+
connectionParams: ({ sharingProtocol }) => {
533+
if (sharingProtocol === 'OFFLINE') {
524534
return IdpassSmartshare.getConnectionParameters();
525535
} else {
526-
const cid = uuid.v4();
527536
return JSON.stringify({
528537
pk: '',
529-
cid,
538+
cid: uuid.v4(),
539+
receiverInfo: {
540+
deviceName: getDeviceNameSync(),
541+
},
530542
});
531543
}
532544
},
@@ -546,6 +558,9 @@ export const requestMachine =
546558
}
547559
: event.vc;
548560
},
561+
senderInfo: (context, event) => {
562+
return event.vc.senderInfo ?? context.senderInfo;
563+
},
549564
}),
550565

551566
registerLoggers: assign({
@@ -734,7 +749,7 @@ export const requestMachine =
734749
if (scannedQrParams.cid === generatedParams.cid) {
735750
const event: PairingResponseEvent = {
736751
type: 'pairing:response',
737-
data: scannedQrParams.cid,
752+
data: scannedQrParams,
738753
};
739754
await onlineSend(event, scannedQrParams.cid);
740755
callback({
@@ -764,6 +779,15 @@ export const requestMachine =
764779
);
765780

766781
return () => subscription.remove();
782+
} else {
783+
return NetInfo.addEventListener((state) => {
784+
callback({
785+
type:
786+
state.isConnected && state.isInternetReachable
787+
? 'ONLINE'
788+
: 'OFFLINE',
789+
});
790+
});
767791
}
768792
},
769793

@@ -785,16 +809,16 @@ export const requestMachine =
785809

786810
return () => subscription.remove();
787811
} else {
788-
onlineSubscribe(
789-
'exchange-sender-info',
790-
async (senderInfo) => {
791-
await GoogleNearbyMessages.unpublish();
792-
await onlineSend(event, context.pairId);
793-
callback({ type: 'EXCHANGE_DONE', senderInfo });
794-
},
795-
null,
796-
{ pairId: context.pairId }
797-
);
812+
// onlineSubscribe(
813+
// 'exchange-sender-info',
814+
// async (senderInfo) => {
815+
// await GoogleNearbyMessages.unpublish();
816+
// await onlineSend(event, context.pairId);
817+
// callback({ type: 'EXCHANGE_DONE', senderInfo });
818+
// },
819+
// null,
820+
// { pairId: context.pairId }
821+
// );
798822
}
799823
},
800824

@@ -882,10 +906,13 @@ export const requestMachine =
882906
return receivedVcs.includes(vcKey);
883907
},
884908

885-
isModeOnline: (context, event) =>
886-
event.type === 'SCREEN_FOCUS'
887-
? context.sharingProtocol === 'ONLINE'
888-
: event.value,
909+
isModeOnline: (context, event) => {
910+
if (event.type === 'SWITCH_PROTOCOL') {
911+
return event.value;
912+
} else {
913+
return context.sharingProtocol === 'ONLINE';
914+
}
915+
},
889916
},
890917

891918
delays: {

machines/request.typegen.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export interface Typegen0 {
99
data: unknown;
1010
__tip: 'See the XState TS docs to learn how to strongly type this.';
1111
};
12+
'xstate.after(500)#request.offline': {
13+
type: 'xstate.after(500)#request.offline';
14+
};
1215
'xstate.after(CANCEL_TIMEOUT)#request.cancelling': {
1316
type: 'xstate.after(CANCEL_TIMEOUT)#request.cancelling';
1417
};
@@ -50,6 +53,7 @@ export interface Typegen0 {
5053
| 'CANCEL'
5154
| 'FACE_INVALID'
5255
| 'FACE_VALID'
56+
| 'OFFLINE'
5357
| 'REJECT'
5458
| 'SCREEN_BLUR'
5559
| 'SCREEN_FOCUS'
@@ -59,6 +63,7 @@ export interface Typegen0 {
5963
| ''
6064
| 'DISCONNECT'
6165
| 'DISMISS'
66+
| 'OFFLINE'
6267
| 'SCREEN_BLUR'
6368
| 'SCREEN_FOCUS'
6469
| 'SWITCH_PROTOCOL'
@@ -76,6 +81,7 @@ export interface Typegen0 {
7681
| 'xstate.after(CLEAR_DELAY)#request.clearingConnection';
7782
removeLoggers:
7883
| 'DISMISS'
84+
| 'OFFLINE'
7985
| 'SCREEN_BLUR'
8086
| 'xstate.after(CLEAR_DELAY)#request.clearingConnection'
8187
| 'xstate.init';
@@ -102,11 +108,11 @@ export interface Typegen0 {
102108
CANCEL_TIMEOUT: 'CANCEL';
103109
CLEAR_DELAY: '';
104110
CONNECTION_TIMEOUT: 'RECEIVE_DEVICE_INFO';
105-
SHARING_TIMEOUT: 'EXCHANGE_DONE';
111+
SHARING_TIMEOUT: 'EXCHANGE_DONE' | 'RECEIVE_DEVICE_INFO';
106112
};
107113
'eventsCausingGuards': {
108114
hasExistingVc: 'VC_RESPONSE';
109-
isModeOnline: 'SCREEN_FOCUS' | 'SWITCH_PROTOCOL';
115+
isModeOnline: 'RECEIVE_DEVICE_INFO' | 'SCREEN_FOCUS' | 'SWITCH_PROTOCOL';
110116
};
111117
'eventsCausingServices': {
112118
advertiseDevice:
@@ -117,10 +123,14 @@ export interface Typegen0 {
117123
| 'SCREEN_FOCUS'
118124
| 'SWITCH_PROTOCOL'
119125
| 'xstate.after(CANCEL_TIMEOUT)#request.cancelling';
120-
checkNetwork: 'APP_ACTIVE' | 'SCREEN_FOCUS' | 'SWITCH_PROTOCOL';
126+
checkNetwork:
127+
| 'APP_ACTIVE'
128+
| 'SCREEN_FOCUS'
129+
| 'SWITCH_PROTOCOL'
130+
| 'xstate.after(500)#request.offline';
121131
exchangeDeviceInfo: 'RECEIVE_DEVICE_INFO';
122-
monitorConnection: 'xstate.init';
123-
receiveVc: 'EXCHANGE_DONE';
132+
monitorConnection: 'OFFLINE' | 'xstate.init';
133+
receiveVc: 'EXCHANGE_DONE' | 'RECEIVE_DEVICE_INFO';
124134
requestBluetooth: 'BLUETOOTH_DISABLED';
125135
sendDisconnect: 'CANCEL';
126136
sendVcResponse: 'CANCEL' | 'REJECT' | 'STORE_RESPONSE';

0 commit comments

Comments
 (0)