diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c6e92bd..225ecbbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ * 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. * 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) ============================================================= diff --git a/dependencies.list b/dependencies.list index 14312953..eb7f65aa 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,5 +1,5 @@ PACKAGE_NAME=realm-js VERSION=2.0.0-rc20 -REALM_CORE_VERSION=4.0.1 -REALM_SYNC_VERSION=2.0.0-rc28 +REALM_CORE_VERSION=4.0.2 +REALM_SYNC_VERSION=2.0.1 REALM_OBJECT_SERVER_VERSION=2.0.0-rc.4 diff --git a/src/js_sync.hpp b/src/js_sync.hpp index 8e0310fd..1e6961c5 100644 --- a/src/js_sync.hpp +++ b/src/js_sync.hpp @@ -179,6 +179,7 @@ class SessionClass : public ClassDefinition { using Object = js::Object; using Value = js::Value; using ReturnValue = js::ReturnValue; + using Arguments = js::Arguments; public: 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 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 const properties = { {"config", {wrap, nullptr}}, {"user", {wrap, nullptr}}, @@ -206,6 +209,7 @@ public: MethodMap const methods = { {"_simulateError", wrap}, {"_refreshAccessToken", wrap}, + {"_overrideServer", wrap}, {"addProgressNotification", wrap}, {"removeProgressNotification", wrap}, }; @@ -511,6 +515,23 @@ void SessionClass::remove_progress_notification(ContextType ctx, FunctionType } } +template +void SessionClass::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>(this_object)->lock()) { + session->override_server(std::move(address), uint16_t(port)); + } +} + template class SyncClass : public ClassDefinition { using GlobalContextType = typename T::GlobalContext; diff --git a/src/object-store b/src/object-store index 0b1a2ad7..054b5c09 160000 --- a/src/object-store +++ b/src/object-store @@ -1 +1 @@ -Subproject commit 0b1a2ad7bc1269d4399785240a525e587cd9ddda +Subproject commit 054b5c09711555949f0e281a3bc195d4813b066e