-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsocketConfig.js
34 lines (28 loc) · 930 Bytes
/
socketConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { io } = require('socket.io-client');
/*
This file mimics the client side socket for testing. In production, chrome-extension is the client
and egress-router/service is the server. In the tests, there is no client, so we have the below to simulate
a client connecting and test that our socket is working.
*/
const socket = io('http://turbosrc-egress-router:4007/', {
path: '/vote-client/socket.io',
transportOptions: {
polling: {
extraHeaders: {
'my-custom-header': 'abcd'
}
}
},
transports: ['websocket'], // <---- Add this line
secure: false // ensure secure connection
});
socket.on('connect', () => {
console.log('Socket connection established');
});
socket.on('connect_error', (error) => {
console.error('Socket connection error:', error);
});
socket.on('disconnect', (reason) => {
console.log('Socket disconnected:', reason);
});
module.exports = { socket };