@@ -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 : {
0 commit comments