Twilio IP messaging: Why am I getting error - WebSocket is already in CLOSING or CLOSED state - twilio

I can't get why my browser console shows an error from time to time. As I can see this error doesn't break anything.
media.twiliocdn.com/sdk/rtc/js/ip-messaging/releases/0.10.6/twilio-ip-messaging.js:22423
WebSocket is already in CLOSING or CLOSED state.
Also I noticed that after some time of inactivity in chat window, I get 'messageAdded' event with a huge latency (it's take around 5+ seconds after message was sent), but Typing event works fine. Why is this happens?

Closed socket errors indicate an issue with the local network and Chrome - can you confirm if you are going through a proxy? Could you also test using Firefox if possible?
If not, can you uncheck "automatically detect settings" in the network part of the Chrome Settings? Clear the cache and then update to the latest version and try again.
As far as the messageAdded event is concerned, what does your code look like?
Adding event listeners for IP Messaging:
//set up listeners for events for the active channel
activeChannel.on('messageAdded', addMessageToHistory);
And the messageAdded method I've seen used without issue:
function addMessageToHistory(message) {
console.log('Message added, adding a message to the history, sid:' + message.sid);
//get a handle to the chat history wrapper
var $messageHistory = $('#chat-history');
//process the message elements
var $messageEntry = $('<div id="' + message.sid + '" class="chat-message clearfix"/>');
var $messageContent = $('<div class="chat-message-content clearfix"/>');
var $messageTime = $('<span id="time_' + message.sid + '" class="chat-time"/>').text(formatDate(message.timestamp));
var $messageAuthor = $('<h5/>').text(message.author);
var $messageBody = $('<p id="msgbody_" ' + message.sid + '" />').text(message.body);
var $messageSeparator = $('<hr/>');
//build the message content
$messageTime.appendTo($messageContent);
$messageAuthor.appendTo($messageContent);
$messageBody.appendTo($messageContent);
//build the message entry
$messageContent.appendTo($messageEntry);
$messageSeparator.appendTo($messageEntry);
//ad the message entry to the history
$messageEntry.appendTo($messageHistory);
//scroll to end
$messageHistory.scrollTop($('#chat-history')[0].scrollHeight);
activeChannel.updateLastConsumedMessageIndex(message.index);
}
If your problem persists, then I'd suggest you contact support where we can take a closer look.

Related

Google Workspace Add-ons Quickstart Cats stopped working on iOS gmail

I've started to receive reports that the add-on we have been using for a while stopped working on iOS mobile. I was able to confirm this and started to dig into the issues. I've been able to reproduce the error with the "Quickstart: Cats Google Workspace Add-on" using multiple google accounts (gmail and workspace). It appears that cards, navigation, and notifications being returned from a function called by a button in card do not render on iOS Gmail. The code appears to work on desktop. I was able to demo this with the Quickstart tutorial. I removed the need for whitelist urls on mobile using the following createCatCard that shows the current time instead of a cat picture. This project works on desktop but not on iOS Gmail.
I've reported this to google via their issue tracker (https://issuetracker.google.com/issues/210484310) but they state that "The Issue Tracker is intended for reporting issues and asking for features related to development with/on Google products, therefore it is not the best place to ask for support on this matter."
Does anyone know if iOS Gmail add-ons are still supported and if there is a workaround for this behavior?
/**
* Creates a card with an image of a cat, overlayed with the text.
* #param {String} text The text to overlay on the image.
* #param {Boolean} isHomepage True if the card created here is a homepage;
* false otherwise. Defaults to false.
* #return {CardService.Card} The assembled card.
*/
function createCatCard(text, isHomepage) {
// Explicitly set the value of isHomepage as false if null or undefined.
if (!isHomepage) {
isHomepage = false;
}
// Use the "Cat as a service" API to get the cat image. Add a "time" URL
// parameter to act as a cache buster.
var now = new Date();
// Replace formward slashes in the text, as they break the CataaS API.
var caption = text.replace(/\//g, ' ');
var d = new Date();
var textLabel = CardService.newTextParagraph().setText("Current Time." + d.toLocaleTimeString());
// Create a button that changes the cat image when pressed.
// Note: Action parameter keys and values must be strings.
var action = CardService.newAction()
.setFunctionName('onChangeCat')
.setParameters({text: text, isHomepage: isHomepage.toString()});
var button = CardService.newTextButton()
.setText('Change cat')
.setOnClickAction(action)
.setTextButtonStyle(CardService.TextButtonStyle.FILLED);
var buttonSet = CardService.newButtonSet()
.addButton(button);
// Assemble the widgets and return the card.
var section = CardService.newCardSection()
.addWidget(textLabel)
.addWidget(buttonSet);
var card = CardService.newCardBuilder()
.addSection(section);
if (!isHomepage) {
// Create the header shown when the card is minimized,
// but only when this card is a contextual card. Peek headers
// are never used by non-contexual cards like homepages.
var peekHeader = CardService.newCardHeader()
.setTitle('Contextual Cat')
.setImageUrl('https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png')
.setSubtitle(text);
card.setPeekCardHeader(peekHeader)
}
return card.build();
}

Problem with messages if unanswered of out of business hours

Edit: resolved. Another question - how to play mp3 message in case of no answer after 30 sec?
I stucked with twilio settings.
We need to play mp3 message (because our language is not supported by twilio).
This is actual function (I followed manual from blog https://www.twilio.com/blog/2018/06/custom-javascript-twilio-functions-code-studio-flows.html)
exports.handler = function(context, event, callback) {
// With timezone:
// In Functions/Configure, add NPM name: moment-timezone, version: 0.5.14
// Timezone function reference: https://momentjs.com/timezone/
let moment = require('moment-timezone');
//
// timezone needed for Daylight Saving Time adjustment
let timezone = event.timezone || 'Europe/Vienna';
console.log("+ timezone: " + timezone);
//
const hour = moment().tz(timezone).format('H');
const dayOfWeek = moment().tz(timezone).format('d');
if ((hour >= 9 && hour < 17) && dayOfWeek <= 7) {
// "open" from 9am to 5pm, PST.
response = "open";
} else {
response = "after";
}
theResponse = response + " : " + hour + " " + dayOfWeek;
console.log("+ Time request: " + theResponse);
callback(null, theResponse);
};
I functions configuration, I set moment-timezone version 0.5.26 (but also tried 0.5.14), and twilio 3.37.1 (also older version = no sucess)
And this is studio flow used:
I also tried this flow, but no success:
If I calling to our twilio number out of business hours, it does not play out of business message, but it play message before call and then connect to out twilio number.
Thank you for advice and help (dummy here)
I found the mistake.
Box "Access control" was checked, that's why this flow does not worked.
After unchecking, it works.
Another question here - how I can play mp3 message in case of no answer after 30sec? Thank you
image 1
Set your Connect Call To widget timeout to 30 seconds and check the DialStatus of this Connect Call To widget using the follow-up Split Based On widget, to see if the value was other than completed and if so, play .mp3 using the Say/Play widget. Watch out for the far-end having voice mail enabled, which may pickup before 30 seconds.

MT4 communication methods

I have tried but couldn't figure it out on my own.
I know MT4 provides Pipe and WebRequest(), as a means of communication, but WebSocket isn't built as part of the Programming. So for now, Pipe is the only thing available. But communication with Pipe breaks at some point. It skips some signals when sent.
How can I get around this please guys?
How can I get around this please guys ?
Free to use either a ZeroMQ or a nanomsg signalling / messaging framework
having been in such a need many years back, started to use ZeroMQ / MQL4-binding, so as to make MetaTrader Terminal work inside a distributed-computing QuantFX-analytics and ML-based augmented trading system.
No O/S localhost-only pipe, no file-based masquerades, but a fair, distributed, low-latency signalling/messaging, with:
remote keyboard / terminal system-console ( yes, added a DSL command language )
remote centralised logs ( avoids MQL4 execution get blocked from resource contentions )
distributed remote AI/ML-predictive engine, with latency under << 80 [ms] RTT
distributed remote automated trade-management processing
ZeroMQ is a way to go, if integration needs are to be kept under your own design controls. A brief sketch was presented here, in [ ZeroMQ hierarchy in less than a five seconds ] Section.
Feel free to read more posts on this and about the differences between WebSockets and ZeroMQ here, in the zeromq and other related posts.
I tried ZeroMQ but couldn't get it working properly.
I'm using WinSockets now and so far have no problems with it.
See: https://www.mql5.com/en/blogs/post/706665
Here you will find a way to use WinSockets in MQL as a server or as a client or both.
I know links can become dead but there is no way to attach files to this answer and the code does not format properly so I cannot include it.
You can then use any programming language that also supports sockets to communicate with your MQL EA. I'm using the build-in node implementation.
See: https://www.digitalocean.com/community/tutorials/how-to-develop-a-node-js-tcp-server-application-using-pm2-and-nginx-on-ubuntu-16-04
const net = require('net');
const port = 7070;
const host = '127.0.0.1';
const server = net.createServer();
server.listen(port, host, () => {
console.log('TCP Server is running on port ' + port + '.');
});
let sockets = [];
server.on('connection', function(sock) {
console.log('CONNECTED: ' + sock.remoteAddress + ':' + sock.remotePort);
sockets.push(sock);
sock.on('data', function(data) {
console.log('DATA ' + sock.remoteAddress + ': ' + data);
// Write the data back to all the connected, the client will receive it as data from the server
sockets.forEach(function(sock, index, array) {
sock.write(sock.remoteAddress + ':' + sock.remotePort + " said " + data + '\n');
});
});
// Add a 'close' event handler to this instance of socket
sock.on('close', function(data) {
let index = sockets.findIndex(function(o) {
return o.remoteAddress === sock.remoteAddress && o.remotePort === sock.remotePort;
})
if (index !== -1) sockets.splice(index, 1);
console.log('CLOSED: ' + sock.remoteAddress + ' ' + sock.remotePort);
});
});
Pipe in MQL is implemented through files, so you can use files instead of pipes - you will receive same or faster result, and no need to care of the communication

Socket.io taking a long time to disconnect on Heroku

I'm running a Nodejs server allowing users to connect with socket.io. Locally, when the tab or window is closed, the disconnect event is called immediately. However, when done on Heroku the event takes around a minute and a half to be called.
I have read the other similar questions, and they all reference either heartbeat or ping timeout. The most current API I can find is this, seeming to indicate I should use pingTimeout and pingInterval. My current pingTimeout code is:
var Server = require('socket.io');
var io = new Server(http, {pingInterval: 5000, pingTimeout: 10000});
And I have tried:
var Server = require('socket.io');
var io = new Server(http, {'pingInterval': 5000, 'pingTimeout': 10000});
As well. Neither options seem to have any effect on the 1 and a half minute wait time when a user closes the tab.
What can I do to debug this, and is there something simple I'm doing wrong?
i am currently using io.set to specify this and it works (socket.io v1.3.7 and node 4x stable). hope this helps
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.set('heartbeat timeout', 50000);
io.set('heartbeat interval', 2000);

How to implement IndexDB in IOS

I am developing a mobile application using phonegap, Initially I have developed using WEBSQL but now I m planning to move it on INDEXDB. The problem is it does not have direct support on IOS , so on doing much R&D I came to know using IndexedDB Polyfil we can implement it on IOS too
http://blog.nparashuram.com/2012/10/indexeddb-example-on-cordova-phonegap.html
http://nparashuram.com/IndexedDBShim/
Can some please help me how to implement this as there are not enough documentation for this and I cannot figure out a any other solution / api except this
I have tested this on safari 5.1.7
Below is my code and Error Image
var request1 = indexedDB.open(dbName, 5);
request1.onsuccess = function (evt) {
db = request1.result;
var transaction = db.transaction(["AcceptedOrders"], "readwrite");
var objectStore = transaction.objectStore("AcceptedOrders");
for (var i in data) {
var request = objectStore.add(data[i]);
request.onsuccess = function (event) {
// alert("am again inserted")
// event.target.result == customerData[i].ssn;
};
}
};
request1.onerror = function (evt) {
alert("IndexedDB error: " + evt.target.errorCode);
};
Error Image
One blind guess
Maybe your dbName contains illegal characters for WebSQL database names. The polyfill doesn't translate your database names in any kind. So if you create a database called my-test, it would try to create a WebSQL database with the name my-test. This name is acceptable for an IndexedDB database, but in WebSQL you'll get in trouble because of the - character. So your database name has to match both, the IndexedDB and the WebSQL name conventions.
... otherwise use the debugger
You could set a break point onto your alert(...); line and use the debugger to look inside the evt object. This way you may get either more information about the error itself or more information to share with us.
To do so, enable the development menu in the Safari advanced settings, hit F10 and go to Developer > Start debugging JavaScript (something like that, my Safari is in a different language). Now open then "Scripts" tab in the developer window, select your script and set the break point by clicking on the line number. Reload the page and it should stop right in your error callback, where you can inspect the evt object.
If this doesn't help, you could get the non-minified version of the polyfill and try set some breakpoints around their open function to find the origin of this error.
You could try my open source library https://bitbucket.org/ytkyaw/ydn-db/wiki/Home. It works on iOS and Android.

Resources