Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Node.js with ASE did not work #4412

Closed
compulim opened this issue Jan 20, 2023 · 1 comment · Fixed by #4413
Closed

Using Node.js with ASE did not work #4412

compulim opened this issue Jan 20, 2023 · 1 comment · Fixed by #4413
Labels
bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team.

Comments

@compulim
Copy link
Contributor

compulim commented Jan 20, 2023

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Versions

What package version of the SDK are you using. 4.14.1
What nodejs version are you using 18
What browser version are you using N/A
What os are you using N/A

Describe the bug

Use DirectLineJS ASE or NodeWebSocket.connect() to connect to ASE or any Web Socket server.

To Reproduce

Steps to reproduce the behavior:

Using DirectLineJS

import { DirectLineStreaming } from 'botframework-directlinejs';

const TOKEN = '...';

async function main() {
  const token = await fetchToken();

  const connection = new DirectLineStreaming({
    domain: 'https://your-bot.azurewebsites.net/.bot/v3/directline',
    token: TOKEN
  });

  connection.connectionStatus$.subscribe(connectionStatus => {
    console.log(`Connection status: ${connectionStatus}`);
  });

  connection.activity$.subscribe(activity => {
    console.log(`Activity: ${activity.text}`);
  });
}

main();

Using NodeWebSocket.connect()

import { NodeWebSocket } from 'botframework-streaming';

async function main() {
  const socket = new NodeWebSocket();

  await socket.connect('wss://your-bot.azurewebsites.net/');
}

main();

Expected behavior

It should connect and will not throw any exceptions.

Screenshots

Using DirectLineJS

It should connect.

Failed to connect Error: Unable to connect client to Node transport.
/home/compulim/repos/experiment-dljs-ase-nodejs/node_modules/botframework-streaming/lib/webSocket/nodeWebSocketClient.js:63
                throw new Error(`Unable to connect client to Node transport.`);
                      ^

Error: Unable to connect client to Node transport.
    at WebSocketClient.<anonymous> (/home/compulim/repos/experiment-dljs-ase-nodejs/node_modules/botframework-streaming/lib/webSocket/nodeWebSocketClient.js:63:23)
    at Generator.throw (<anonymous>)
    at rejected (/home/compulim/repos/experiment-dljs-ase-nodejs/node_modules/botframework-streaming/lib/webSocket/nodeWebSocketClient.js:13:65)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Using NodeWebSocket.connect

It should not use URL as hostname. Because it is using the URL as the hostname, DNS cannot resolve wss://your-bot.azurewebsites.net/. Instead, it should resolve your-bot.azurewebsites.net.

node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: getaddrinfo ENOTFOUND wss://your-bot.azurewebsites.net/
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'wss://your-bot.azurewebsites.net/'
}

Additional context

NodeWebSocket.connect is not implemented correctly. Currently, it is:

  1. Create a Web Socket server (not client)
  2. Fake handshake
  3. Fake UPGRADE request
  4. Wait until the Web Socket is closed

It is broken in multiple ways:

  • It should not create a server to fake the connection
  • It is insufficiently faking the handshake
  • It should wait until the Web Socket is connected (open event), instead of close

I believe NodeWebSocket.connect never work and never tested properly.

@compulim compulim added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Jan 20, 2023
@orgads
Copy link

orgads commented Jan 27, 2023

@compulim I can now start the connection, but if I get an error, an unhandled exception is thrown from here, and I can't find a way to handle it. Looks similar to microsoft/BotFramework-DirectLineJS#170.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants