aboutsummaryrefslogtreecommitdiff
path: root/src/server/websocket.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/websocket.ts')
-rw-r--r--src/server/websocket.ts38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/server/websocket.ts b/src/server/websocket.ts
index be5cdb202..a26b81bdf 100644
--- a/src/server/websocket.ts
+++ b/src/server/websocket.ts
@@ -1,10 +1,8 @@
import { blue } from 'colors';
import * as express from 'express';
-import { createServer, Server } from 'https';
+import { createServer } from 'https';
+import { Server, Socket } from '../../node_modules/socket.io/dist/index';
import { networkInterfaces } from 'os';
-import * as sio from 'socket.io';
-import { Socket } from 'socket.io';
-import { Opt } from '../fields/Doc';
import { Utils } from '../Utils';
import { logPort } from './ActionUtilities';
import { timeMap } from './ApiManagers/UserManager';
@@ -18,31 +16,31 @@ import { DocumentsCollection } from './IDatabase';
import { Diff, GestureContent, MessageStore, MobileDocumentUploadContent, MobileInkOverlayContent, Transferable, Types, UpdateMobileInkOverlayPositionContent, YoutubeQueryInput, YoutubeQueryTypes } from './Message';
import { Search } from './Search';
import { resolvedPorts } from './server_Initialization';
-var _ = require('lodash');
+import * as _ from 'lodash';
export namespace WebSocket {
export let _socket: Socket;
export const clients: { [key: string]: Client } = {};
- export const socketMap = new Map<SocketIO.Socket, string>();
+ export const socketMap = new Map<Socket, string>();
export const userOperations = new Map<string, number>();
export let disconnect: Function;
export async function initialize(isRelease: boolean, app: express.Express) {
- let io: sio.Server;
+ let io: Server;
if (isRelease) {
const { socketPort } = process.env;
if (socketPort) {
resolvedPorts.socket = Number(socketPort);
}
- let socketEndpoint: Opt<Server>;
- await new Promise<void>(resolve => (socketEndpoint = createServer(SSL.Credentials, app).listen(resolvedPorts.socket, resolve)));
- io = sio(socketEndpoint!, SSL.Credentials as any);
+ io = new Server(createServer(SSL.Credentials, app), SSL.Credentials as any);
+ io.listen(resolvedPorts.socket);
} else {
- io = sio().listen(resolvedPorts.socket);
+ io = new Server();
+ io.listen(resolvedPorts.socket);
}
logPort('websocket', resolvedPorts.socket);
- io.on('connection', function (socket: Socket) {
+ io.on('connection', socket => {
_socket = socket;
socket.use((_packet, next) => {
const userEmail = socketMap.get(socket);
@@ -67,8 +65,8 @@ export namespace WebSocket {
socket.on('create or join', function (room) {
console.log('Received request to create or join room ' + room);
- const clientsInRoom = socket.adapter.rooms[room];
- const numClients = clientsInRoom ? Object.keys(clientsInRoom.sockets).length : 0;
+ const clientsInRoom = socket.rooms.has(room);
+ const numClients = clientsInRoom ? Object.keys(room.sockets).length : 0;
console.log('Room ' + room + ' now has ' + numClients + ' client(s)');
if (numClients === 0) {
@@ -90,7 +88,7 @@ export namespace WebSocket {
socket.on('ipaddr', function () {
const ifaces = networkInterfaces();
for (const dev in ifaces) {
- ifaces[dev].forEach(function (details) {
+ ifaces[dev]?.forEach(function (details) {
if (details.family === 'IPv4' && details.address !== '127.0.0.1') {
socket.emit('ipaddr', details.address);
}
@@ -191,7 +189,7 @@ export namespace WebSocket {
initializeGuest();
}
- function barReceived(socket: SocketIO.Socket, userEmail: string) {
+ function barReceived(socket: Socket, userEmail: string) {
clients[userEmail] = new Client(userEmail.toString());
const currentdate = new Date();
const datetime = currentdate.getDate() + '/' + (currentdate.getMonth() + 1) + '/' + currentdate.getFullYear() + ' @ ' + currentdate.getHours() + ':' + currentdate.getMinutes() + ':' + currentdate.getSeconds();
@@ -308,9 +306,9 @@ export namespace WebSocket {
if (sendBack) {
console.log('Warning: list modified during update. Composite list is being returned.');
const id = socket.id;
- socket.id = '';
+ (socket as any).id = '';
socket.broadcast.emit(MessageStore.UpdateField.Message, diff);
- socket.id = id;
+ (socket as any).id = id;
} else socket.broadcast.emit(MessageStore.UpdateField.Message, diff);
dispatchNextOp(diff.id);
},
@@ -401,9 +399,9 @@ export namespace WebSocket {
// the two copies are different, so the server sends its copy.
console.log('SEND BACK');
const id = socket.id;
- socket.id = '';
+ (socket as any).id = '';
socket.broadcast.emit(MessageStore.UpdateField.Message, diff);
- socket.id = id;
+ (socket as any).id = id;
} else socket.broadcast.emit(MessageStore.UpdateField.Message, diff);
dispatchNextOp(diff.id);
},