2 Star 0 Fork 0

mirrors_jitsi/jvb-rtcstats-push

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
JvbLogTail.js 2.14 KB
一键复制 编辑 原始数据 按行查看 历史
const { Tail } = require('tail')
const CLEAN_INTERVAL = 60 * 1000 // Retain up to 1 minute of logs
module.exports = class JvbLogTail {
constructor (path) {
this.lastMeetingId = null
this.meetingStates = {}
this.tail = new Tail(path)
this.tail.on('line', line => {
const meetingId = this.getMeetingId(line)
if (meetingId === null) return
const state = this.getState(meetingId)
state.logs.push(line)
state.lastAccess = new Date()
this.clean()
})
this.tail.on('error', e => {
console.log('Error reading from the log file:' + e)
this.tail.unwatch()
})
}
getState (meetingId) {
let state = this.meetingStates[meetingId]
if (!state) {
state = { meetingId, logs: [], last: new Date() }
this.meetingStates[meetingId] = state
}
return state
}
clean () {
for (const meetingId in this.meetingStates) {
const t = new Date() - this.meetingStates[meetingId].lastAccess
if (t > CLEAN_INTERVAL) {
console.log('Remove stale logs ' + meetingId)
delete this.meetingStates[meetingId]
}
};
}
// The JVB log file includes only the first part of the full meeting ID UUID (we are okay with the
// low probability of collisions), so search for any meeting ID that matches it with startsWith.
getLogs (fullMeetingId) {
for (const meetingId in this.meetingStates) {
if (fullMeetingId.startsWith(meetingId)) {
const logs = this.meetingStates[meetingId].logs
this.meetingStates[meetingId].logs = []
return logs
}
}
return []
}
/* Read the meeting_id from a log line, and update this.lastMeetingId if the line starts a new log. */
getMeetingId (line) {
if (!line.startsWith('JVB ')) {
// Subsequent line from a multi-line message.
return this.lastMeetingId
}
const c = line.replaceAll('[', '').replaceAll(']', '').split(' ').filter(m => m.startsWith('meeting_id='))
if (!c || !c.length) {
this.lastMeetingId = null
return null
}
const meetingId = c[0].replace('meeting_id=', '')
this.lastMeetingId = meetingId
return meetingId
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_jitsi/jvb-rtcstats-push.git
[email protected]:mirrors_jitsi/jvb-rtcstats-push.git
mirrors_jitsi
jvb-rtcstats-push
jvb-rtcstats-push
master

搜索帮助