-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(server): refactor wss handler
- Loading branch information
Showing
10 changed files
with
109 additions
and
93 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { Socket } from "socket.io"; | ||
import { IUser } from "@litespace/types"; | ||
|
||
import { CallHandler } from "./call"; | ||
import { ConnectionHandler } from "./connection"; | ||
import { MessageHandler } from "./message"; | ||
import { PeerHandler } from "./peer"; | ||
import { InputDevicesHandler } from "./inputDevices"; | ||
import { Call } from "@/wss/handlers/call"; | ||
import { Connection } from "@/wss/handlers/connection"; | ||
import { Messages } from "@/wss/handlers/message"; | ||
import { Peer } from "@/wss/handlers/peer"; | ||
import { InputDevices } from "./inputDevices"; | ||
|
||
export class WSSHandlers { | ||
public readonly connection: ConnectionHandler; | ||
public readonly call: CallHandler; | ||
public readonly message: MessageHandler; | ||
public readonly peer: PeerHandler; | ||
public readonly inputDevices: InputDevicesHandler; | ||
export class WssHandlers { | ||
public readonly connection: Connection; | ||
public readonly call: Call; | ||
public readonly messages: Messages; | ||
public readonly peer: Peer; | ||
public readonly inputDevices: InputDevices; | ||
|
||
constructor(socket: Socket, user: IUser.Self | IUser.Ghost) { | ||
this.connection = new ConnectionHandler(socket, user); | ||
this.call = new CallHandler(socket, user); | ||
this.message = new MessageHandler(socket, user); | ||
this.peer = new PeerHandler(socket, user); | ||
this.inputDevices = new InputDevicesHandler(socket, user); | ||
this.connection = new Connection(socket, user).init(); | ||
this.call = new Call(socket, user).init(); | ||
this.messages = new Messages(socket, user).init(); | ||
this.peer = new Peer(socket, user); | ||
this.inputDevices = new InputDevices(socket, user).init(); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,32 +1,14 @@ | ||
import { Socket } from "socket.io"; | ||
import { WSSHandlers } from "./handlers"; | ||
import { WssHandlers } from "@/wss/handlers"; | ||
import { logger } from "@litespace/sol"; | ||
import { Wss } from "@litespace/types"; | ||
|
||
const stdout = logger("wss"); | ||
|
||
export function wssConnectionHandler(socket: Socket) { | ||
export function wssHandler(socket: Socket) { | ||
const user = socket.request.user; | ||
if (!user) { | ||
stdout.warning("(function) wssHandler: No user has been found in the request obj!"); | ||
return; | ||
} | ||
const handlers = new WSSHandlers(socket, user); | ||
|
||
handlers.connection.connect(); | ||
socket.on(Wss.ClientEvent.Disconnect, handlers.connection.disconnect.bind(handlers.connection)); | ||
|
||
socket.on(Wss.ClientEvent.JoinCall, handlers.call.onJoinCall.bind(handlers.call)); | ||
socket.on(Wss.ClientEvent.LeaveCall, handlers.call.onLeaveCall.bind(handlers.call)); | ||
|
||
socket.on(Wss.ClientEvent.SendMessage, handlers.message.sendMessage.bind(handlers.message)); | ||
socket.on(Wss.ClientEvent.UpdateMessage, handlers.message.updateMessage.bind(handlers.message)); | ||
socket.on(Wss.ClientEvent.DeleteMessage, handlers.message.deleteMessage.bind(handlers.message)); | ||
|
||
socket.on(Wss.ClientEvent.PeerOpened, handlers.peer.peerOpened.bind(handlers.peer)); | ||
socket.on(Wss.ClientEvent.RegisterPeer, handlers.peer.registerPeer.bind(handlers.peer)); | ||
|
||
socket.on(Wss.ClientEvent.ToggleCamera, handlers.inputDevices.toggleCamera.bind(handlers.inputDevices)); | ||
socket.on(Wss.ClientEvent.ToggleMic, handlers.inputDevices.toggleMic.bind(handlers.inputDevices)); | ||
socket.on(Wss.ClientEvent.UserTyping, handlers.inputDevices.userTyping.bind(handlers.inputDevices)); | ||
if (!user) | ||
return stdout.warning( | ||
"wssHandler: No user has been found in the request obj!" | ||
); | ||
return new WssHandlers(socket, user); | ||
} |