From 68e63e5def975763cf370f6de44cfc2e5b31a9d5 Mon Sep 17 00:00:00 2001 From: Skylar Sadlier Date: Thu, 19 Feb 2026 22:45:31 -0700 Subject: [PATCH] Upgrade from matrix-js-sdk v34 to v34.13.0 --- package-lock.json | 98 +++++++++++++++------------- package.json | 9 ++- src/matrix-crypt-file.js | 4 +- src/matrix-server-config.js | 124 +++++++++++++++--------------------- 4 files changed, 111 insertions(+), 124 deletions(-) diff --git a/package-lock.json b/package-lock.json index adefe96..198204c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "node-red-contrib-matrix-chat", - "version": "0.8.0", + "version": "0.9.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "node-red-contrib-matrix-chat", - "version": "0.8.0", + "version": "0.9.2", "license": "SEE LICENSE FILE", "dependencies": { "abort-controller": "^3.0.0", @@ -15,7 +15,7 @@ "got": "^12.0.2", "image-size": "^1.0.2", "isomorphic-webcrypto": "^2.3.8", - "matrix-js-sdk": "34.11.1", + "matrix-js-sdk": "^34.13.0", "mime": "^3.0.0", "node-fetch": "^3.3.0", "node-localstorage": "^2.2.1", @@ -25,7 +25,7 @@ "utf8": "^3.0.0" }, "engines": { - "node": ">=14.0.0" + "node": ">=18.0.0" } }, "node_modules/@ampproject/remapping": { @@ -4191,6 +4191,7 @@ "version": "9.1.0", "resolved": "https://registry.npmjs.org/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-9.1.0.tgz", "integrity": "sha512-CtPoNcoRW6ehwxpRQAksG3tR+NJ7k4DV02nMFYTDwQtie1V4R8OTY77BjEIs97NOblhtS26jU8m1lWsOBEz0Og==", + "license": "Apache-2.0", "engines": { "node": ">= 10" } @@ -4198,7 +4199,8 @@ "node_modules/@matrix-org/olm": { "version": "3.2.15", "resolved": "https://registry.npmjs.org/@matrix-org/olm/-/olm-3.2.15.tgz", - "integrity": "sha512-S7lOrndAK9/8qOtaTq/WhttJC/o4GAzdfK0MUPpo8ApzsJEC0QjtwrkC3KBXdFP1cD1MXi/mlKR7aaoVMKgs6Q==" + "integrity": "sha512-S7lOrndAK9/8qOtaTq/WhttJC/o4GAzdfK0MUPpo8ApzsJEC0QjtwrkC3KBXdFP1cD1MXi/mlKR7aaoVMKgs6Q==", + "license": "Apache-2.0" }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", @@ -6620,9 +6622,10 @@ "integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==" }, "node_modules/base-x": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.0.tgz", - "integrity": "sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ==" + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.1.tgz", + "integrity": "sha512-M7uio8Zt++eg3jPj+rHMfCC+IuygQHHCOU+IYsVtik6FWjuYpVt/+MRKcgsAMHh8mMFAwnB+Bs+mTrFiXjMzKg==", + "license": "MIT" }, "node_modules/base64-js": { "version": "1.5.1", @@ -6824,6 +6827,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/bs58/-/bs58-6.0.0.tgz", "integrity": "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw==", + "license": "MIT", "dependencies": { "base-x": "^5.0.0" } @@ -10629,9 +10633,9 @@ } }, "node_modules/loglevel": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.8.1.tgz", - "integrity": "sha512-tCRIJM51SHjAayKwC+QAg8hT8vg6z7GSgLJKGvzuPb1Wc+hLzqtuVLxp6/HzSPOozuK+8ErAhy7U/sVzw8Dgfg==", + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.9.2.tgz", + "integrity": "sha512-HgMmCqIJSAKqo68l0rS2AanEWfkxaZ5wNiEFb5ggm08lDs9Xl2KxBlX3PTcaD2chBM1gXAYf491/M2Rv8Jwayg==", "engines": { "node": ">= 0.6.0" }, @@ -10713,9 +10717,10 @@ "integrity": "sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==" }, "node_modules/matrix-js-sdk": { - "version": "34.11.1", - "resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-34.11.1.tgz", - "integrity": "sha512-rDbIUIqEsN/pbHb6haBQmjxxgeb9G3Df2IhPPOotUbX6R1KseA8yJ6TAY0YySM2zVaBV3yZ6dnKWexF/uWvZfA==", + "version": "34.13.0", + "resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-34.13.0.tgz", + "integrity": "sha512-AAU8ZdCawca+7ucQfdcC3LA85OtCTV7QeqcjvKt/ZZhU3xL9VoawuoRQ+4R6H8KZnqyJmT4j7bdeC0jG4qcqLg==", + "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.12.5", "@matrix-org/matrix-sdk-crypto-wasm": "^9.0.0", @@ -10726,33 +10731,34 @@ "jwt-decode": "^4.0.0", "loglevel": "^1.7.1", "matrix-events-sdk": "0.0.1", - "matrix-widget-api": "^1.8.2", + "matrix-widget-api": "^1.10.0", "oidc-client-ts": "^3.0.1", "p-retry": "4", "sdp-transform": "^2.14.1", "unhomoglyph": "^1.0.6", - "uuid": "10" + "uuid": "11" }, "engines": { "node": ">=20.0.0" } }, "node_modules/matrix-js-sdk/node_modules/uuid": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", - "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz", + "integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==", "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" ], + "license": "MIT", "bin": { - "uuid": "dist/bin/uuid" + "uuid": "dist/esm/bin/uuid" } }, "node_modules/matrix-widget-api": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/matrix-widget-api/-/matrix-widget-api-1.13.1.tgz", - "integrity": "sha512-mkOHUVzaN018TCbObfGOSaMW2GoUxOfcxNNlTVx5/HeMk3OSQPQM0C9oEME5Liiv/dBUoSrEB64V8wF7e/gb1w==", + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/matrix-widget-api/-/matrix-widget-api-1.17.0.tgz", + "integrity": "sha512-5FHoo3iEP3Bdlv5jsYPWOqj+pGdFQNLWnJLiB0V7Ygne7bb+Gsj3ibyFyHWC6BVw+Z+tSW4ljHpO17I9TwStwQ==", "dependencies": { "@types/events": "^3.0.0", "events": "^3.2.0" @@ -13767,9 +13773,9 @@ } }, "node_modules/sdp-transform": { - "version": "2.14.1", - "resolved": "https://registry.npmjs.org/sdp-transform/-/sdp-transform-2.14.1.tgz", - "integrity": "sha512-RjZyX3nVwJyCuTo5tGPx+PZWkDMCg7oOLpSlhjDdZfwUoNqG1mM8nyj31IGHyaPWXhjbP7cdK3qZ2bmkJ1GzRw==", + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/sdp-transform/-/sdp-transform-2.15.0.tgz", + "integrity": "sha512-KrOH82c/W+GYQ0LHqtr3caRpM3ITglq3ljGUIb8LTki7ByacJZ9z+piSGiwZDsRyhQbYBOBJgr2k6X4BZXi3Kw==", "bin": { "sdp-verify": "checker.js" } @@ -20333,9 +20339,9 @@ "integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==" }, "base-x": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.0.tgz", - "integrity": "sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ==" + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.1.tgz", + "integrity": "sha512-M7uio8Zt++eg3jPj+rHMfCC+IuygQHHCOU+IYsVtik6FWjuYpVt/+MRKcgsAMHh8mMFAwnB+Bs+mTrFiXjMzKg==" }, "base64-js": { "version": "1.5.1", @@ -23413,9 +23419,9 @@ } }, "loglevel": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.8.1.tgz", - "integrity": "sha512-tCRIJM51SHjAayKwC+QAg8hT8vg6z7GSgLJKGvzuPb1Wc+hLzqtuVLxp6/HzSPOozuK+8ErAhy7U/sVzw8Dgfg==" + "version": "1.9.2", + "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.9.2.tgz", + "integrity": "sha512-HgMmCqIJSAKqo68l0rS2AanEWfkxaZ5wNiEFb5ggm08lDs9Xl2KxBlX3PTcaD2chBM1gXAYf491/M2Rv8Jwayg==" }, "loose-envify": { "version": "1.4.0", @@ -23477,9 +23483,9 @@ "integrity": "sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==" }, "matrix-js-sdk": { - "version": "34.11.1", - "resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-34.11.1.tgz", - "integrity": "sha512-rDbIUIqEsN/pbHb6haBQmjxxgeb9G3Df2IhPPOotUbX6R1KseA8yJ6TAY0YySM2zVaBV3yZ6dnKWexF/uWvZfA==", + "version": "34.13.0", + "resolved": "https://registry.npmjs.org/matrix-js-sdk/-/matrix-js-sdk-34.13.0.tgz", + "integrity": "sha512-AAU8ZdCawca+7ucQfdcC3LA85OtCTV7QeqcjvKt/ZZhU3xL9VoawuoRQ+4R6H8KZnqyJmT4j7bdeC0jG4qcqLg==", "requires": { "@babel/runtime": "^7.12.5", "@matrix-org/matrix-sdk-crypto-wasm": "^9.0.0", @@ -23490,25 +23496,25 @@ "jwt-decode": "^4.0.0", "loglevel": "^1.7.1", "matrix-events-sdk": "0.0.1", - "matrix-widget-api": "^1.8.2", + "matrix-widget-api": "^1.10.0", "oidc-client-ts": "^3.0.1", "p-retry": "4", "sdp-transform": "^2.14.1", "unhomoglyph": "^1.0.6", - "uuid": "10" + "uuid": "11" }, "dependencies": { "uuid": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", - "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==" + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.0.tgz", + "integrity": "sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==" } } }, "matrix-widget-api": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/matrix-widget-api/-/matrix-widget-api-1.13.1.tgz", - "integrity": "sha512-mkOHUVzaN018TCbObfGOSaMW2GoUxOfcxNNlTVx5/HeMk3OSQPQM0C9oEME5Liiv/dBUoSrEB64V8wF7e/gb1w==", + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/matrix-widget-api/-/matrix-widget-api-1.17.0.tgz", + "integrity": "sha512-5FHoo3iEP3Bdlv5jsYPWOqj+pGdFQNLWnJLiB0V7Ygne7bb+Gsj3ibyFyHWC6BVw+Z+tSW4ljHpO17I9TwStwQ==", "requires": { "@types/events": "^3.0.0", "events": "^3.2.0" @@ -25867,9 +25873,9 @@ } }, "sdp-transform": { - "version": "2.14.1", - "resolved": "https://registry.npmjs.org/sdp-transform/-/sdp-transform-2.14.1.tgz", - "integrity": "sha512-RjZyX3nVwJyCuTo5tGPx+PZWkDMCg7oOLpSlhjDdZfwUoNqG1mM8nyj31IGHyaPWXhjbP7cdK3qZ2bmkJ1GzRw==" + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/sdp-transform/-/sdp-transform-2.15.0.tgz", + "integrity": "sha512-KrOH82c/W+GYQ0LHqtr3caRpM3ITglq3ljGUIb8LTki7ByacJZ9z+piSGiwZDsRyhQbYBOBJgr2k6X4BZXi3Kw==" }, "semver": { "version": "7.6.2", diff --git a/package.json b/package.json index 0a008d9..527815e 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "got": "^12.0.2", "image-size": "^1.0.2", "isomorphic-webcrypto": "^2.3.8", - "matrix-js-sdk": "34.11.1", + "matrix-js-sdk": "^34.13.0", "mime": "^3.0.0", "node-fetch": "^3.3.0", "node-localstorage": "^2.2.1", @@ -55,7 +55,7 @@ } }, "engines": { - "node": ">=14.0.0" + "node": ">=18.0.0" }, "keywords": [ "node-red", @@ -72,5 +72,8 @@ "name": "Skylar Sadlier", "url": "https://skylar.tech" }, - "license": "SEE LICENSE FILE" + "license": "SEE LICENSE FILE", + "engines": { + "node": ">=18.0.0" + } } diff --git a/src/matrix-crypt-file.js b/src/matrix-crypt-file.js index 779a1c8..a6236cf 100644 --- a/src/matrix-crypt-file.js +++ b/src/matrix-crypt-file.js @@ -58,11 +58,11 @@ module.exports = function(RED) { RED.nodes.registerType("matrix-decrypt-file", MatrixDecryptFile); function atob(a) { - return new Buffer.from(a, 'base64').toString('binary'); + return Buffer.from(a, 'base64').toString('binary'); } function btoa(b) { - return new Buffer.from(b).toString('base64'); + return Buffer.from(b).toString('base64'); } // the following was taken & modified from https://github.com/matrix-org/browser-encrypt-attachment/blob/master/index.js diff --git a/src/matrix-server-config.js b/src/matrix-server-config.js index f3acc44..d69cd49 100644 --- a/src/matrix-server-config.js +++ b/src/matrix-server-config.js @@ -1,51 +1,32 @@ +const {RelationType, TimelineWindow} = require("matrix-js-sdk"); + global.Olm = require('olm'); const fs = require("fs-extra"); -let RelationType, sdk, LocalStorageCryptoStore, RoomEvent, RoomMemberEvent, HttpApiEvent, ClientEvent, MemoryStore; - -(async () => { - const mod = await import("matrix-js-sdk"); - RelationType = mod.RelationType; - // matrix-js-sdk doesn't export a default – the top-level export is the same object: - sdk = mod; - - RoomEvent = mod.RoomEvent; - RoomMemberEvent = mod.RoomMemberEvent; - HttpApiEvent = mod.HttpApiEvent; - ClientEvent = mod.ClientEvent; - MemoryStore = mod.MemoryStore; - - // For LocalStorageCryptoStore, specify the file extension for Node 20+: - const cmod = await import("matrix-js-sdk/lib/crypto/store/localStorage-crypto-store.js"); - LocalStorageCryptoStore = cmod.LocalStorageCryptoStore; -})(); - +const sdk = require("matrix-js-sdk"); const { resolve } = require('path'); const { LocalStorage } = require('node-localstorage'); +const { LocalStorageCryptoStore } = require('matrix-js-sdk/lib/crypto/store/localStorage-crypto-store'); +const {RoomEvent, RoomMemberEvent, HttpApiEvent, ClientEvent, MemoryStore} = require("matrix-js-sdk"); require("abort-controller/polyfill"); // polyfill abort-controller if we don't have it if (!globalThis.fetch) { // polyfill fetch if we don't have it if (!globalThis.fetch) { import('node-fetch').then(({ default: fetch, Headers, Request, Response }) => { - Object.assign(globalThis, { fetch, Headers, Request, Response }); - }); + Object.assign(globalThis, { fetch, Headers, Request, Response }) + }) } } module.exports = function(RED) { // disable logging if set to "off" let loggingSettings = RED.settings.get('logging'); - if ( + if( typeof loggingSettings.console !== 'undefined' && typeof loggingSettings.console.level !== 'undefined' && ['info','debug','trace'].indexOf(loggingSettings.console.level.toLowerCase()) >= 0 ) { - import('matrix-js-sdk/lib/logger.js') - .then(({ logger }) => { - logger.disableAll(); - }) - .catch((err) => { - console.error("Error loading logger module:", err); - }); + const { logger } = require('matrix-js-sdk/lib/logger'); + logger.disableAll(); } function MatrixFolderNameFromUserId(name) { @@ -74,18 +55,17 @@ module.exports = function(RED) { this.autoAcceptRoomInvites = n.autoAcceptRoomInvites; this.e2ee = n.enableE2ee || false; this.globalAccess = n.global; - this.allowUnknownDevices = n.allowUnknownDevices || false; this.initializedAt = new Date(); node.initialSyncLimit = 25; - // Keep track of all consumers of this node to catch errors + // Keep track of all consumers of this node to be able to catch errors node.register = function(consumerNode) { node.users[consumerNode.id] = consumerNode; }; node.deregister = function(consumerNode) { delete node.users[consumerNode.id]; }; - + if(!this.userId) { node.log("Matrix connection failed: missing user ID in configuration."); return; @@ -118,7 +98,7 @@ module.exports = function(RED) { device_id = this.matrixClient.getDeviceId(); if(!device_id && node.enableE2ee) { - node.error("Failed to auto detect deviceId for this auth token. You will need to manually specify one. You may need to login to create a new deviceId.", {}); + node.error("Failed to auto detect deviceId for this auth token. You will need to manually specify one. You may need to login to create a new deviceId.", {}) } else { if(!stored_device_id || stored_device_id !== device_id) { node.log(`Saving Device ID (old:${stored_device_id} new:${device_id})`); @@ -135,7 +115,7 @@ module.exports = function(RED) { node.matrixClient.setDeviceDetails(device_id, { display_name: node.deviceLabel }).then( - function() {}, + function(response) {}, function(error) { node.error("Failed to set device label: " + error, {}); } @@ -173,6 +153,7 @@ module.exports = function(RED) { }), userId: this.userId, deviceId: (this.deviceId || getStoredDeviceId(localStorage)) || undefined + // verificationMethods: ["m.sas.v1"] }); node.debug(`hasLazyLoadMembersEnabled=${node.matrixClient.hasLazyLoadMembersEnabled()}`); @@ -198,7 +179,7 @@ module.exports = function(RED) { if(node.globalAccess) { try { node.context().global.set('matrixClient["'+node.userId+'"]', undefined); - } catch(e) { + } catch(e){ node.error(e.message, {}); } } @@ -212,15 +193,15 @@ module.exports = function(RED) { node.matrixClient.on(RoomEvent.Timeline, async function(event, room, toStartOfTimeline, removed, data) { if (toStartOfTimeline) { node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: paginated result"); - return; + return; // ignore paginated results } if (!data || !data.liveEvent) { node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: old message"); - return; + return; // ignore old message (we only want live events) } if(node.initializedAt > event.getDate()) { node.log("Ignoring" + (event.isEncrypted() ? ' encrypted' : '') +" timeline event [" + (event.getContent()['msgtype'] || event.getType()) + "]: (" + room.name + ") " + event.getId() + " for reason: old message before init"); - return; + return; // skip events that occurred before our client initialized } try { @@ -395,6 +376,7 @@ module.exports = function(RED) { } }); + node.matrixClient.on(HttpApiEvent.SessionLoggedOut, async function(errorObj){ // Example if user auth token incorrect: // { @@ -417,7 +399,6 @@ module.exports = function(RED) { node.log("Initializing crypto..."); await node.matrixClient.initCrypto(); node.matrixClient.getCrypto().globalBlacklistUnverifiedDevices = false; // prevent errors from unverified devices - node.matrixClient.getCrypto().globalErrorOnUnknownDevices = !node.allowUnknownDevices; } node.log("Connecting to Matrix server..."); await node.matrixClient.startClient({ @@ -467,7 +448,7 @@ module.exports = function(RED) { node.error("Auth check failed: " + err, {}); } } - ); + ) })(); } } @@ -492,19 +473,17 @@ module.exports = function(RED) { deviceId = req.body.deviceId || undefined, displayName = req.body.displayName || undefined; - (async () => { - const mod = await import("matrix-js-sdk"); - const matrixClient = mod.createClient({ - baseUrl: baseUrl, - deviceId: deviceId, - timelineSupport: true, - localTimeoutMs: '30000' - }); + const matrixClient = sdk.createClient({ + baseUrl: baseUrl, + deviceId: deviceId, + timelineSupport: true, + localTimeoutMs: '30000' + }); + matrixClient.timelineSupport = true; - matrixClient.timelineSupport = true; - - matrixClient.login('m.login.password', { + matrixClient.login( + 'm.login.password', { identifier: { type: 'm.id.user', user: userId, @@ -512,27 +491,23 @@ module.exports = function(RED) { password: password, initial_device_display_name: displayName }) - .then( - function(response) { - res.json({ - 'result': 'ok', - 'token': response.access_token, - 'device_id': response.device_id, - 'user_id': response.user_id, - }); - }, - function(err) { - res.json({ - 'result': 'error', - 'message': err - }); - } - ); - })().catch(err => { - res.json({ result: 'error', message: err.toString() }); - }); - } - ); + .then( + function(response) { + res.json({ + 'result': 'ok', + 'token': response.access_token, + 'device_id': response.device_id, + 'user_id': response.user_id, + }); + }, + function(err) { + res.json({ + 'result': 'error', + 'message': err + }); + } + ); + }); function upgradeDirectoryIfNecessary(node, storageDir) { let oldStorageDir = './matrix-local-storage', @@ -573,6 +548,9 @@ module.exports = function(RED) { } } + /** + * If a device ID is stored we will use that for the client + */ function getStoredDeviceId(localStorage) { let deviceId = localStorage.getItem('my_device_id'); if(deviceId === "null" || !deviceId) { @@ -588,4 +566,4 @@ module.exports = function(RED) { localStorage.setItem('my_device_id', deviceId); return true; } -}; \ No newline at end of file +}