mirror of
https://github.com/ragestudio/comty.git
synced 2025-07-09 01:04:16 +00:00
34 lines
747 B
JavaScript
Executable File
34 lines
747 B
JavaScript
Executable File
import React from "react"
|
|
|
|
export default (
|
|
wsEvents,
|
|
{
|
|
socketName
|
|
} = {}
|
|
) => {
|
|
function registerEvents() {
|
|
for (const [eventName, eventHandler] of Object.entries(wsEvents)) {
|
|
app.cores.api.listenEvent(eventName, eventHandler, socketName)
|
|
}
|
|
}
|
|
|
|
function unregisterEvents() {
|
|
for (const [eventName, eventHandler] of Object.entries(wsEvents)) {
|
|
app.cores.api.unlistenEvent(eventName, eventHandler, socketName)
|
|
}
|
|
}
|
|
|
|
React.useEffect(() => {
|
|
if (typeof wsEvents === "function") {
|
|
wsEvents = [wsEvents]
|
|
}
|
|
|
|
registerEvents()
|
|
|
|
return () => {
|
|
unregisterEvents()
|
|
}
|
|
}, [])
|
|
|
|
return wsEvents
|
|
} |