jo2 jo2 - 6 months ago 24
Javascript Question

OpenWhisk - socket.io - client possible?

I am trying to use socket.io from OpenWhisk action. I want to use it as a WebSocket client, but cannot seem to get it to work. Is socket.io client supported,
or is it only as server?

EDIT a client sample from http://socket.io/docs/

var io = require('socket.io');
var socket = io('ws://noderedjo2.mybluemix.net/ws/luftkvalitet/aqmeasure');
socket.on('connect', function () {
socket.send('hi');
});


This gives TypeError undefined is not a function. (on the io(...).

I guess one has to stand up a ws server, like in the Node.js samples on the same page...?!

Cheers
-jo2

Answer

OpenWhisk currently does not support a websocket client library as part of the Node.js action containers. The packages currently supported are listed here. I've opened an issue to add the most commonly used ones to this image as the use-case you laid out (running an OpenWhisk action and pushing to a websocket) sounds very useful.

socket.io itself only seems to be able to spin up a server, which is not suitable for an OpenWhisk action, as it is very short-running. socket.io-client (I suggested to add that) is needed to connect to a Websocket server.

Comments