Skip to content
7 changes: 7 additions & 0 deletions src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export class UnauthorizedDeviceResponseError extends Error {
}
}

export class ECPSettingModeDisabledError extends Error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align with the new term ecpNetworkAccessMode

constructor(message: string, public results?: any) {
super(message);
Object.setPrototypeOf(this, ECPSettingModeDisabledError.prototype);
}
}

export class UnparsableDeviceResponseError extends Error {
constructor(message: string, public results?: any) {
super(message);
Expand Down
40 changes: 36 additions & 4 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1196,10 +1196,18 @@ export class RokuDeploy {

const url = `http://${options.host}:${options.remotePort}/query/device-info`;

let response = await this.doGetRequest({
url: url,
timeout: options.timeout
});
let response;
try {
response = await this.doGetRequest({
url: url,
timeout: options.timeout
});
} catch (e) {
if ((e as any)?.results?.response?.headers.server?.includes('Roku')) {
throw new errors.ECPSettingModeDisabledError('ECP Device Info request failed. ECP setting mode is disabled.', response);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align with new term

}
throw e;
}
try {
const parsedContent = await xml2js.parseStringPromise(response.body, {
explicitArray: false
Expand All @@ -1223,6 +1231,30 @@ export class RokuDeploy {
}
}

/**
* Get the External Control Protocol (ECP) setting mode of the device. This determines whether
* the device accepts remote control commands via the ECP API.
*
* @param options - Configuration options including host, remotePort, timeout, etc.
* @returns The ECP setting mode:
* - 'enabled': fully enabled and accepting commands
* - 'disabled': ECP is disabled (device may still be reachable but ECP commands won't work)
* - 'limited': Restricted functionality, text and movement commands only
* - 'permissive': Full access for internal networks
*/
public async getECPSetting(options: GetDeviceInfoOptions): Promise<'enabled' | 'disabled' | 'limited' | 'permissive'> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name this feature EcpNetworkAccessMode.

Also, let's extract the return value into a named type. Then we can reference that in here. (helps with devs on the outside wanting to reference this type).

export type EcpNetworkAccessMode= 'enabled' | 'disabled' | 'limited' | 'permissive'; 

try {
const deviceInfo = await this.getDeviceInfo(options);
return deviceInfo.ecpSettingMode;
} catch (e) {
if ((e as any)?.results?.response?.headers.server?.includes('Roku')) {
return 'disabled';
}
throw new errors.UnknownDeviceResponseError('Could not retrieve device ECP setting');
}

}

/**
* Normalize a deviceInfo field value. This includes things like converting boolean strings to booleans, number strings to numbers,
* decoding HtmlEntities, etc.
Expand Down
Loading