I use Twilio for a while, and today when I try to create a video Room,
The LED in my web cam appears then disappears and Twilio says this message:
Could not connect to Live: Signaling connection disconnected
When I do Inspect Element in Firefox I see this:
Firefox can’t establish a connection to the server at wss://sdkgw.us1.twilio.com/v1/VideoEvents.
This is how I used to connect with js
var connectOptions = {
name: room_name,
}
Twilio.Video.connect(token, connectOptions).then(roomJoined, function(error) {
var text = ('Could not connect to Live: ' + error.message )
ring('danger',text);
}
Does someone know what is wrong?
According to this bug report, this is possible if your token has expired. Instead of throwing a 20104, it throws 53000. Check your token. It was the same in my case.
Related
I have been trying to setup a wss server using nodejs, and have encountered a problem when trying to connect to it using chrome. The problem still occurs with all extensions disabled and in an incognito window so I've ruled that out as the problem.
When trying to connect using chrome, I get the error:
WebSocket connection to 'wss://www.domain-name.com/' failed:
with no reason given. On the server, socket.on('close') is called immediately with description "Connection dropped by remote peer" The close event has wasClean = false. This error does not occur when connecting from safari and Firefox so I'm not really sure where to look to see what's causing it. It's running on AWS Lightsail, and through an Apache proxy server.
The client code:
var socket = new WebSocket("wss://www.domain-name.com", 'JSON')
socket.onopen = function (event) {
console.log('open');
socket.send('socket opened')};
socket.onclose = function (event) {
console.log(event)};
socket.onmessage = function(message) {
console.log('receiving message from server...')};
And the server code:
const WebSocketServer = require('websocket').server;
app = express()
var server = app.listen(3000, () => {
console.log('Server started');
});
app.use(express.static('public'));
var wsServer = new WebSocketServer({
httpServer: server
});
wsServer.on('request', function(request){
console.log('New connection');
var connection = request.accept(null, request.origin);
connection.send('welcome from server...');
connection.on('message', function(message){
console.log(message)};
connection.on('close', function(reasonCode, description) {
console.log('disconnecting', reasonCode, description);
});
});
I also got the same error before switching to a secure WebSocket server. Any help would be appreciated, I've run out of places to look and ways to try and get more information to help out what the problem is.
EDIT: it seems to work on chrome on my phone, but not on chrome on my friends phone?
The problem was not specifying the protocol when accepting the connection. After about 20 hours working on the same bug and implementing an SSL certificate to get it to work, I changed:
request.accept(null, request.origin);
to:
request.accept('json', request.origin);
For some reason the chrome gives a really unhelpful error message. Microsoft edge the same error occurs, but gives a much more helpful error message so I could work out what was going on.
In my case, this was caused by passing an unused options value as the third parameter to the WebSocket constructor. The options parameter is supported by Node.js's ws module but not by browsers; however, instead of displaying a clean error message, Chrome closed the connection without a good description.
Bottom line up front: The Paho MQTT client sucessfully connects to my Mosquitto broker, but immediately disconnects when I try to publish a message or when it receives a message from a topic it's subscribed to. I've tried changing Mosquitto's listening port and authentication settings, and using two different versions of Paho MQTT, and I still have the same problem.
Now let's get into detail.
Intro: I'm making a dashboard for some facial recognition devices that communicate through MQTT. I set up a Mosquitto broker and I've had no problems connecting to it and communicating with the devices using the Paho MQTT client for Python (I made a kind of server to sync the device's info to a database). Now I'm making the web interface, so I added a WebSockets listener to my mosquitto.conf and wrote a script using the Paho MQTT library for Javascript to connect to it, subscribe to topic sgdrf/out, send a simple JSON message to topic sgdrf/in to get the list of online devices, and process the response of the Python server once it arrives.
Problem and attempted solutions: I ran the Django server, loaded the web page and opened the JS console to find that the MQTT client successfully connected to the broker but immediately disconnected when it tried to publish the message to topic sgdrf/in. Here's each line of console output with their explanations:
The message produced by the onSuccess function, which indicates that the client successfully connected to the Mosquitto broker:
Conexión exitosa al broker MQTT.
In the onConnected function, I added console.log(uri) to see the URI used by the client to connect to the broker. I got:
ws://localhost:61613/
After printing uri to console, I made the client subscribe to sgdrf/out and then print 'subscribed' to console:
subscribed
Then I call get_online_devices(mqtt_client), a function which creates a simple JSON string and publishes it to the topic sgdrf/in. But first, it prints the strign to the console so that I can check it (just in case):
{"operator":"GetOnlineDevices","messageId":96792535859850080000,"info":{}}
Then, when the publish method is actually executed, is when I get this error (captured by the onConnectionLost function):
Pérdida de conexión con el broker MQTT: AMQJS0005E Internal error. Error Message: message is not defined, Stack trace: No Error Stack Available (código: 5)
I checked the Mosquitto log file and it only says when a new client was connected and then when it was disconnected because of a socket error (each time for every page reload). Tail of /var/log/mosquitto/mosquitto.log:
1614796149: New connection from 127.0.0.1 on port 61612.
1614796149: New client connected from 127.0.0.1 as mqttx_53195902 (p2, c1, k60, u'admin').
1614796182: Socket error on client sgdrf_dashboard_8499, disconnecting.
1614796325: New client connected from ::ffff:127.0.0.1 as sgdrf_dashboard_1597 (p2, c1, k60, u'admin').
1614796325: Socket error on client sgdrf_dashboard_1597, disconnecting.
1614796336: New client connected from ::ffff:127.0.0.1 as sgdrf_dashboard_6565 (p2, c1, k60, u'admin').
1614796336: Socket error on client sgdrf_dashboard_6565, disconnecting.
1614796931: New client connected from ::ffff:127.0.0.1 as sgdrf_dashboard_9773 (p2, c1, k60, u'admin').
1614796931: Socket error on client sgdrf_dashboard_9773, disconnecting.
1614797168: Saving in-memory database to /var/lib/mosquitto/mosquitto.db.
I tried changing the listening port in mosquitto.conf, and enabling and disabling authentication, but it changes nothing. And obviously I've had to restart Mosquito every time I changed the config file. I don't think the problem is Mosquitto.
I have the same problem whether I use Paho MQTT version 1.1.0 or 1.0.3.
As an experiment, I commented out the call to get_online_devices in my Javascript so that it doesn't try to publish anything, reloaded the page and there was no error, as expected. Then, I used MQTTX to send a JSON message to the sgdrf/out topic to which the MQTT JS client is subscribed to, and it immediately disconnected with the same error message.
Code: At the bottom of the page (index.html) I have the following code (the original code has Django template tags to fill in some values, so this is the actual code received by the browser):
<!-- Paho MQTT -->
<script src="/static/js/paho-mqtt-min.js"></script>
<!-- Scripts -->
<script src="/static/js/dashboard.js"></script>
<script>
function get_online_devices(mqtt_client) {
cmd = {
operator: "GetOnlineDevices",
messageId: generate_random_number_n_exp(20),
info: {}
};
payload_string = JSON.stringify(cmd);
console.log(payload_string)
mqtt_client.publish("sgdrf/in", payload_string);
}
function add_device_to_list(device) {
// Omitted for brevity. It's not being used yet.
}
let mqtt_client = make_mqtt_client("localhost", 61613);
let connection_options = make_connection_options(
"admin",
"CENSORED_PASSWORD"
);
mqtt_client.onConnected = function(reconnect, uri) {
console.log(uri)
mqtt_client.subscribe("sgdrf/out");
console.log('subscribed');
get_online_devices(mqtt_client);
};
mqtt_client.onConnectionLost = mqtt_client_on_connection_lost;
mqtt_client.onMessageDelivered = mqtt_client_on_message_delivered;
mqtt_client.onMessageArrived = function (msg) {
// Omitted for brevity. Checks if the payload is a
// JSON object with the right data and calls
// add_device_to_list for each item of a list in it.
};
$(document).ready(function() {
mqtt_client.connect(connection_options);
$("#reload-device-list-btn").click(function() {
get_online_devices(mqtt_client);
});
});
</script>
The dashboard.js files mentioned above just has some functions that I think will be useful for other pages, so I separated them to a file:
// dashboard.js
function generate_random_number_n_exp(n) {
return parseInt(Math.random() * Math.pow(10, n), 10)
}
function make_mqtt_client(host, port) {
let client_id = "sgdrf_dashboard_" + generate_random_number_n_exp(4);
return new Paho.Client(host, port, '/', client_id);
}
function make_connection_options(user, password) {
let connection_options = {
userName: user,
password: password,
onSuccess: mqtt_client_on_success,
onFailure: mqtt_client_on_failure,
};
return connection_options;
}
function mqtt_client_on_success() {
console.log('Conexión exitosa al broker MQTT.');
}
function mqtt_client_on_failure(error) {
console.log(
'Fallo de conexión con el broker MQTT: ' + error.errorMessage
+ ' (código: ' + error.errorCode + ')'
);
}
function mqtt_client_on_connection_lost (error) {
console.log('Pérdida de conexión con el broker MQTT: ' + error.errorMessage
+ ' (código: ' + error.errorCode + ')'
);
}
function mqtt_client_on_message_delivered(msg) {
let topic = message.destinationName;
let payload = message.payloadString;
console.log("Mensaje enviado a " + topic + ": " + payload);
}
function mqtt_client_on_message_arrived(msg) {
let topic = message.destinationName;
let payload = message.payloadString;
console.log("Mensaje recibido de " + topic + ": " + payload);
}
Here are the contents of my mosquitto.conf file:
per_listener_settings true
listener 61612
allow_anonymous false
password_file /home/s8a/Projects/sgdrf/config/pwdfile.txt
listener 61613
protocol websockets
allow_anonymous false
password_file /home/s8a/Projects/sgdrf/config/pwdfile.txt
It just sets up a TCP listener and a WebSockets listener, both disallow anonymous connections, and authenticate using a pwdfile. As I said before, I have enabled and disabled anonymous connections, and changed the port number to 9001 and back to 61613, and I still have the same error.
Conclusion: I don't know what to do and this project's deadline is next week.
I feel kinda stupid, because it was really a trivial typing mistake. The problem is that the onMessageDelivered and onMessageArrived functions have msg as argument, but I wrote messagein the function body for some reason. That's what the "message is not defined" error meant, message is literally not defined. Anyway I fixed that and now it sends and receives messages without problems.
...
More detailed story: What was not trivial is how I figured it out.
I decided to get my hands dirty and opened the non-minified version of paho-mqtt.js. I looked for "Invalid error" and found where the error constant is defined, and two places where it's used in a catch block. In both catch blocks I noticed that there was a ternary operator checking if (error.hasOwnProperty("stack") == "undefined") but the true and false clauses were inverted, which is why I was getting "No Error Stack Available".
So I inverted the clauses, and indeed I got a stack trace in the console (maybe I should file a bug report to the Paho dev team when I can). The stack trace had my mqtt_client_on_message_delivered function right at the top, so I read it again and suddenly everything made sense. Then I felt stupid for wasting an afternoon on this.
Software versions:
"webtorrent-hybrid": "^4.0.1",
OS X 10.14.4
NPM: 6.13.4
Node: v8.17.0
var WebTorrent = require('webtorrent-hybrid')
var client = new WebTorrent()
client.on('error', (err) => {
console.error(`fatalError ${err.message || err}`);
process.exit(1);
});
client.seed('./c5l.mp4', function (torrent) {
torrent.on('warning', function (err) {
console.warn(err);
});
torrent.on('error', function (err) {
console.error(err);
});
console.log('client.seed done', {
magnetURI: torrent.magnetURI,
ready: torrent.ready,
paused: torrent.paused,
done: torrent.done,
infohash: torrent.infoHash
});
});
Gives me my magnet string. On the frontend I have:
script(src = 'https://cdnjs.cloudflare.com/ajax/libs/webtorrent/0.107.17/webtorrent.min.js')
script.
var client = new WebTorrent()
// working torrentId
var torrentId2 = 'magnet:?xt=urn:btih:c9e15763f722f23e98a29decdfae341b98d53056&dn=Cosmos+Laundromat&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fcosmos-laundromat.torrent'
// failing torrentId
var torrentId5 = 'magnet:?xt=urn:btih:f9435fb103d53a0b3cce14afbae867cc6999d76b&dn=c5l.mp4&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.openwebtorrent.com'
client.add(torrentId5, function (torrent) {
// Torrents can contain many files. Let's use the .mp4 file
var file = torrent.files.find(function (file) {
console.log(file);
return file.name.endsWith('.mp4')
})
// Display the file by adding it to the DOM.
// Supports video, audio, image files, and more!
file.appendTo('body')
})
When I have the working torrentId the video loads as expected. When I sub it out with the magnet url that was created via the webtorrent-hybrid package I first get some errors:
WebSocket connection to 'wss://tracker.fastcast.nz/' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED
Great, so I remove that tracker from the querystring, try again:
WebSocket connection to 'wss://tracker.btorrent.xyz/' failed: Unknown reason
Great, remove it again I get something that just hangs and nothing happens.
If I use the magnet on Brave it just hangs at Loading the torrent file list and the spinner endlessly spins.
What's going on? Thanks
// working torrentId
var torrentId2
magnet:?xt=urn:btih:c9e15763f722f23e98a29decdfae341b98d53056&dn=Cosmos+Laundromat&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fcosmos-laundromat.torrent
is/are a well seeded file(s) is means it works 90-100%
// failing torrentId
var torrentId5 = 'magnet:?xt=urn:btih:f9435fb103d53a0b3cce14afbae867cc6999d76b&dn=c5l.mp4&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.openwebtorrent.com'
is none or low seeded file(s) is means it works 0.1-10%
When I have the working torrentId the video loads as expected. When I
sub it out with the magnet url that was created via the
webtorrent-hybrid package I first get some errors:
WebSocket connection to 'wss://tracker.fastcast.nz/' failed: Error in
connection establishment: net::ERR_NAME_NOT_RESOLVED
Great, so I remove that tracker from the querystring, try again:
WebSocket connection to 'wss://tracker.btorrent.xyz/' failed: Unknown
reason
Great, remove it again I get something that just hangs and nothing
happens.
If I use the magnet on Brave it just hangs at Loading the torrent file
list and the spinner endlessly spins.
What's going on? Thanks
WebSocket connection to 'wss://tracker.fastcast.nz/' failed: Error in
connection establishment: net::ERR_NAME_NOT_RESOLVED
wss://tracker.fastcast.nz/ is dead and discontinued to support by the owner in year 2019
WebSocket connection to 'wss://tracker.btorrent.xyz/' failed: Unknown reason
is a busy tracker, the response rate is too long and runs in a cheap server due to low funding. so it works 30-90%. so the result is failed: Unknown reason
If I use the magnet on Brave it just hangs at Loading the torrent file
list and the spinner endlessly spins.
Webtorrent clients have some issues downloading/playing large files and unsupported file formats like .mkv (video/x-Matroska). And you can not see any notification if there is an error(s). It just hangs up.
I am trying to make a wss connection using JavaScript(mqttws31.js) client with generated self signed certificate but unable to create a connection and getting the below error.
"Firefox can’t establish a connection to the server at wss://localhost:8883/mqtt."
"Error: AMQJS0011E Invalid state not connected."
I have included the MQTT broker configuration details and JavaScript script code for reference.
MQTT Broker configuration( mosquitto.conf ).
port 8084
persistence true
persistence_file mosquitto.db
listener 1883 localhost
protocol mqtt
listener 8883
protocol websockets
allow_anonymous true
require_certificate false
cafile C:/Program Files/mosquitto/certs/certs/ca.crt
certfile C:/Program Files/mosquitto/certs/certs/server.crt
keyfile C:/Program Files/mosquitto/certs/certs/server.key
tls_version tlsv1.2
Javascript Client Code:
Below are inputs passing to the function.
host: localhost , port : 8883 and clientID : 1234.
function(){
that.client = new Paho.MQTT.Client(host, Number(port), clientId);
console.log("Connecting to " + host);
that.client.onConnectionLost = onConnectionLost;
that.client.onMessageArrived = onMessageArrived;
that.client.connect({
onSuccess : onConnect,
userName: 'user',
password:'password',
useSSL: true,
cleanSession : false
});
}
function onConnect() {
console.log('onConnect:');
that.client.subscribe("mgtl/#", {
qos : 2,
onSuccess : function(){
console.log('Acknowldgement recieved by sender');
},
onFailure : function(){
console.log('Subscribe request has failed or timed out');
}
});
that.client.subscribe("local/ack", {qos : 0});
console.log('mqtt connected');
}
Can anyone provide me the solution.
As hashed out in the comments, it sounds like your browser didn't trust the CA you used to sign your brokers certificate.
Browsers do not pop up the same dialog about untrusted certificates as they do for HTTPS connection as they expect the code to make a decision about what to do with a connection failure (but I don't think they actually provide the reason in the error messages)
The best way to track this sort of thing down is usually to make sure you check the network tab in the browsers developer tools.
As to why Chrome is not liking the imported CA cert, it may depend on what OS you are on as Chrome uses the system cert store unlike Firefox that maintains it's own iirc.
I'm using the following code from the Twilio Programmable Video Javascript Quickstart Guide, trying to Initialize the SDK with an access token:
https://www.twilio.com/docs/api/video/guide/identity
// Create an AccessManager to manage our Access Token
var accessManager = new Twilio.AccessManager('$TWILIO_ACCESS_TOKEN');
// Create a Conversations Client and connect to Twilio's backend
conversationsClient = new Twilio.Conversations.Client(accessManager);
conversationsClient.listen().then(function() {
console.log('Connected to Twilio!');
}, function (error) {
console.log('Could not connect to Twilio: ' + error.message);
});
But before even hitting the "could not connect to Twilio" error message designed into the above code, I get the following console error:
twilio-conversations.min.js:91 Client ERROR r {_errorData: Object, name: "LISTEN_FAILED", message: "Gateway responded with: 31201 Unknown authentication error"}
I'm testing this on an https-enabled development server, via ngrok.io. I've followed the code in the tutorial (link above) carefully. Does anyone understand what causes this cryptic 31201 error?