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

Basic client not working #52

Open
timmeade opened this issue Aug 15, 2018 · 6 comments
Open

Basic client not working #52

timmeade opened this issue Aug 15, 2018 · 6 comments

Comments

@timmeade
Copy link

timmeade commented Aug 15, 2018

i converted the basic client to es6 as that is what we use. Also our FS servers are not on localhost and this is just seeming to not work. Any help or thoughts are appreciated.

// const FS = require('esl');

const fsCommand = (cmd) => {
  const client = FS.client(() => {
    this.api(cmd)
      .then((res) => {
        console.log(res);
        // res contains the headers and body of FreeSwitch's response.
        // res.body.should.match(/\+OK/);
      })
      .then(() => {
        console.log('exit');
        this.exit();
      })
      .then(() => {
        console.log('end');
        client.end();
      });
  });
  // console.log(client);
  client.connect(8021, '10.2.20.21');
};

fsCommand('reloadxml');
@shimaore
Copy link
Owner

@timmeade There are plenty of reasons this could fail (connectivity issues between the client and FreeSwitch, password different from default, etc.); running your script with DEBUG="*" in the environment should help diagnose.

@timmeade
Copy link
Author

interesting. that helped. Says the 'api' property is undefined.

  esl:response:trace onceAsync freeswitch_auth_request undefined +0ms
  esl:main Ready to start esl 9.0.1 client. +0ms
  esl:response:trace onceAsync: on_event freeswitch_auth_request [ { headers: { 'Content-Type': 'auth/request' }, body: undefined } ] +45ms
  esl:response:trace onceAsync freeswitch_command_reply 10000 +3ms
  esl:response:trace write { command: 'auth ClueCon', args: undefined } +1ms
  esl:response:trace onceAsync: on_event freeswitch_command_reply [ { headers: 
     { 'Content-Type': 'command/reply',
       'Reply-Text': '+OK accepted' },
    body: undefined } ] +19ms
  esl:response:trace send: received reply { command: 'auth ClueCon', args: undefined } +0ms
  esl:response:trace send: success { command: 'auth ClueCon', args: undefined } +0ms
  esl:response:trace onceAsync freeswitch_command_reply 10000 +1ms
  esl:response:trace write { command: 'event json CHANNEL_EXECUTE_COMPLETE BACKGROUND_JOB',
  args: undefined } +0ms
  esl:response:trace onceAsync: on_event freeswitch_command_reply [ { headers: 
     { 'Content-Type': 'command/reply',
       'Reply-Text': '+OK event listener enabled json' },
    body: undefined } ] +20ms
  esl:response:trace send: received reply { command: 'event json CHANNEL_EXECUTE_COMPLETE BACKGROUND_JOB',
  args: undefined } +0ms
  esl:response:trace send: success { command: 'event json CHANNEL_EXECUTE_COMPLETE BACKGROUND_JOB',
  args: undefined } +0ms
  esl:main Client report error: TypeError: Cannot read property 'api' of undefined +91ms

@timmeade
Copy link
Author

i tried hardcoding the command and got the same thing.

this.api('reloadxml')

@shimaore
Copy link
Owner

Ah, using the => shortcut won't work because it binds this inside your function.

Try for example

const fsCommand = function (cmd) {

etc.

@timmeade
Copy link
Author

Made no difference. I am using babel to transpose this, so curious what that would change.

@shimaore
Copy link
Owner

That's strange. Did you replace all the occurrences of => with function ()?

Basically => works as (function () {…}).bind(this). In the example you provided this means this.api tries to locate .api in your global (topmost) context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants