7 examples of 'socket io cdn' in JavaScript

Every line of 'socket io cdn' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
91function handleSocketConnections(io) {
92 io.sockets.on('connection', socket => {
93 logger('info', 'sockets: adding client ->', socket.id);
94 CLIENTS.push(socket);
95 udpdateClientFromCache(socket);
96
97 socket.on('disconnect', () => {
98 logger('info', 'sockets: removing client ->', socket.id);
99 CLIENTS.splice(CLIENTS.indexOf(socket), 1);
100 });
101 });
102}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

15connect() {
16 this._socket = io();
17
18 this._socket.on('connect', () => {
19 this.setupEventListeners();
20 });
21
22 return this._socket;
23}
29function open(port) {
30
31 // set default port
32 port = port || 8080;
33
34 // don't try to re-open
35 if (server.socket) {
36 return server.socket;
37 }
38
39 // update state
40 var socket = io(port);
41 server.socket = socket;
42
43 subscribe(socket);
44 return socket;
45}
9function initSocket(io) {
10 state_1.State[safe.get('State._io')] = io;
11 io.on('connection', (socket) => {
12 const logger = new logger_1.Logger('ioServer');
13 state_1.State.pushSocket(socket);
14 logger.info(`socket connected: { socketId: ${socket.id}, pid: ${process.pid} }`);
15 logger.info('Implementing socket web services');
16 if (state_1.State.models && state_1.State.models.length) {
17 let models = state_1.State.models;
18 for (let i = 0; i < models.length; i++) {
19 let model = models[i];
20 if (model.$get('apiType') === types_1.API_TYPES.REST)
21 continue;
22 let services = model.$getServices();
23 for (let service in services) {
24 if (services[service].apiType === types_1.API_TYPES.REST)
25 continue;
26 socket.on(services[service].event, context_1.Context.Socket(socket, model, services[service]));
27 }
28 }
29 }
30 socket.on('disconnect', () => {
31 context_1.Context.deleteContextsOf('socket', socket.id);
32 state_1.State.deleteSocket(socket.id);
33 io.emit('user disconnected');
34 socket.disconnect();
35 });
36 });
37 process.on('message', msg => {
38 if (msg.data && msg.action === 'response') {
39 let response = msg.data;
40 if ((response.domain === types_1.RESPONSE_DOMAINS.ROOM || response.domain === types_1.RESPONSE_DOMAINS.ALL_ROOM) && response.room) {
41 io.to(response.room).emit(response.event, response);
42 }
43 else if (response.domain === types_1.RESPONSE_DOMAINS.OTHERS || response.domain === types_1.RESPONSE_DOMAINS.ALL) {
44 io.sockets.emit(response.event, response);
45 }
46 }
47 });
48}
9function init(server){
10 // socket.io
11 _socket = socket(server);
12 _socket.on('connection', function (socket) {
13 winston.log('info', 'a user connected');
14 });
15
16
17
18 return _socket;
19}
25function io() {
26 var mockSocketObject = createMockSocketObject();
27 return mockSocketObject.connect();
28}
8use(io) {
9 io.on('connection', socket => {
10 socket.on('sign in', address => this._signIn(socket, address))
11 })
12}

Related snippets