diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a3236d68..9c03586d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [client] Fixed issue where tab icon glyphs weren't working on Mac in PR [1428](https://github.com/Microsoft/BotFramework-Emulator/pull/1428) - [client] Fixed issue where cancelling out of opening a transcript was creating a broken livechat window in PR [1441](https://github.com/Microsoft/BotFramework-Emulator/pull/1441) - [client] Fixed invisible scrollbar styling in log panel in PR [1442](https://github.com/Microsoft/BotFramework-Emulator/pull/1442) +- [main] Fixed issue where opening a livechat or bot via protocol wasn't working because ngrok wasn't being started on startup in PR [1446](https://github.com/Microsoft/BotFramework-Emulator/pull/1446) ## Removed - [main] Removed custom user agent string from outgoing requests in PR [1427](https://github.com/Microsoft/BotFramework-Emulator/pull/1427) diff --git a/packages/app/main/src/protocolHandler.spec.ts b/packages/app/main/src/protocolHandler.spec.ts index cc0ffbf81..5a00057ad 100644 --- a/packages/app/main/src/protocolHandler.spec.ts +++ b/packages/app/main/src/protocolHandler.spec.ts @@ -77,9 +77,13 @@ jest.mock('./settingsData/store', () => ({ }, }), })); + +let mockGetSpawnStatus = jest.fn(() => ({ triedToSpawn: true })); +const mockRecycle = jest.fn(() => null); const mockEmulator = { ngrok: { - getSpawnStatus: () => ({ triedToSpawn: true }), + getSpawnStatus: () => mockGetSpawnStatus(), + recycle: () => mockRecycle(), }, }; jest.mock('./emulator', () => ({ @@ -134,6 +138,8 @@ describe('Protocol handler tests', () => { statusCode: 200, body: '["activity1", "activity2", "activity3"]', }; + mockRecycle.mockClear(); + mockGetSpawnStatus.mockClear(); }); afterAll(() => { @@ -283,8 +289,12 @@ describe('Protocol handler tests', () => { const overrides = { endpoint: parseEndpointOverrides(protocol.parsedArgs) }; const overriddenBot = applyBotConfigOverrides(mockOpenedBot, overrides); + // ngrok should be kick-started if it hasn't tried to spawn yet + mockGetSpawnStatus = jest.fn(() => ({ triedToSpawn: false })); + await ProtocolHandler.openBot(protocol); + expect(mockRecycle).toHaveBeenCalled(); expect(mockCallsMade).toHaveLength(2); expect(mockCallsMade[0].commandName).toBe(SharedConstants.Commands.Bot.Open); expect(mockCallsMade[0].args).toEqual(['path/to/bot.bot', 'someSecret']); @@ -374,8 +384,12 @@ describe('Protocol handler tests', () => { mockEndpoint.name = 'New livechat'; mockedBot.services.push(mockEndpoint); + // ngrok should be kick-started if it hasn't tried to spawn yet + mockGetSpawnStatus = jest.fn(() => ({ triedToSpawn: false })); + await ProtocolHandler.openLiveChat(protocol); + expect(mockRecycle).toHaveBeenCalled(); expect(mockCallsMade).toHaveLength(1); expect(mockCallsMade[0].commandName).toBe(SharedConstants.Commands.Bot.RestartEndpointService); expect(mockCallsMade[0].args).toEqual([]); diff --git a/packages/app/main/src/protocolHandler.ts b/packages/app/main/src/protocolHandler.ts index 66da41a6f..31a7d00c6 100644 --- a/packages/app/main/src/protocolHandler.ts +++ b/packages/app/main/src/protocolHandler.ts @@ -202,8 +202,13 @@ export const ProtocolHandler = new class ProtocolHandlerImpl implements Protocol const appSettings: FrameworkSettings = getSettings().framework; if (appSettings.ngrokPath) { - const ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus(); - if (!ngrokSpawnStatus.triedToSpawn || (ngrokSpawnStatus.triedToSpawn && ngrokSpawnStatus.err)) { + let ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus(); + // if ngrok hasn't spawned yet, we need to start it up + if (!ngrokSpawnStatus.triedToSpawn) { + await Emulator.getInstance().ngrok.recycle(); + } + ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus(); + if (ngrokSpawnStatus.triedToSpawn && ngrokSpawnStatus.err) { throw new Error(`Error while trying to spawn ngrok instance: ${ngrokSpawnStatus.err || ''}`); } @@ -304,8 +309,13 @@ export const ProtocolHandler = new class ProtocolHandlerImpl implements Protocol const appSettings: FrameworkSettings = getSettings().framework; if (appSettings.ngrokPath) { - const ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus(); - if (!ngrokSpawnStatus.triedToSpawn || (ngrokSpawnStatus.triedToSpawn && ngrokSpawnStatus.err)) { + let ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus(); + // if ngrok hasn't spawned yet, we need to start it up + if (!ngrokSpawnStatus.triedToSpawn) { + await Emulator.getInstance().ngrok.recycle(); + } + ngrokSpawnStatus = Emulator.getInstance().ngrok.getSpawnStatus(); + if (ngrokSpawnStatus.triedToSpawn && ngrokSpawnStatus.err) { throw new Error(`Error while trying to spawn ngrok instance: ${ngrokSpawnStatus.err || ''}`); }