mirror of
https://github.com/streamwall/streamwall.git
synced 2026-04-07 14:22:05 -04:00
Use stable textual ids for streams
This commit is contained in:
@@ -45,3 +45,29 @@ export async function* pollSpreadsheetData(creds, sheetId, tabName) {
|
||||
await sleep(refreshInterval)
|
||||
}
|
||||
}
|
||||
|
||||
export async function* processData(dataGen) {
|
||||
// Give each stream a unique and recognizable short id.
|
||||
const idMap = new Map()
|
||||
for await (const data of dataGen) {
|
||||
for (const stream of data) {
|
||||
const { Link, Source } = stream
|
||||
if (!idMap.has(Link)) {
|
||||
let counter = 0
|
||||
let newId
|
||||
const normalizedSource = Source.toLowerCase()
|
||||
.replace(/[^\w]/g, '')
|
||||
.replace(/^the|^https?(www)?/, '')
|
||||
do {
|
||||
const sourcePart = normalizedSource.substr(0, 3).toLowerCase()
|
||||
const counterPart = counter === 0 ? '' : counter
|
||||
newId = `${sourcePart}${counterPart}`
|
||||
counter++
|
||||
} while (idMap.has(newId))
|
||||
idMap.set(Link, newId)
|
||||
}
|
||||
stream._id = idMap.get(Link)
|
||||
}
|
||||
yield data
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import yargs from 'yargs'
|
||||
import { app, BrowserWindow, BrowserView, ipcMain, shell } from 'electron'
|
||||
import { interpret } from 'xstate'
|
||||
|
||||
import { pollPublicData, pollSpreadsheetData } from './data'
|
||||
import { pollPublicData, pollSpreadsheetData, processData } from './data'
|
||||
import viewStateMachine from './viewStateMachine'
|
||||
import { boxesFromSpaceURLMap } from './geometry'
|
||||
|
||||
@@ -177,7 +177,7 @@ async function main() {
|
||||
dataGen = pollPublicData()
|
||||
}
|
||||
|
||||
for await (const data of dataGen) {
|
||||
for await (const data of processData(dataGen)) {
|
||||
mainWin.webContents.send('stream-data', data)
|
||||
overlayView.webContents.send('stream-data', data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user