Browse Source

s

bugfix/timeout-logging
Evan Feenstra 5 years ago
parent
commit
f6581fac7f
  1. 16
      api/utils/socket.ts
  2. 17
      dist/api/utils/socket.js
  3. 2
      dist/api/utils/socket.js.map

16
api/utils/socket.ts

@ -1,11 +1,11 @@
import * as WebSocket from 'ws' // import * as WebSocket from 'ws'
const socketio = require("socket.io"); const socketio = require("socket.io");
let io: any let io: any
let srvr: any // let srvr: any
export function connect(server) { export function connect(server) {
srvr = new WebSocket.Server({ server, clientTracking:true }) // srvr = new WebSocket.Server({ server, clientTracking:true })
io = socketio(server); io = socketio(server);
io.on('connection', client => { io.on('connection', client => {
@ -16,11 +16,11 @@ export function connect(server) {
export const send = (body) => { export const send = (body) => {
if(io) io.sockets.emit('message',body) if(io) io.sockets.emit('message',body)
if(srvr){ // if(srvr){
srvr.clients.forEach(c=>{ // srvr.clients.forEach(c=>{
if(c) c.send(body) // if(c) c.send(body)
}) // })
} // }
} }
export const sendJson = (object) => { export const sendJson = (object) => {

17
dist/api/utils/socket.js

@ -1,11 +1,11 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const WebSocket = require("ws"); // import * as WebSocket from 'ws'
const socketio = require("socket.io"); const socketio = require("socket.io");
let io; let io;
let srvr; // let srvr: any
function connect(server) { function connect(server) {
srvr = new WebSocket.Server({ server, clientTracking: true }); // srvr = new WebSocket.Server({ server, clientTracking:true })
io = socketio(server); io = socketio(server);
io.on('connection', client => { io.on('connection', client => {
console.log("=> [socket.io] connected!"); console.log("=> [socket.io] connected!");
@ -15,12 +15,11 @@ exports.connect = connect;
exports.send = (body) => { exports.send = (body) => {
if (io) if (io)
io.sockets.emit('message', body); io.sockets.emit('message', body);
if (srvr) { // if(srvr){
srvr.clients.forEach(c => { // srvr.clients.forEach(c=>{
if (c) // if(c) c.send(body)
c.send(body); // })
}); // }
}
}; };
exports.sendJson = (object) => { exports.sendJson = (object) => {
exports.send(JSON.stringify(object)); exports.send(JSON.stringify(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;AAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAEtC,IAAI,EAAO,CAAA;AACX,IAAI,IAAS,CAAA;AAEb,SAAgB,OAAO,CAAC,MAAM;IAC5B,IAAI,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,cAAc,EAAC,IAAI,EAAE,CAAC,CAAA;IAE5D,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IACtB,EAAE,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,EAAE;QAC3B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,0BAOC;AAEY,QAAA,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;IAC3B,IAAG,EAAE;QAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAC,IAAI,CAAC,CAAA;IAEtC,IAAG,IAAI,EAAC;QACN,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA,EAAE;YACtB,IAAG,CAAC;gBAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACpB,CAAC,CAAC,CAAA;KACH;AACH,CAAC,CAAA;AAEY,QAAA,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE;IACjC,YAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;AAC9B,CAAC,CAAA"} {"version":3,"file":"socket.js","sourceRoot":"","sources":["../../../api/utils/socket.ts"],"names":[],"mappings":";;AAAA,kCAAkC;AAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAEtC,IAAI,EAAO,CAAA;AACX,gBAAgB;AAE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