Skip to content

Commit

Permalink
Merge pull request #32 from efrei-craft/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JiveOff authored Jul 28, 2024
2 parents 4237f1b + 891a1ad commit fc6d9a1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/realms/rest/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,22 @@ export const emitterMessage = Type.Union(

export type EmitterMessage = Static<typeof emitterMessage>

// eslint-disable-next-line no-control-regex
const ANSI_ESCAPE = /\x1b\[[0-9;]*m/g;

function removeAnsiColorCodes(str: string):string {
return str.replace(ANSI_ESCAPE, "");
}

export const prepareRedisListeners = () => {
const redisSubscriptionClient = new RedisClient()
redisSubscriptionClient.client.subscribe("emitter")
redisSubscriptionClient.client.on("message", (channel, message) => {
if (channel === "emitter") {
const body = JSON.parse(message.toString()) as EmitterMessage
if (body.type === "serverLog") {
body.payload.message = removeAnsiColorCodes(body.payload.message)
}
emitter.emit(body.type, body.payload)
}
})
Expand Down

0 comments on commit fc6d9a1

Please sign in to comment.