ARI JS client mute error - javascript

Am currently developing a mute function for asterisk which I can run from my web front end using asterisk ARI.
But every time I try to run/call the mute function it gives me the following error:
Error: {
"message": "Channel not in Stasis application"
}
But it is, as far as am aware am passing the channel data directly to this function but to no avail.
Any one any suggestions or used to working with the ARI JS client?
Client Side
When mute button is clicked emit the data found in td to the server side.
$(document).on('click', '.mute', function () {
var mute = $(this).closest('td').siblings(':first-child').text();
socket.emit('muting', mute);
if ($(this).hasClass('mute')) {
$(this).removeClass('mute').addClass('unmute').find('span').text('Unmute');
} else {
console.log("Error");
}
});
Server Side
Store the data received from client side into a var and then call the stasis function.
io.sockets.on('connection', function (socket) {
updateSip();
socket.on('muting', function (data) {
mute(data);
console.log("Reached listener for muting")
});
});
Stasis function
Mute the channel which you have just passed from client to server side using ARI client commands, user will be muted and will show in stasis application.
function mute(mutval) {
console.log("Muting:" + mutval);
client.channels.mute
({
channelId : mutval
},
function (err) {
if (err) {
throw err;
}
});
}
The channel is in the application and being passed to the mute function, so am not sure as to way its not working currently.
EDIT: I have a hangup/kick function being handled in the same way and it works fine. Below is all my debugging.
Channel Dump
Free PBX Logs
Asterisk CLI Debug Level 5
Socket.io Error
I have also tried running it via socket.io and without it and the outcome is the same, I have other functions and they all work just fine, its just the mute function.

Turns out it would not run because it needed channel ID and not channel name, but functions would run with channel name.
It is inconsistency with the Asterisk ARI as it should work with channel name and not just channel ID like other functions did such as hangup and originate functions.

Related

(javascript) Unable to return value received in Socket.on(event)

Basically I have a client side code that sends data to the server, the server responds with data which calls a socket.on(event) in the client side code. Within the function that is immediately run I can log the received data but I cannot return it to outside for the life of me.
function receive_data(){
socket.off('Sent_data_to_client').on('Sent_data_to_client',(player_info));
console.log(player_info)
}
If i try to log player_info it tells me it is undefined "Uncaught (in promise) ReferenceError: player_info is not defined". I want to return player_info as the result of the receive_data function but it is undefined.
I am new to javascript and Socket.Io as a whole, i apologise for any obvious mistakes made.
Sockets in JS doesnt work like this. Have a specifics events.
https://nodejs.org/api/net.html#new-netsocketoptions
This is the Node JS documentation, but it doesn't matter because Node JS is based on "V8 engine", that is, it's the same.
As you can see in the documentation it indicates that there are a series of events that the socket can handle, among them the 'data', calling a callback function where you implement the necessary logic for your code.
In this case, for example:
const net = require('net');
const socket = new net.Socket();
// Open a socket connection with example.com
socket.connect(80, 'example.com', () => {
console.log('Connected');
});
socket.on('data', (data) => {
console.log(`Recived: ${data}`);
});
socket.on('error', (error) => {
console.log(`Error: ${error}`);
});
You should change the function definition to accept an argument, which will be the data that the server sends.
function receive_data(){
socket.off('Sent_data_to_client').on('Sent_data_to_client', function(player_info) {
console.log(player_info);
return player_info;
});
}

How do i recieve message from my arduino to my webpage as a text using javascript MQTT

I have been trying to find out how to i receive incoming message from my arduino to populate the data in my webpage.
It will be nice if anybody would know!
$(function () {
var client = mqtt.connect('mqtt://busHelper:busHelper#broker.shiftr.io', {
clientId: 'SmartBus'
});
client.on('connect', function () {
console.log('client has connected!');
});
client.on('message', function (topic, message) {
console.log('new message:', topic, message.toString());
});
client.subscribe('/UserStatus');
client.subscribe('/lat');
client.subscribe('/lang');
client.subscribe('/busSelection');
You could use websockets for the live update, try socket.io
https://socket.io/
Configire socket.io listener in backend that it will act as a bridge. In the on message function event socket.io will pass that message to frontend
To use either the Paho Javascript MQTT or the MQTT.js clients from with the browser, your broker needs to support MQTT over websockets.
This also means your URL needs to start with ws:// not mqtt:// to signify the protocol to use.

get data from mqtt broker -6lbr

I followed this tutorial :
Running the CC26xx Contiki Examples
but instead of using the cc26xx-demo I used the cc26xx-web-demo and successfully manged to get everything up and running and I can access the 6lbr web page, when I access the sensorTag page I see a mqtt configuration page as shown:
and if I click index in the sensorTag page (pic above) I get to see the data:
the question is , how can I write a simple nodejs js file that uses the mqtt broker information to grab all the sensorTag sensors data and save it in an local object.
I tried to do run this example but no luck
var mqtt = require('mqtt')
client = mqtt.createClient(1883, '192.168.1.109');
client.subscribe(what do I write here);
client.on('message', function(topic, message) { console.log(message); });
I don't know what I'm doing wrong
UPDATE:
mqtt configuration page :
javascript file :
and I run the js with node and listen on port 1883:
tcpdump seems to detect mqqt packets on 1883 port but I can't to seem to be able to console.log the sensor data when I run the js file with node ??
I went on the contiki wiki and came across this info
"You can also subscribe to topics and receive commands, but this will only work if you use "Org ID" != 'quickstart'. Thus, if you provide a different Org ID (do not forget the auth token!), the device will subscribe to:
iot-2/cmd/+/fmt/json"
does this mean that the topic to subscribe to is quickstart but even if that's so, I used '+/#' which subrcibes to all topics and still got nothing printing on the console ?
Hope this works for you:
var mqtt = require('mqtt');
var fs = require('fs');
var options = { port: PORT, host: HOST };/*user, password and others authentication if there.*/
var client = mqtt.connect('HOST', options);
client.on('connect', function ()
{
client.subscribe("topic, command or data");
client.publish("topic, command or data", data, function () {
});
});
client.on('error', function () { });
client.on('offline', function () { });
client.on('message', function (topic, message) {
console.log(message.toString());
});

Swampdragon: how to determine a channel the message was published to?

In my project backend sends a lot of messages published to different channels.
I can see from browser console the message arrived has channel property.
But the problem is a callback passed to swampdragon.onChannelMessage doesn't get that channel information. It gets strange channels list instead.
So when a message arrives (in browser) I can't figure out the channel it was published to and therefore handle it properly.
I found the code where that channel info is stripped off https://github.com/jonashagstedt/swampdragon/blob/master/swampdragon/static/swampdragon/js/dist/swampdragon.js#L261
if ('channel' in e.data) {
var channel = swampDragon.channels[e.data.channel];
delete(e.data['channel']);
swampDragon.settings.onchannelmessage(channel, e.data);
return;
}
So my question is how frontend developer can figure out what channel the message arrived was published to in order to be able to handle the message properly?
A little late, but in case you weren't able to solve this:
swampdragon.open(function() {
swampdragon.subscribe('notification', 'notification', null, function (context, data) {
// Successfully subscribed to the notification channel
}, function () {
console.error('Error', arguments);
});
});
swampdragon.onChannelMessage(function(channels, message) {
if (channels.indexOf('notification') > -1) {
// Message sent on the notification channel
}
});
In onChannelMessage the channels argument is an array of channels the incoming messages was sent to. You can use indexOf to check the channel you are interested in exists in the list.

Can't send message to only one specific room through node.js and socket.io

I have a problem that i don't seems to be able to solve it. I'm doing some kind of integration with remote system and my code is in iframe but that can't be important for this one i hope :).
I'm trying to send a message from server to specific room/client to begin session. First thing I do is when user log in, I emit message from client side with username.
CLIENT.JS
conn.on('connect', function () {
conn.emit('session', { username: 'some_username' });
}, false);
And on server side i get message and join socket to the room.
SERVER.JS
socket.on('session', function(session) {
socket.join(session.username);
});
I have another module that communicates with this server.js script through redis. So i have two more events in server.js
SERVER.JS
var userCreate = redis.createClient();
userCreate.subscribe("userCreate", "userCreate");
var userDestroy = redis.createClient();
userDestroy.subscribe("userDestroy", "userDestroy");
userCreate.on("message", function(channel, data) {
socket.to(JSON.parse(data).username).emit('beginSession', data);
});
userDestroy.on("message", function(channel, data) {
socket.to(JSON.parse(data).username).emit('endSession', data);
socket.leave(JSON.parse(data).username);
});
But when ever i try to emit message from server to client i broadcast message to everyone. What am I doing wrong?
Well, from the syntax point of view you are doing everything correct.
Didn't you forget to specify the userId property in the endSession?
userDestroy.on("message", function(channel, data) {
socket.to(JSON.parse(data).userId).emit('endSession', data);
socket.leave(JSON.parse(data).userId);
});
If that doesn't work - you should provide the contents of a data object

Categories

Resources