amiws icon indicating copy to clipboard operation
amiws copied to clipboard

start command to send data

Open Newassistent opened this issue 4 years ago • 8 comments

Hi, you can have the websocket server (amiws) send data to the client only after receiving a command from the Javascript script. For example "ws.send ('start')"? if yes, how can i do?

Newassistent avatar Jun 11 '20 11:06 Newassistent

Hello, You can send commands to Asterisk whenever you want. it is AMI proxy, so you need to send AMI commands. Here is an example: https://github.com/staskobzar/amiws_queue/blob/master/src/store/mutations.js#L107

staskobzar avatar Jun 11 '20 12:06 staskobzar

thanks for the fast reply. I think I wasn't very clear... I would like to communicate with amiws proxy from browser (script javascript) and not from/to the Asterisk side. I would like to send a string from browser to amiws for enable the start of the transmission of json strings to the browser.

Newassistent avatar Jun 11 '20 12:06 Newassistent

Yes, you can send commands from browser with javascript. How to do this is your choice of implementation.

ws.send(JSON.stringify({
      Action: 'QueueAdd',
      AMIServerID: queue.sid,
      Queue: queue.name,
      Interface: member.interface,
      Penalty: member.penalty,
      Paused: member.paused,
      MemberName: member.name
    }))

staskobzar avatar Jun 11 '20 12:06 staskobzar

Here is example project: https://github.com/staskobzar/amiws_queue

staskobzar avatar Jun 11 '20 12:06 staskobzar

Thanks, I know this way to communicate with websocket, but I would like to add in the Amiws source files the possibility of NOT immediately sending all the json data to the browser, but after the handshake, wait my input to start the communication . Which source file or function should I work on?

Newassistent avatar Jun 11 '20 13:06 Newassistent

May you can just implement delay to connect and send in your javascript? I am sorry, but I probably do not understand what you are trying to do. Javascript is all under your control. You can simply connect amiws via websocket when your data is ready.

staskobzar avatar Jun 11 '20 14:06 staskobzar

ok, i will try the best solution thanks. Another question: I need to read the URI content in the amiws_lib.c source file, in the ami_ev_handler function. Can you help me, sorry i don't know C language very well. thanks a lot.

Newassistent avatar Jun 11 '20 16:06 Newassistent

I was using mongoose library for the networking (https://github.com/cesanta/mongoose/) you can see for helper function there. There are plenty of other C libraries which can help parse URI.

staskobzar avatar Jun 11 '20 17:06 staskobzar