Skip to content

Commit 86087f1

Browse files
author
edencoder
committed
upgrade to socket.io v4
1 parent ff73cd0 commit 86087f1

File tree

4 files changed

+2119
-543
lines changed

4 files changed

+2119
-543
lines changed

bundles/socket/daemons/socket.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import config from 'config';
44
import Daemon from 'daemon';
55
import session from 'express-session';
6-
import socketio from 'socket.io';
76
import SessionStore from '@edenjs/session-store';
87
import cookieParser from 'cookie-parser';
8+
import { Server } from 'socket.io';
99
import { v4 as uuid } from 'uuid';
1010

1111
// require models
@@ -80,7 +80,9 @@ export default class SocketDaemon extends Daemon {
8080
});
8181

8282
// Set io
83-
this.__socketIO = socketio(this.eden.router.app.server);
83+
this.__socketIO = new Server(this.eden.router.app.server, {
84+
allowEIO3 : true,
85+
});
8486

8587
// initialize store
8688
SessionStore.initialize(session);

bundles/socket/public/js/bootstrap.js renamed to bundles/socket/public/js/bootstrap.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
// Require dependencies
3-
const io = require('socket.io-client');
4-
const uuid = require('uuid').v4;
3+
import io from 'socket.io-client';
4+
import { v4 as uuid } from 'uuid';
55

66
// Require local dependencies
7-
const store = require('core/public/js/store');
7+
import store from 'core/public/js/store';
88

99
/**
1010
* Build socket class
@@ -34,8 +34,9 @@ class SocketStore {
3434
*/
3535
async build() {
3636
// Run socket
37-
this.socket = io.connect(store.get('config.socket.url') === 'host' ? `//${window.location.hostname}` : store.get('config.socket.url'),
38-
store.get('config.socket.params') || {});
37+
this.socket = io.connect(store.get('config.socket.url') === 'host' ? null : store.get('config.socket.url'), {
38+
...(store.get('config.socket.params') || {}),
39+
});
3940

4041
// socket on
4142
this.socket.on('connect', () => {
@@ -162,4 +163,7 @@ class SocketStore {
162163
*
163164
* @type {SocketStore}
164165
*/
165-
exports = module.exports = window.eden.socket = new SocketStore();
166+
window.eden.socket = new SocketStore();
167+
168+
// export default
169+
export default window.eden.socket;

0 commit comments

Comments
 (0)