mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
format
This commit is contained in:
parent
52dd4ecffd
commit
fa83c55264
@ -1,5 +1,4 @@
|
||||
import buildFunctionHandler from "@utils/buildFunctionHandler"
|
||||
import { Snowflake } from "nodejs-snowflake"
|
||||
|
||||
import { ChatMessage } from "@db_models"
|
||||
|
||||
@ -34,7 +33,10 @@ export default class Room {
|
||||
throw new OperationError(500, "Not implemented")
|
||||
},
|
||||
"room:send:message": async (client, payload) => {
|
||||
console.log(`[${this.roomID}] [@${client.userData.username}] sent message >`, payload)
|
||||
console.log(
|
||||
`[${this.roomID}] [@${client.userData.username}] sent message >`,
|
||||
payload,
|
||||
)
|
||||
|
||||
let { message } = payload
|
||||
|
||||
@ -43,7 +45,10 @@ export default class Room {
|
||||
}
|
||||
|
||||
if (message.length > this.limitations.maxMessageLength) {
|
||||
message = message.substring(0, this.limitations.maxMessageLength)
|
||||
message = message.substring(
|
||||
0,
|
||||
this.limitations.maxMessageLength,
|
||||
)
|
||||
}
|
||||
|
||||
const created_at = new Date().getTime()
|
||||
@ -84,22 +89,26 @@ export default class Room {
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
handlers = {
|
||||
join: (client) => {
|
||||
if (client.connectedRoomID) {
|
||||
console.warn(`[${client.id}][@${client.userData.username}] already connected to room ${client.connectedRoomID}`)
|
||||
console.warn(
|
||||
`[${client.id}][@${client.userData.username}] already connected to room ${client.connectedRoomID}`,
|
||||
)
|
||||
|
||||
client.leave(client.connectedRoomID)
|
||||
}
|
||||
|
||||
console.log(`[${client.id}][@${client.userData.username}] joined room ${this.roomID}`)
|
||||
console.log(
|
||||
`[${client.id}][@${client.userData.username}] joined room ${this.roomID}`,
|
||||
)
|
||||
|
||||
client.connectedRoomID = this.roomID
|
||||
|
||||
@ -131,17 +140,21 @@ export default class Room {
|
||||
username: client.userData.username,
|
||||
fullName: client.userData.fullName,
|
||||
avatar: client.userData.avatar,
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
leave: (client) => {
|
||||
if (!client.connectedRoomID) {
|
||||
console.warn(`[${client.id}][@${client.userData.username}] not connected to any room`)
|
||||
console.warn(
|
||||
`[${client.id}][@${client.userData.username}] not connected to any room`,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
if (client.connectedRoomID !== this.roomID) {
|
||||
console.warn(`[${client.id}][@${client.userData.username}] not connected to room ${this.roomID}, cannot leave`)
|
||||
console.warn(
|
||||
`[${client.id}][@${client.userData.username}] not connected to room ${this.roomID}, cannot leave`,
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
@ -157,20 +170,22 @@ export default class Room {
|
||||
username: client.userData.username,
|
||||
fullName: client.userData.fullName,
|
||||
avatar: client.userData.avatar,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
for (const [event, handler] of client.handlers) {
|
||||
client.off(event, handler)
|
||||
}
|
||||
|
||||
console.log(`[${client.id}][@${client.userData.username}] left room ${this.roomID}`)
|
||||
console.log(
|
||||
`[${client.id}][@${client.userData.username}] left room ${this.roomID}`,
|
||||
)
|
||||
},
|
||||
broadcastToMembers: (event, payload) => {
|
||||
for (const client of this.connections) {
|
||||
client.emit(event, payload)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
getConnectedUsers = () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user