I am trying to create some karma tests and some of the functions I'm testing are supposed to make Websocket connections.
When running the code normally outside of Karma (using Chrome or Firefox), I see that my console log messages show that ws.onopen() fires as expected.
Not so when running in Karma using PhantomJS or even Chrome. I'm running version 0.12 of Karma. Could this be related to how Karma uses socket.io, instead of the browser's Websocket?
I am not doing anything in regards to manually writing a handshake.
webSocketConnect = function() {
ws = new WebSocket("ws://192.168.103.83:9000", "ws-xyz");
ws.onopen = function(evt) {
console.log("Connection is opened...");
};
};
When webSocketConnect is invoked, i.e.:
webSocketConnect();
I get no error but I don't see "Connection is opened..." in the console log.
Thanks for any help.
Edit: I think that the code is not getting executed because XSS protections are coming into play. I took the code above and started playing around with it in jsfiddle and saw that when I ran it I would get: "
SecurityError: The operation is insecure." I think it's a shame that Karma is not reporting any error. In fact Karma is completely silent and I wasn't even noticing that none of the websocket code was being executed at all.
Related
After two weeks of trying to run my site, I'm asking for your help.
Has anyone hosted Sails.JS on PlanetHoster?
My queries don't work because the connection to the database doesn't seem established.
Here's an example of some very simple queries:
await User.findOne({ email: email });
Here's what's displayed in the browser error console:
Uncaught (in promise) Error: Request failed with status code 500
I've tried to handle the errors but nothing is displayed...
try { await User.findOne({ email: email }); } catch(err) { // nothing }
So I've deduced that it was a problem with calling the database.
Unfortunately, I have no way to read the error logs ...
Yet, I've set the production.js file (config/env/production.js) and when I run NODE_ENV = production node app.js, it's still displayed in development. In fact, PlanetHoster doesn't require running the command sails lift, it just runs the platform already ...
I'm currently in a total blur as for where to go from here so if you have suggestions, I will take them with pleasure.
Thank you
Environment: Sails v1.0.2
I am using the gulp-aemsync plugin to sync my css and js changes to a clientlib on an AEM instance. A have a gulp task watching the js and css that runs gulp-aemsync fine (changes are on the site when i refresh), but being a bit lazy as i am it would be nice to get live reload working so that i never have to manually refresh the page while working.
I have tried to follow both these 2 online guides:
https://adobe-consulting-services.github.io/acs-aem-tools/features/live-reload/index.html
https://www.cognifide.com/our-blogs/cq/up-and-running-with-livereload-in-adobe-aem6
Followed the steps of:
installing Netty package on AEM instance
installing ACS AEM tools package on the AEM instance
installing the RemoteLiveReload chrome extension (the AEM instance is hosted on AWS)
That didn't work, so i got one of our DevOps engineers to open port 35729 (which is the default for Livereload) on the AEM instance. That still doesn't work, and when i click the chrome browser extension to sync it i get the following message:
Could not connect to LiveReload server. Please make sure that LiveReload 2.3 (or later) or another compatible server is running.
Can anyone help me figure this out as i'd really like to get it working to streamline my workflow.
Thanks
DISCLAIMER: This answer is based on a setup I had working at some point, and by no means is a complete/working answer. But it should give you an alternative to the other tools that exist and get you half way there.
I have not used the tools you are mentioning, but since you are using gulp and aemsync, you could do the following:
In your gulp setup, create a websocket server and basically make that server publish messages everytime aemsync is triggered to push content to AEM.
// start a websocket server
const WebSocket = require('ws'); // requires "npm install ws"
const wss = new WebSocket.Server({ port: 8081 });
const connections = [];
wss.on('connection', function connection(ws) {
connections.push(ws); // keep track of all clients
// send any new messages that come to this server, to all connected clients
ws.on('message', (d) => connections.forEach(connection => connection.send(d)));
});
// create a new websocket to send messages to the websocket server above
const ws = new WebSocket('ws://localhost:8081');
// send a regex to the server every second
// NOTE: CHANGE this to run when aemsync is triggered in your build
setInterval( () => ws.send('reload'), 1000 );
Then in your JS code (on AEM) or really in a <script> tag that you make sure will NOT go beyond your local (or dev/prod) you can setup a websocket listener to refresh the page:
socket = new WebSocket('ws://localhost:8081');
socket.onopen = // add function for when ws is open
socket.onclose = // add function for when ws is closed
socket.onerror = // add function for when ws errors
// listen to messages and reload!
socket.addEventListener('message', function (event) {
location.reload();
});
Alternatively, you could use the chrome plugin I've developed:
https://github.com/ahmed-musallam/websocket-refresh-chrome-ext
It's not perfect by any means. However, for a basic setup, it should work great! an you don't need to touch your AEM JS.
I followed a tutorial on how to make a multiplayer tetris game, here is the repo:
https://github.com/Leftier/tetris
It worked just fine on localhost so I tried to deploy it in heroku (https://tetrixtest.herokuapp.com/ --ASD to move Q/E to rotate) but I get the following error:
WebSocket connection to 'wss://tetrixtest.herokuapp.com/' failed: Error during WebSocket handshake: Unexpected response code: 200
while trying to create the webSocket in this line (connection-manager.js line 14):
this.conn = new WebSocket(`wss://${window.location.hostname}:${window.location.port}`)
I don't know much about webSockets,
at first I thought that heroku was not able to handle websockets but that wasn't the case so I tried using the link directly as an argument instead of reading it from the browser but still the same issue.
I would like some clues/hints about why does this happens, I searched in google and github, but I only found issues related to socket.io
For me the solution was to turn on "Session affinity" by running this command heroku features:enable http-session-affinity
More info at https://devcenter.heroku.com/articles/session-affinity
Session affinity, sometimes referred to as sticky sessions, is a
platform feature that associates all HTTP requests coming from an
end-user with a single application instance (web dyno).
I have a custom error handler that's supposed to show a notification with gulp-notify and then log it in the console.
module.exports = function () {
return plumber(function (err) {
notify({
title: 'Gulp Build Error',
message: 'Check the Task Runner or console for more details.'
}).write(err);
gutil.log(err);
this.emit('end');
});
};
I'm inclined to believe it's set up properly, because it's successfully printing this in the console (followed by the error details):
[15:35:04] gulp-notify: [Gulp Build Error] Check the Task Runner or console for more details.
However, no toast notification is being displayed. Oddly enough, this exact configuration was displaying it a few weeks ago. Does anyone see any red flags in the way this is configured or know of anything that may be preventing the toast notification from popping up? I'm on Windows 8.1, and SnoreToast is set to show notifications in Notifications Settings.
Thanks.
Update: This appears to be a Windows 8.1 issue. I ran this on a Windows 10 machine and the notification showed up.
When I exit from the debugger and relaunch I often get the message:
Error: Error #2002: Operation attempted on invalid socket.
at flash.net::ServerSocket/internalBind()
at flash.net::ServerSocket/bind()
I usually have to wait a while before I can relaunch the application without the error.
How can I avoid this?
private function openConnection():void
{
_serverSocket = new ServerSocket();
_serverSocket.addEventListener(ServerSocketConnectEvent.CONNECT, onConnect)
_serverSocket.bind(888);
_serverSocket.listen();
}
private function onConnect(e:ServerSocketConnectEvent):void
{
trace("Client is connected");
_clientSocket = e.socket;
_clientSocket.addEventListener(ProgressEvent.SOCKET_DATA, onData);
_clientSocket.addEventListener(Event.CLOSE, onConnectionClosed);
}
I don't think you can avoid it. I it just takes awhile for the OS to free the socket after AIR lets go of it. As a workaround, you could catch the error and use a timer to retry binding the socket every few seconds.
And AIR apps never need policy files (unless the code opening the socket was loaded from outside the application).