This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add event class and separate socket.io server
- Loading branch information
Showing
9 changed files
with
130 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { expect } from 'chai' | ||
import { ConnectionEvent } from './connection.event' | ||
|
||
describe('Events', () => { | ||
describe('ConnectionEvent', () => { | ||
it("should have 'connection' event as name", () => { | ||
expect(ConnectionEvent.eventName).to.equal('connection') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Event } from './event' | ||
|
||
export class ConnectionEvent { | ||
static readonly eventName: string = Event.Connection | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class Event { | ||
static readonly Connection = 'connection' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './connection.event' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ConnectionEvent } from '../domain/events' | ||
|
||
class Socket { | ||
private io: SocketIO.Server | ||
constructor(io: SocketIO.Server) { | ||
this.io = io | ||
} | ||
|
||
public connect() { | ||
this.io | ||
.of('/occupapp-beta') | ||
.on(ConnectionEvent.eventName, (socket: SocketIOClient.Socket) => { | ||
// socket.on( | ||
// 'update-profile', | ||
// () => console.log('ok') | ||
// //updateProfile(socket.id, profile, ack) | ||
// ) | ||
// rooms (unique room) | ||
// socket.on('join', (userProfile, ack) => { | ||
// if (socket.rooms.includes(uniqueRoom)) { | ||
// ack({'status': 'error', 'reason': "Already in the room 'default room'"}) | ||
// } | ||
// socket.join(uniqueRoom, () => { | ||
// // Add or update the guest in the list of | ||
// addGuest(socket, guestData, ack)) | ||
// | ||
// let rooms = Object.keys(socket.rooms); | ||
// console.log(rooms); // [ <socket.id>, 'room 237' ] | ||
// io.to('room 237').emit('a new user has joined the room'); // broadcast to everyone in the room | ||
// }); | ||
// } | ||
// // socket.on('update-urlqueryspec', onUpdateUrlQuerySpec(socket)) | ||
// socket.on('disconnecting', () => removeGuest(socket)) | ||
}) | ||
} | ||
} | ||
|
||
export { Socket } |