代码拉取完成,页面将自动刷新
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
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。