diff --git a/plugins/reolink/src/main.ts b/plugins/reolink/src/main.ts index 647d13b765..f8d65a181e 100644 --- a/plugins/reolink/src/main.ts +++ b/plugins/reolink/src/main.ts @@ -218,7 +218,13 @@ class ReolinkCamera extends RtspSmartCamera implements Camera, DeviceProvider, R async updateAbilities() { const api = this.getClient(); - const abilities = await api.getAbility(); + const apiWithToken = this.getClientWithToken(); + let abilities; + try { + abilities = await api.getAbility(); + } catch(e) { + abilities = await apiWithToken.getAbility(); + } this.storageSettings.values.abilities = abilities; this.console.log('getAbility', JSON.stringify(abilities)); } @@ -797,6 +803,7 @@ class ReolinkProvider extends RtspProvider { const rtspChannel = parseInt(settings.rtspChannel?.toString()) || 0; if (!skipValidate) { const api = new ReolinkCameraClient(httpAddress, username, password, rtspChannel, this.console); + const apiWithToken = new ReolinkCameraClient(httpAddress, username, password, rtspChannel, this.console, true); try { await api.jpegSnapshot(); } @@ -810,7 +817,11 @@ class ReolinkProvider extends RtspProvider { doorbell = deviceInfo.type === 'BELL'; name = deviceInfo.name ?? 'Reolink Camera'; ai = await api.getAiState(); - abilities = await api.getAbility(); + try { + abilities = await api.getAbility(); + } catch(e) { + abilities = await apiWithToken.getAbility(); + } } catch (e) { this.console.error('Reolink camera does not support AI events', e); diff --git a/plugins/reolink/src/reolink-api.ts b/plugins/reolink/src/reolink-api.ts index 5f5b7a3f66..283f37c9df 100644 --- a/plugins/reolink/src/reolink-api.ts +++ b/plugins/reolink/src/reolink-api.ts @@ -153,15 +153,37 @@ export class ReolinkCameraClient { const params = url.searchParams; params.set('cmd', 'GetAbility'); params.set('channel', this.channelId.toString()); - const response = await this.requestWithLogin({ + let response = await this.requestWithLogin({ url, responseType: 'json', }); - const error = response.body?.[0]?.error; + let error = response.body?.[0]?.error; if (error) { - this.console.error('error during call to getAbility', error); - throw new Error('error during call to getAbility'); + this.console.error('error during call to getAbility GET, Trying with POST', error); + + url.search = ''; + + const body = [ + { + cmd: "GetAbility", + action: 0, + param: { User: { userName: this.username } } + } + ]; + + response = await this.requestWithLogin({ + url, + responseType: 'json', + method: 'POST', + }, this.createReadable(body)); + + error = response.body?.[0]?.error; + if (error) { + this.console.error('error during call to getAbility GET, Trying with POST', error); + throw new Error('error during call to getAbility'); + } } + return { value: response.body?.[0]?.value || response.body?.value, data: response.body,