This commit is contained in:
Kenneth Geisshirt 2017-09-27 15:59:21 +02:00
parent 87ab6dd6d3
commit f4248f5d30
4 changed files with 40 additions and 29 deletions

View File

@ -42,6 +42,8 @@ namespace js {
using SharedUser = std::shared_ptr<realm::SyncUser>;
using WeakSession = std::weak_ptr<realm::SyncSession>;
static bool config_fs_done;
template<typename T>
class UserClass : public ClassDefinition<T, SharedUser> {
using GlobalContextType = typename T::GlobalContext;
@ -516,6 +518,7 @@ public:
static FunctionType create_constructor(ContextType);
static void set_sync_log_level(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
static void initialize(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &);
// private
static std::function<SyncBindSessionHandler> session_bind_callback(ContextType ctx, ObjectType sync_constructor);
@ -526,6 +529,7 @@ public:
MethodMap<T> const static_methods = {
{"setLogLevel", wrap<set_sync_log_level>},
{"initialize", wrap<initialize>},
};
};
@ -537,10 +541,7 @@ inline typename T::Function SyncClass<T>::create_constructor(ContextType ctx) {
Object::set_property(ctx, sync_constructor, "User", ObjectWrap<T, UserClass<T>>::create_constructor(ctx), attributes);
Object::set_property(ctx, sync_constructor, "Session", ObjectWrap<T, SessionClass<T>>::create_constructor(ctx), attributes);
// setup synced realmFile paths
ensure_directory_exists_for_file(default_realm_file_directory());
SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption);
config_fs_done = false;
return sync_constructor;
}
@ -647,5 +648,13 @@ void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType realm_constr
}
}
}
template<typename T>
void SyncClass<T>::initialize(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
// setup synced realmFile paths
ensure_directory_exists_for_file(default_realm_file_directory());
SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption);
return_value.set(Nan::Undefined());
}
} // js
} // realm

View File

@ -11,9 +11,9 @@ var Realm = require(realmModule);
function createObjects(user) {
const config = {
sync: { user,
url: `realm://localhost:9080/~/${realmName}`,
error: err => console.log(err)
sync: { user,
url: `realm://localhost:9080/~/${realmName}`,
error: err => console.log(err)
},
schema: [{ name: 'Dog', properties: { name: 'string' } }]
};
@ -30,6 +30,7 @@ function createObjects(user) {
setTimeout(() => process.exit(0), 3000);
}
Realm.Sync.initialize();
Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, registeredUser) => {
if (error) {
const registrationError = JSON.stringify(error);
@ -43,8 +44,8 @@ Realm.Sync.User.register('http://localhost:9080', username, 'password', (error,
createObjects(loggedUser);
}
});
}
else {
}
else {
createObjects(registeredUser);
}
});
});

View File

@ -29,7 +29,7 @@ const isNodeProccess = (typeof process === 'object' && process + '' === '[object
function node_require(module) {
return require(module);
}
}
let tmp;
let fs;
@ -37,7 +37,7 @@ let execFile;
if (isNodeProccess) {
tmp = node_require('tmp');
fs = node_require('fs');
fs = node_require('fs-extra');
execFile = node_require('child_process').execFile;
tmp.setGracefulCleanup();
}
@ -275,7 +275,7 @@ module.exports = {
});
});
},
testProgressNotificationsForRealmOpenAsync() {
if (!isNodeProccess) {
return Promise.resolve();
@ -292,7 +292,7 @@ module.exports = {
let progressNotificationCalled = false;
let config = {
sync: { user, url: `realm://localhost:9080/~/${realmName}`,
_onDownloadProgress: (transferred, total) => {
_onDownloadProgress: (transferred, total) => {
progressNotificationCalled = true
},
},
@ -486,7 +486,7 @@ module.exports = {
const progressCallback = (transferred, total) => {
resolve();
};
realm.syncSession.addProgressNotification('download', 'reportIndefinitely', progressCallback);
setTimeout(function() {
@ -495,7 +495,7 @@ module.exports = {
});
});
});
},
},
testProgressNotificationsUnregisterForRealmConstructor() {
if (!isNodeProccess) {
@ -519,7 +519,7 @@ module.exports = {
let realm = new Realm(config);
let unregisterFunc;
let writeDataFunc = () => {
realm.write(() => {
for (let i = 1; i <= 3; i++) {
@ -534,14 +534,14 @@ module.exports = {
if (failOnCall) {
reject(new Error("Progress callback should not be called after removeProgressNotification"));
}
syncFinished = transferred === total;
//unregister and write some new data.
if (syncFinished) {
if (syncFinished) {
failOnCall = true;
unregisterFunc();
//use second callback to wait for sync finished
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', (x, y) => {
if (x === y) {
@ -551,9 +551,9 @@ module.exports = {
writeDataFunc();
}
};
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', progressCallback);
unregisterFunc = () => {
realm.syncSession.removeProgressNotification(progressCallback);
};
@ -601,7 +601,7 @@ module.exports = {
});
});
});
},
},
testProgressNotificationsForRealmOpenAsync2() {
if (!isNodeProccess) {
@ -624,14 +624,14 @@ module.exports = {
};
let progressCalled = false;
Realm.openAsync(config,
Realm.openAsync(config,
(error, realm) => {
if (error) {
reject(error);
return;
}
TestCase.assertTrue(progressCalled);
resolve();
},
@ -645,5 +645,5 @@ module.exports = {
});
});
});
},
},
}

View File

@ -11,7 +11,8 @@
"terminate": "^1.0.8",
"tmp": "^0.0.30",
"url-parse": "^1.1.7",
"typescript": "^2.5.2"
"typescript": "^2.5.2",
"fs-extra": "^4.0.2"
},
"scripts": {
"check-typescript" : "tsc --noEmit --alwaysStrict ./../lib/index.d.ts",