cloud: fix upnp port persistence bug

This commit is contained in:
Koushik Dutta
2023-01-26 14:35:13 -08:00
parent 3cf9aad83f
commit 8e174842fa
4 changed files with 18 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
{
"scrypted.debugHost": "koushik-ubuntu",
"scrypted.debugHost": "127.0.0.1",
}

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/cloud",
"version": "0.0.56",
"version": "0.0.57",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/cloud",
"version": "0.0.56",
"version": "0.0.57",
"dependencies": {
"@eneris/push-receiver": "../../external/push-receiver",
"@scrypted/common": "file:../../common",

View File

@@ -50,5 +50,5 @@
"@types/nat-upnp": "^1.1.2",
"@types/node": "^18.11.18"
},
"version": "0.0.56"
"version": "0.0.57"
}

View File

@@ -111,6 +111,11 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings,
this.updatePortForward(this.storageSettings.values.upnpPort);
},
},
register: {
group: 'Advanced',
title: 'Register',
type: 'button',
},
});
upnpInterval: NodeJS.Timeout;
upnpClient = upnp.createClient();
@@ -120,6 +125,11 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings,
constructor() {
super();
this.storageSettings.settings.register.onPut = async () => {
const registrationId = await this.manager.registrationId;
await this.sendRegistrationId(registrationId);
}
this.storageSettings.settings.upnpStatus.onGet = async () => {
return {
hide: this.storageSettings.values.forwardingMode !== 'UPNP',
@@ -197,11 +207,10 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings,
this.console.log('Registering UPNP IP and Port', ip, upnpPort);
const registrationId = await this.manager.registrationId;
const data = await this.sendRegistrationId(registrationId, upnpPort);
const data = await this.sendRegistrationId(registrationId);
if (this.storageSettings.values.hostname && ip !== data.ip_address) {
this.log.a(`Scrypted Cloud could not verify the IP Address of your custom domain ${this.storageSettings.values.hostname}.`);
}
this.storageSettings.values.lastPersistedUpnpPort = upnpPort;
this.storageSettings.values.lastPersistedIp = ip;
}
}
@@ -348,10 +357,10 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings,
}
}
async sendRegistrationId(registration_id: string, upnp_port?: number) {
async sendRegistrationId(registration_id: string) {
const registration_secret = this.storageSettings.values.registrationSecret || crypto.randomBytes(8).toString('base64');
const q = qs.stringify({
upnp_port: upnp_port || this.storageSettings.values.lastPersistedUpnpPort,
upnp_port: this.storageSettings.values.upnpPort,
registration_id,
sender_id: DEFAULT_SENDER_ID,
registration_secret,
@@ -366,6 +375,7 @@ class ScryptedCloud extends ScryptedDeviceBase implements OauthClient, Settings,
});
this.console.log('registered', response.data);
this.storageSettings.values.lastPersistedRegistrationId = registration_id;
this.storageSettings.values.lastPersistedUpnpPort = this.storageSettings.values.upnpPort;
this.storageSettings.values.registrationSecret = registration_secret;
return response.data;
}