Regarding to send the streamId as the headers while making the external Media

Hi Team,

I came across the problem in the external media Feature the problem is if set the connection in

/etc/asterisk/websocket_client.conf
[rtp_engine]
;type = websocket_client       ; Must be "websocket_client"
type = websocket_client
;connection_type = persistent  : "persistent" or "per_call_config"
                               ; Default: none
connection_type = per_call_config
;uri = ws://localhost:8765     ; The URI needed to contact the remote server.
                               ; If you've enabled tls, use "wss" for the scheme.
                               ; Default: none
uri = ws://streamimg-media-flow
;protocols = ari               ; The websocket protocol expected by the server.
                               ; Default: none
;username = username           ; An authentication username if required by the server.
                               ; Default: none
;password = password           ; The authentication password for the username.
                               ; Default: none
;connection_timeout = 500      ; Connection timeout in milliseconds.
                               ; Default: 500
;reconnect_interval = 1000     ; Number of milliseconds between (re)connection
                               ; attempts.
                               ; Default: 500
;reconnect_attempts = 4    

The problem is the us url is the loadbalancer and the request comes to that and then goes to backend ws server now the problem is there is not identifier that can tell the loadbalancer or any previlede that that websocket unique channel_id comes in the header part of that websocket request and thoguht the we can manage the logic if we want to route that call of streamId to a specific server, It is really usefull when it comes to build custom logic and handle the load distribution on the load balancer level on the basis of any Unique Call identifier that we can receive and for this case i believe that is channel_id ,

how can we do that ?? or we can have the privelege to set the dynamic host and port of the websocekt while creating the external media instead of getting it from the conf file

I believe that this is a needful change that we can do

[improvement]: Websocket channel with custom URI · Issue #1352 · asterisk/asterisk · GitHub was filed which ultimately resulted in the ability to add URI parameters to the outgoing URI, and is the approach others are taking for wanting information in a proxy.

I agreed jcolp but there is so such option doing this in external media ari apis

how can i send the headers that apis dont support this
i tried using this Code

const meta = encodeURIComponent(JSON.stringify({
callId: “12345”,
userId: “gaurav”,
env: “prod”
}));

return await channel.externalMedia(
{
channelId : externalMediaId,
app : streaming,chanType:streaming,
external_host : rtp_engine?meta=${meta},
format : format,
transport : “websocket”,
encapsulation : “none”,
connection_type: “client”,
direction : “both”,
transport_data : “hello”
});

but this does not work instead it throws me error

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

Error: {
“message”: “external_host must be a valid websocket_client connection id.”
}
at SwaggerRequest.swaggerError [as errorCallback] (/var/www/servetel_v3.0_nodejs/node_modules/ari-client/lib/resources.js:944:19)
at Object.error (/var/www/servetel_v3.0_nodejs/node_modules/swagger-client/lib/swagger.js:1077:24)
at EventEmitter.error (/var/www/servetel_v3.0_nodejs/node_modules/swagger-client/lib/swagger.js:1296:19)
at EventEmitter.emit (node:events:518:28)
at emit (/var/www/servetel_v3.0_nodejs/node_modules/shred/lib/shred/request.js:454:21)
at /var/www/servetel_v3.0_nodejs/node_modules/shred/lib/shred/request.js:473:9
at setBodyAndFinish (/var/www/servetel_v3.0_nodejs/node_modules/shred/lib/shred/response.js:103:7)
at IncomingMessage. (/var/www/servetel_v3.0_nodejs/node_modules/shred/lib/shred/response.js:120:7)
at IncomingMessage.emit (node:events:530:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.11.0

so i am not able to use this functionality using ari api’s

I have passed. that using the transport data like

Launching Stasis(voice,chanType:streaming,{“callId”:“12345”,“userId”:“gaurav”,“env”:“prod”}) on WebSocket/vpaas_rtp_engine/0x71c1740024b0

const meta = JSON.stringify({
callId: “12345”,
userId: “gaurav”,
env: “prod”
});

return await channel.externalMedia(
{
channelId : externalMediaId,
app : voice,chanType:streaming,
external_host : `vpaas_rtp_engine`,
format : format,
transport : “websocket”,
encapsulation : “none”,
connection_type: “client”,
direction : “both”,
transport_data : meta,
data : meta
});

transport_data must contain the same string you’d pass in a Dial dialstring.

So if you would call Dial like so…

Dial(WebSocket/vpaas_rtp_engine/c(alaw)v(callid=12345,userid=guarav,env=prod),10)

…you’d call externalMedia like so…

return await channel.externalMedia(
{
channelId : externalMediaId,
app : voice,
external_host : `vpaas_rtp_engine`,
format : "alaw",
transport : “websocket”,
encapsulation : “none”,
connection_type: “client”,
direction : “both”,
transport_data : "v(callid=12345,userid=guarav,env=prod)",
data : meta
});