Merge pull request #1408 from realm/mar/override-server

Add the ability to override the server that's used by a given sync session
This commit is contained in:
Mark Rowe 2017-10-12 10:50:33 -07:00 committed by GitHub
commit 35f5116553
4 changed files with 25 additions and 4 deletions

View File

@ -16,7 +16,7 @@
* Upgrading to Realm Object Server 2.0.0-rc.4. * Upgrading to Realm Object Server 2.0.0-rc.4.
* OpenSSL for Android is distributed in a separate package, and the build system needed updates to accommendate this. * OpenSSL for Android is distributed in a separate package, and the build system needed updates to accommendate this.
* Added `-fvisibility=hidden` to Android builds (reduces size of `.so` file). * Added `-fvisibility=hidden` to Android builds (reduces size of `.so` file).
* Add `Session._overrideServer` to force an existing session to connect to a different server.
2.0.0-rc19 Release notes (2017-10-7) 2.0.0-rc19 Release notes (2017-10-7)
============================================================= =============================================================

View File

@ -1,5 +1,5 @@
PACKAGE_NAME=realm-js PACKAGE_NAME=realm-js
VERSION=2.0.0-rc20 VERSION=2.0.0-rc20
REALM_CORE_VERSION=4.0.1 REALM_CORE_VERSION=4.0.2
REALM_SYNC_VERSION=2.0.0-rc28 REALM_SYNC_VERSION=2.0.1
REALM_OBJECT_SERVER_VERSION=2.0.0-rc.4 REALM_OBJECT_SERVER_VERSION=2.0.0-rc.4

View File

@ -179,6 +179,7 @@ class SessionClass : public ClassDefinition<T, WeakSession> {
using Object = js::Object<T>; using Object = js::Object<T>;
using Value = js::Value<T>; using Value = js::Value<T>;
using ReturnValue = js::ReturnValue<T>; using ReturnValue = js::ReturnValue<T>;
using Arguments = js::Arguments<T>;
public: public:
std::string const name = "Session"; std::string const name = "Session";
@ -196,6 +197,8 @@ public:
static void add_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &); static void add_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &);
static void remove_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &); static void remove_progress_notification(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &);
static void override_server(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue&);
PropertyMap<T> const properties = { PropertyMap<T> const properties = {
{"config", {wrap<get_config>, nullptr}}, {"config", {wrap<get_config>, nullptr}},
{"user", {wrap<get_user>, nullptr}}, {"user", {wrap<get_user>, nullptr}},
@ -206,6 +209,7 @@ public:
MethodMap<T> const methods = { MethodMap<T> const methods = {
{"_simulateError", wrap<simulate_error>}, {"_simulateError", wrap<simulate_error>},
{"_refreshAccessToken", wrap<refresh_access_token>}, {"_refreshAccessToken", wrap<refresh_access_token>},
{"_overrideServer", wrap<override_server>},
{"addProgressNotification", wrap<add_progress_notification>}, {"addProgressNotification", wrap<add_progress_notification>},
{"removeProgressNotification", wrap<remove_progress_notification>}, {"removeProgressNotification", wrap<remove_progress_notification>},
}; };
@ -511,6 +515,23 @@ void SessionClass<T>::remove_progress_notification(ContextType ctx, FunctionType
} }
} }
template<typename T>
void SessionClass<T>::override_server(ContextType ctx, ObjectType this_object, Arguments args, ReturnValue&) {
args.validate_count(2);
std::string address = Value::validated_to_string(ctx, args[0], "address");
double port = Value::validated_to_number(ctx, args[1], "port");
if (port < 1 || port > 65535 || uint16_t(port) != port) {
std::ostringstream message;
message << "Invalid port number. Expected an integer in the range 1-65,535, got '" << port << "'";
throw std::invalid_argument(message.str());
}
if (auto session = get_internal<T, SessionClass<T>>(this_object)->lock()) {
session->override_server(std::move(address), uint16_t(port));
}
}
template<typename T> template<typename T>
class SyncClass : public ClassDefinition<T, void*> { class SyncClass : public ClassDefinition<T, void*> {
using GlobalContextType = typename T::GlobalContext; using GlobalContextType = typename T::GlobalContext;

@ -1 +1 @@
Subproject commit 0b1a2ad7bc1269d4399785240a525e587cd9ddda Subproject commit 054b5c09711555949f0e281a3bc195d4813b066e