How to migrate?
2 minute read
If you have gone through the rSDK changes, migrating your app will be easy. If you are ready to migrate your project to latest rSDK changes, then you are good to go.
Get instance of atClient.
AtClientImplhas been replace withAtClientManagerinstance.createClientmethod has been removed and replaced withsetCurrentAtSign.atClientinstance can be obtained throughatClientManagerinstance.
/// **SDK 2.X**
await AtClientImpl.createClient('@alice', 'wavi', <preference>);
var atClient = await (AtClientImpl.getClient(atsign));
/// **SDK 3.X**
var atClientManager = await AtClientManager.getInstance().setCurrentAtSign('@alice', 'wavi', <preference>);
final atClient = atClientManager.atClient;
Starting listening to notifications.
startMonitormethod has been removed. With rSDK you must subscribe and listen toatClientinstance’sNotificationService.subscribemethod takes a optional parameterregexto filter the notifications.Decoding the response on callback function is not required.
/// **SDK 2.X**
await atClient!.startMonitor(<private_key>, _notificationCallBack, regex: 'atmosphere');
void _notificationCallBack(var response) {
response = response.replaceFirst('notification:', '');
var responseJson = jsonDecode(response);
var notificationKey = responseJson['key'];
var fromAtSign = responseJson['from'];
// ....... REST CODE .......
}
/// **SDK 3.X**
atClientManager.notificationService.subscribe(regex: 'wavi').listen(_notificationCallBack);
void _notificationCallBack(AtNotification atNotification) {
var notificationKey = atNotification.key;
var fromAtSign = atNotification.from;
// ....... REST CODE .......
}
Send notifications.
To send notification, you must use
AtClientManagerinstance’sNotificationServiceto accessnotifymethod.notifymethod takes a positional parameterNotificationParams.The
NotificationParamshas all the methods depending to the operation you do.forUpdate()- To send update notification.forDelete()- To send delete notification.forText()- To send a text message to another atSign.
/// **SDK 2.X**
await AtClientImpl.createClient('@alice', 'wavi', <preference>);
atClient = await (AtClientImpl.getClient('@alice'));
AtKey atKey = AtKey()..key = 'phone'
..sharedWith = '@bob'
..sharedBy = '@alice';
String atValue = '+1 445 446 7879';
atClient.notify(atKey, atValue, OperationEnum.update);
/// **SDK 3.X**
AtClientManager atClientManager = await AtClientManager.getInstance()
.setCurrentAtSign(‘@alice’, 'wavi', <preference>);
AtClient atClient = atClientManager.atClient;
AtKey atKey = AtKey()..key = 'phone'
..sharedWith = '@bob'
..sharedBy = '@alice';
String atValue = '+1 445 446 7879';
NotificationResult result = await atClientManager.notificationService
.notify(NotificationParams.forUpdate(atKey, value: atValue));
Check whether local and remote server are in sync.
Instead of using
SyncManager, useSyncServiceto accessisInSyncmethod.You must use
AtClientManagerinstance’sSyncServiceto accessisInSyncmethod.
/// **SDK 2.X**
final syncManager = atClient.getSyncManager();
bool isInSync = await syncManager.isInSync();
/// **SDK 3.X**
final syncService = atClientManager.syncService;
bool isInSync = await syncService.isInSync();
Calling on demand sync.
- This may not be needed by all apps with new SDK changes. sync is performed automatically on any update/delete operation on atClient.
/// **SDK 2.X**
final syncManager = atClient.getSyncManager();
await syncManager.sync();
/// **SDK 3.X**
final syncService = atClientManager.syncService;
syncService.sync();