diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c6e92bd..c3fe3254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -2.0.0-rc20 Release notes (2017-10-11) +2.0.0 Release notes (2017-10-12) ============================================================= ### Breaking changes * None @@ -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 eb7f65aa..d256fef4 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,5 +1,5 @@ PACKAGE_NAME=realm-js -VERSION=2.0.0-rc20 +VERSION=2.0.0-rc21 REALM_CORE_VERSION=4.0.2 REALM_SYNC_VERSION=2.0.1 REALM_OBJECT_SERVER_VERSION=2.0.0-rc.4 diff --git a/package.json b/package.json index 9d415702..6825cb55 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "realm", "description": "Realm is a mobile database: an alternative to SQLite and key-value stores", - "version": "2.0.0-rc20", + "version": "2.0.0-rc21", "license": "Apache-2.0", "homepage": "https://realm.io", "keywords": [ 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;