Skip to content

Commit

Permalink
Upgrade to new deviceInfo api from roku-deploy (#167)
Browse files Browse the repository at this point in the history
* Upgrade to new deviceInfo api from roku-deploy

* Fix tests
  • Loading branch information
TwitchBronBron authored Nov 5, 2023
1 parent acc5c90 commit 2ec2ef8
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 117 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"postman-request": "^2.88.1-postman.32",
"replace-in-file": "^6.3.2",
"replace-last": "^1.2.6",
"roku-deploy": "^3.10.3",
"roku-deploy": "^3.10.4",
"semver": "^7.5.4",
"serialize-error": "^8.1.0",
"smart-buffer": "^4.2.0",
Expand Down
72 changes: 0 additions & 72 deletions src/DeviceInfo.ts

This file was deleted.

15 changes: 9 additions & 6 deletions src/RendezvousTracker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { assert, expect } from 'chai';
import type { RendezvousHistory } from './RendezvousTracker';
import { RendezvousTracker } from './RendezvousTracker';
import { SceneGraphDebugCommandController } from './SceneGraphDebugCommandController';
import type { LaunchConfiguration } from './LaunchConfiguration';

describe('BrightScriptFileUtils ', () => {
let rendezvousTracker: RendezvousTracker;
Expand All @@ -12,12 +13,14 @@ describe('BrightScriptFileUtils ', () => {
let expectedHistory: RendezvousHistory;

beforeEach(() => {
let deviceInfo = {
'software-version': '11.5.0',
let launchConfig = {
'host': '192.168.1.5',
'remotePort': 8060
};
rendezvousTracker = new RendezvousTracker(deviceInfo);
let deviceInfo = {
softwareVersion: '11.5.0'
};
rendezvousTracker = new RendezvousTracker(deviceInfo, launchConfig as any);
rendezvousTracker.registerSourceLocator(async (debuggerPath: string, lineNumber: number) => {
//remove preceding pkg:
if (debuggerPath.toLowerCase().startsWith('pkg:')) {
Expand Down Expand Up @@ -279,13 +282,13 @@ describe('BrightScriptFileUtils ', () => {

describe('isEcpRendezvousTrackingSupported ', () => {
it('works', () => {
rendezvousTracker['deviceInfo']['software-version'] = '11.0.0';
rendezvousTracker['deviceInfo'].softwareVersion = '11.0.0';
expect(rendezvousTracker.doesHostSupportEcpRendezvousTracking).to.be.false;

rendezvousTracker['deviceInfo']['software-version'] = '11.5.0';
rendezvousTracker['deviceInfo'].softwareVersion = '11.5.0';
expect(rendezvousTracker.doesHostSupportEcpRendezvousTracking).to.be.true;

rendezvousTracker['deviceInfo']['software-version'] = '12.0.1';
rendezvousTracker['deviceInfo'].softwareVersion = '12.0.1';
expect(rendezvousTracker.doesHostSupportEcpRendezvousTracking).to.be.true;
});
});
Expand Down
16 changes: 8 additions & 8 deletions src/RendezvousTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import type { SourceLocation } from './managers/LocationManager';
import { logger } from './logging';
import { SceneGraphDebugCommandController } from './SceneGraphDebugCommandController';
import * as xml2js from 'xml2js';
import * as request from 'request';
import { util } from './util';
import * as semver from 'semver';

const telnetRendezvousString = 'on\n';
import type { DeviceInfo } from 'roku-deploy';
import type { LaunchConfiguration } from './LaunchConfiguration';

export class RendezvousTracker {
constructor(
private deviceInfo
private deviceInfo: DeviceInfo,
private launchConfiguration: LaunchConfiguration
) {
this.clientPathsMap = {};
this.emitter = new EventEmitter();
Expand All @@ -38,7 +38,7 @@ export class RendezvousTracker {
* Determine if the current Roku device supports the ECP rendezvous tracking feature
*/
public get doesHostSupportEcpRendezvousTracking() {
return semver.gte(this.deviceInfo['software-version'] as string, '11.5.0');
return semver.gte(this.deviceInfo.softwareVersion, '11.5.0');
}

public logger = logger.createLogger(`[${RendezvousTracker.name}]`);
Expand Down Expand Up @@ -140,7 +140,7 @@ export class RendezvousTracker {
* Run a SceneGraph logendezvous 8080 command and get the text output
*/
private async runSGLogrendezvousCommand(command: 'status' | 'on' | 'off'): Promise<string> {
let sgDebugCommandController = new SceneGraphDebugCommandController(this.deviceInfo.host as string);
let sgDebugCommandController = new SceneGraphDebugCommandController(this.launchConfiguration.host);
try {
this.logger.info(`port 8080 command: logrendezvous ${command}`);
return (await sgDebugCommandController.logrendezvous(command)).result.rawResponse;
Expand Down Expand Up @@ -197,7 +197,7 @@ export class RendezvousTracker {
* Get the response from an ECP sgrendezvous request from the Roku
*/
public async getEcpRendezvous(): Promise<EcpRendezvousData> {
const url = `http://${this.deviceInfo.host}:${this.deviceInfo.remotePort}/query/sgrendezvous`;
const url = `http://${this.launchConfiguration.host}:${this.launchConfiguration.remotePort}/query/sgrendezvous`;
this.logger.info(`Sending ECP rendezvous request:`, url);
// Send rendezvous query to ECP
const rendezvousQuery = await util.httpGet(url);
Expand Down Expand Up @@ -241,7 +241,7 @@ export class RendezvousTracker {
try {
this.logger.log(`Sending ecp sgrendezvous request: ${toggle}`);
const response = await util.httpPost(
`http://${this.deviceInfo.host}:${this.deviceInfo.remotePort}/sgrendezvous/${toggle}`,
`http://${this.launchConfiguration.host}:${this.launchConfiguration.remotePort}/sgrendezvous/${toggle}`,
//not sure if we need this, but it works...so probably better to just leave it here
{ body: '' }
);
Expand Down
12 changes: 7 additions & 5 deletions src/adapters/DebugProtocolAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ describe('DebugProtocolAdapter', function() {
let plugin: DebugProtocolServerTestPlugin;
let breakpointManager: BreakpointManager;
let projectManager: ProjectManager;
let launchConfig = {
host: '192.168.1.5',
remotePort: 8060
};
let deviceInfo = {
'software-version': '11.5.0',
'host': '192.168.1.5',
'remotePort': 8060
softwareVersion: '11.5.0'
};
let rendezvousTracker = new RendezvousTracker(deviceInfo);
let rendezvousTracker = new RendezvousTracker(deviceInfo, launchConfig as any);

beforeEach(async () => {
sinon.stub(console, 'log').callsFake((...args) => { });
Expand All @@ -62,7 +64,7 @@ describe('DebugProtocolAdapter', function() {
};
const sourcemapManager = new SourceMapManager();
const locationManager = new LocationManager(sourcemapManager);
const rendezvousTracker = new RendezvousTracker({});
const rendezvousTracker = new RendezvousTracker({}, {} as any);
breakpointManager = new BreakpointManager(sourcemapManager, locationManager);
projectManager = new ProjectManager(breakpointManager, locationManager);
projectManager.mainProject = new Project({
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/DebugProtocolAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { DebugProtocolClient } from '../debugProtocol/client/DebugProtocolClient
import type { Variable } from '../debugProtocol/events/responses/VariablesResponse';
import { VariableType } from '../debugProtocol/events/responses/VariablesResponse';
import type { TelnetAdapter } from './TelnetAdapter';
import type { DeviceInfo } from '../DeviceInfo';
import type { DeviceInfo } from 'roku-deploy';

/**
* A class that connects to a Roku device over telnet debugger port and provides a standardized way of interacting with it.
Expand Down Expand Up @@ -335,7 +335,7 @@ export class DebugProtocolAdapter {
* Determines if the current version of the debug protocol supports emitting compile error updates.
*/
public get supportsCompileErrorReporting() {
return semver.satisfies(this.deviceInfo['brightscript-debugger-version'], '>=3.1.0');
return semver.satisfies(this.deviceInfo.brightscriptDebuggerVersion, '>=3.1.0');
}

public async watchCompileOutput() {
Expand Down
13 changes: 8 additions & 5 deletions src/adapters/TelnetAdapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { TelnetAdapter } from './TelnetAdapter';
import * as dedent from 'dedent';
import { HighLevelType } from '../interfaces';
import { RendezvousTracker } from '../RendezvousTracker';
import type { LaunchConfiguration } from '../LaunchConfiguration';

describe('TelnetAdapter ', () => {
let adapter: TelnetAdapter;
let deviceInfo = {
'software-version': '11.5.0',
let launchConfig = {
'host': '192.168.1.5',
'remotePort': 8060
};
let rendezvousTracker = new RendezvousTracker(deviceInfo);
let deviceInfo = {
softwareVersion: '11.5.0'
};
let rendezvousTracker = new RendezvousTracker(deviceInfo, launchConfig as any);

beforeEach(() => {
adapter = new TelnetAdapter(
Expand All @@ -38,9 +41,9 @@ describe('TelnetAdapter ', () => {
vscode_is_string:falsetrue
vscode_is_string:falsefalse
vscode_is_string:truecat
vscode_is_string:truecat
vscode_is_string:truecat
vscode_is_string:true
vscode_is_string:true
vscode_is_string:true
`).length).to.equal(6);
});
it('handles basic arrays', () => {
Expand Down
13 changes: 6 additions & 7 deletions src/debugSession/BrightScriptDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fsExtra from 'fs-extra';
import { orderBy } from 'natural-orderby';
import * as path from 'path';
import { rokuDeploy, CompileError } from 'roku-deploy';
import type { RokuDeploy, RokuDeployOptions } from 'roku-deploy';
import type { DeviceInfo, RokuDeploy, RokuDeployOptions } from 'roku-deploy';
import {
BreakpointEvent,
DebugSession as BaseDebugSession,
Expand Down Expand Up @@ -49,7 +49,6 @@ import type { AugmentedSourceBreakpoint } from '../managers/BreakpointManager';
import { BreakpointManager } from '../managers/BreakpointManager';
import type { LogMessage } from '../logging';
import { logger, FileLoggingManager, debugServerLogOutputEventTransport, LogLevelPriority } from '../logging';
import type { DeviceInfo } from '../DeviceInfo';
import * as xml2js from 'xml2js';
import { VariableType } from '../debugProtocol/events/responses/VariablesResponse';
import { DiagnosticSeverity } from 'brighterscript';
Expand Down Expand Up @@ -277,12 +276,12 @@ export class BrightScriptDebugSession extends BaseDebugSession {

// fetches the device info and parses the xml data to JSON object
try {
this.deviceInfo = await this.fetchDeviceInfo(this.launchConfiguration.host, this.launchConfiguration.remotePort);
this.deviceInfo = await rokuDeploy.getDeviceInfo({ host: this.launchConfiguration.host, remotePort: this.launchConfiguration.remotePort, enhance: true });
} catch (e) {
return this.shutdown(`Unable to connect to roku at '${this.launchConfiguration.host}'. Verify the IP address is correct and that the device is powered on and connected to same network as this computer.`);
}

if (!this.deviceInfo['developer-enabled']) {
if (this.deviceInfo && !this.deviceInfo.developerEnabled) {
return this.shutdown(`Developer mode is not enabled for host '${this.launchConfiguration.host}'.`);
}

Expand All @@ -309,7 +308,7 @@ export class BrightScriptDebugSession extends BaseDebugSession {

await this.initRendezvousTracking();

this.createRokuAdapter(this.launchConfiguration.host, this.rendezvousTracker);
this.createRokuAdapter(this.rendezvousTracker);
if (!this.enableDebugProtocol) {
//connect to the roku debug via telnet
if (!this.rokuAdapter.connected) {
Expand Down Expand Up @@ -446,7 +445,7 @@ export class BrightScriptDebugSession extends BaseDebugSession {
}

private async _initRendezvousTracking() {
this.rendezvousTracker = new RendezvousTracker(this.deviceInfo);
this.rendezvousTracker = new RendezvousTracker(this.deviceInfo, this.launchConfiguration);

//pass the debug functions used to locate the client files and lines thought the adapter to the RendezvousTracker
this.rendezvousTracker.registerSourceLocator(async (debuggerPath: string, lineNumber: number) => {
Expand Down Expand Up @@ -1216,7 +1215,7 @@ export class BrightScriptDebugSession extends BaseDebugSession {
await this.shutdown();
}

private createRokuAdapter(host: string, rendezvousTracker: RendezvousTracker) {
private createRokuAdapter(rendezvousTracker: RendezvousTracker) {
if (this.enableDebugProtocol) {
this.rokuAdapter = new DebugProtocolAdapter(this.launchConfiguration, this.projectManager, this.breakpointManager, rendezvousTracker, this.deviceInfo);
} else {
Expand Down

0 comments on commit 2ec2ef8

Please sign in to comment.