Browse Source

test socketio

bugfix/timeout-logging
Evan Feenstra 5 years ago
parent
commit
14fcab8a00
  1. 29
      api/utils/socket.ts
  2. 27
      dist/api/utils/socket.js
  3. 2
      dist/api/utils/socket.js.map
  4. 1016
      package-lock.json
  5. 5
      package.json

29
api/utils/socket.ts

@ -1,20 +1,27 @@
import * as WebSocket from 'ws'
let srvr: any
let io: any
const connect = (server) => {
srvr = new WebSocket.Server({ server, clientTracking:true })
console.log('=> [socket] connected to server')
const io = require('socket.io')(server, {
path: '/socket',
serveClient: false,
// below are engine.IO options
pingInterval: 10000,
pingTimeout: 5000,
cookie: false
});
srvr.on('connection', socket => {
console.log('=> [socket] connection received')
})
io.on('connection', client => {
console.log("=> [socket.io] connected!")
client.on('event', data => { /* … */ });
client.on('disconnect', () => { /* … */ });
});
}
const send = (body) => {
srvr.clients.forEach(c=>{
if(c) c.send(body)
})
// srvr.clients.forEach(c=>{
// if(c) c.send(body)
// })
io.sockets.send(body)
}
const sendJson = (object) => {

27
dist/api/utils/socket.js

@ -1,20 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const WebSocket = require("ws");
let srvr;
let io;
const connect = (server) => {
srvr = new WebSocket.Server({ server, clientTracking: true });
console.log('=> [socket] connected to server');
srvr.on('connection', socket => {
console.log('=> [socket] connection received');
const io = require('socket.io')(server, {
path: '/socket',
serveClient: false,
// below are engine.IO options
pingInterval: 10000,
pingTimeout: 5000,
cookie: false
});
io.on('connection', client => {
console.log("=> [socket.io] connected!");
client.on('event', data => { });
client.on('disconnect', () => { });
});
};
exports.connect = connect;
const send = (body) => {
srvr.clients.forEach(c => {
if (c)
c.send(body);
});
// srvr.clients.forEach(c=>{
// if(c) c.send(body)
// })
io.sockets.send(body);
};
exports.send = send;
const sendJson = (object) => {

2
dist/api/utils/socket.js.map

@ -1 +1 @@
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../../api/utils/socket.ts"],"names":[],"mappings":";;AAAA,gCAA+B;AAE/B,IAAI,IA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xC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,GAAW,CAAC,CAAC,CAAC;QACxC,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,EAAE,GAAW,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAA;AAcC,0BAAO;AAZT,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;IACpB,4BAA4B;IAC5B,uBAAuB;IACvB,KAAK;IACL,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACvB,CAAC,CAAA;AAQC,oBAAI;AANN,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE;IAC1B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;AAC9B,CAAC,CAAA;AAKC,4BAAQ"}

1016
package-lock.json

File diff suppressed because it is too large

5
package.json

@ -44,12 +44,12 @@
"fetch-blob": "^1.0.5",
"form-data": "^3.0.0",
"fs": "^0.0.1-security",
"grpc": "^1.24.2",
"grpc": "^1.24.3",
"helmet": "^3.21.1",
"jasmine": "^3.5.0",
"js-sha256": "^0.9.0",
"jscryptor": "0.0.12",
"lodash": "^4.17.15",
"lodash": "^4.17.19",
"md5": "^2.2.1",
"mqtt": "^4.0.0",
"multer": "^1.4.2",
@ -75,6 +75,7 @@
"sequelize-typescript": "^1.1.0",
"short-uuid": "^3.1.1",
"sjcl": "^1.0.8",
"socket.io": "^2.3.0",
"tail": "^2.0.3",
"ts-node": "^8.5.4",
"tsc": "^1.20150623.0",

Loading…
Cancel
Save