Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const connect = (store, next, action, callSocket) => {
// initial setup
if(!memoizedSocket && !pendingConnection && action.type === SOCKET_REQUEST) {
pendingConnection = true
const socket = socketCluster.connect({
hostname: process.env.SOCKET_HOSTNAME || location.hostname,
path: process.env.SOCKET_PATH || '/ws',
autoReconnect: true,
autoReconnectOptions: process.env.AUTO_RECONNECT_OPTIONS,
authTokenName: process.env.AUTH_TOKEN_NAME,
})
attachListeners(store, next, action, socket, callSocket)
socket.on('connect', data => {
// yay! lets memoize the socket
memoizedSocket = socket
pendingConnection = false
const authToken = socket.getAuthToken()
const channels = authToken && authToken.channels || undefined
export function loadNotes() {
const query = `
subscription {
getAllNotes {
id,
title,
laneId,
userId,
index
}
}`;
const serializedParams = prepareGraphQLParams({query});
const sub = 'getAllNotes';
const socket = socketCluster.connect(socketOptions);
socket.subscribe(serializedParams, {waitForAuth: true});
return dispatch => {
// client-side changefeed handler
socket.on(sub, data => {
const meta = {synced: true};
if (!data.old_val) {
dispatch(addNote(data.new_val, meta));
} else if (!data.new_val) { // eslint-disable-line no-negated-condition
dispatch(deleteNote(data.old_val.id, meta));
} else {
dispatch(updateNote(data.new_val, meta));
}
});
socket.on('unsubscribe', channelName => {
if (channelName === sub) {
dispatch({type: CLEAR_NOTES});
it('should connect with valid options', function (done) {
socket = scClient.connect(validOptions);
socket.on('connecting', function (data) {
console.log('CONNECTING...', data);
});
socket.on('connectAbort', function (data) {
done('should not reject handshake with valid params', data);
});
socket.on('connect', function (data) {
done();
});
socket.on('error', function (err) {
done(err);
});
before(function() {
socket = scClient.connect({ hostname: 'localhost', port: 8000 });
socket.connect();
socket.on('error', function(error) {
console.error('Socket1 error', error);
});
socket2 = scClient.connect({ hostname: 'localhost', port: 8000 });
socket2.connect();
socket.on('error', function(error) {
console.error('Socket2 error', error);
});
});
before(function() {
socket = scClient.connect({ hostname: 'localhost', port: 8000 });
socket.connect();
socket.on('error', function(error) {
console.error('Socket1 error', error);
});
socket2 = scClient.connect({ hostname: 'localhost', port: 8000 });
socket2.connect();
socket.on('error', function(error) {
console.error('Socket2 error', error);
});
});
testNodeConfigs.forEach(testNodeConfig => {
monitorWSClient.wsPort = testNodeConfig.wsPort;
var socket = scClient.connect(monitorWSClient);
wampClient.upgradeToWAMP(socket);
socket.on('connect', () => {
sockets.push(socket);
connectedTo += 1;
if (connectedTo === testNodeConfigs.length) {
done();
}
});
socket.on('error', () => {});
socket.on('connectAbort', () => {
done(
`Unable to establish WS connection with ${testNodeConfig.ip}:${
testNodeConfig.wsPort
}`
);
});
function connect() {
clientSocket = scClient.connect(validClientSocketOptions);
clientSocket.on('connectAbort', () => {
connectAbortStub();
});
clientSocket.on('disconnect', () => {
disconnectStub();
});
clientSocket.on('error', () => {
errorStub();
});
clientSocket.on('close', () => {
closeStub();
});
clientSocket.on('connect', () => {
connectStub();
});
}
initRemoteListeners(options) {
const defaultSocketOptions = {
secure: false,
hostname: 'localhost',
port: 5000,
autoReconnect: true,
autoReconnectOptions: {
randomness: 30000
}
};
this.socket = socketCluster.connect(assign({}, defaultSocketOptions, options));
this.socket.on('error', function (err) {
console.error('Mimic Remote unable to connect. Please check mimic-remote is running.');
});
this.socket.on('connect', () => {
this.socket.emit('mimic-message', { type: EVENTS.GET_MOCKED_REQUESTS });
});
const channel = this.socket.subscribe('mimic-message');
channel.watch((message) => {
if (message.type === EVENTS.MIMIC_SET_DATA) {
Mocks.setMocks(message.payload.mocks);
Groups.setGroups(message.payload.groups);
this.initialized = true;
var socketCluster = require('socketcluster-client');
var api_credentials =
{
"apiKey" : "",
"apiSecret" : ""
}
var options = {
hostname : "sc-02.coinigy.com",
port : "443",
secure : "true"
};
console.log(options);
var SCsocket = socketCluster.connect(options);
SCsocket.on('connect', function (status) {
console.log(status);
SCsocket.on('error', function (err) {
console.log(err);
});
SCsocket.emit("auth", api_credentials, function (err, token) {
if (!err && token) {
var scChannel = SCsocket.subscribe("TRADE-OK--BTC--CNY");
addSocket: (peer, logger) => {
peer.socket = scClient.connect(peer.connectionOptions);
if (peer.socket && Object.keys(socketConnections).length < 1000) {
const hostname = peer.socket.options.hostname;
if (!socketConnections[hostname]) {
socketConnections[hostname] = { closed: 0, open: 0, disconnect: 0 };
}
if (peer.socket.state === 'closed') {
socketConnections[hostname].closed += 1;
} else if (peer.socket.state === 'open') {
socketConnections[hostname].open += 1;
} else if (peer.socket.state === 'disconnect') {
socketConnections[hostname].disconnect += 1;
}
logger.trace(