Skip to content

Commit

Permalink
Merge branch 'main' of github.com:koush/scrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Oct 21, 2024
2 parents d996088 + 04be700 commit 57eff2f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
15 changes: 13 additions & 2 deletions plugins/reolink/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
Expand Down
30 changes: 26 additions & 4 deletions plugins/reolink/src/reolink-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 57eff2f

Please sign in to comment.