mirror of
https://github.com/streamwall/streamwall.git
synced 2026-01-26 23:12:48 -05:00
Add support for custom streams list
Also, fix bug where unique stream ids were not being generated.
This commit is contained in:
@@ -46,28 +46,34 @@ export async function* pollSpreadsheetData(creds, sheetId, tabName) {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
export class StreamIDGenerator {
|
||||
constructor(parent) {
|
||||
this.idMap = new Map(parent ? parent.idMap : null)
|
||||
this.idSet = new Set(this.idMap.values())
|
||||
}
|
||||
|
||||
process(streams) {
|
||||
const { idMap, idSet } = this
|
||||
for (const stream of streams) {
|
||||
const { Link, Source, Label } = stream
|
||||
if (!idMap.has(Link)) {
|
||||
let counter = 0
|
||||
let newId
|
||||
const normalizedSource = Source.toLowerCase()
|
||||
const normalizedText = (Source || Label || Link)
|
||||
.toLowerCase()
|
||||
.replace(/[^\w]/g, '')
|
||||
.replace(/^the|^https?(www)?/, '')
|
||||
do {
|
||||
const sourcePart = normalizedSource.substr(0, 3).toLowerCase()
|
||||
const counterPart = counter === 0 ? '' : counter
|
||||
newId = `${sourcePart}${counterPart}`
|
||||
const textPart = normalizedText.substr(0, 3).toLowerCase()
|
||||
const counterPart = counter === 0 && textPart ? '' : counter
|
||||
newId = `${textPart}${counterPart}`
|
||||
counter++
|
||||
} while (idMap.has(newId))
|
||||
} while (idSet.has(newId))
|
||||
idMap.set(Link, newId)
|
||||
idSet.add(newId)
|
||||
}
|
||||
stream._id = idMap.get(Link)
|
||||
}
|
||||
yield data
|
||||
return streams
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import fs from 'fs'
|
||||
import yargs from 'yargs'
|
||||
import { app, shell, BrowserWindow } from 'electron'
|
||||
|
||||
import { pollPublicData, pollSpreadsheetData, processData } from './data'
|
||||
import { pollPublicData, pollSpreadsheetData, StreamIDGenerator } from './data'
|
||||
import StreamWindow from './StreamWindow'
|
||||
import initWebServer from './server'
|
||||
|
||||
@@ -49,12 +49,14 @@ async function main() {
|
||||
})
|
||||
.help().argv
|
||||
|
||||
const idGen = new StreamIDGenerator()
|
||||
|
||||
const streamWindow = new StreamWindow()
|
||||
streamWindow.init()
|
||||
|
||||
let browseWindow = null
|
||||
|
||||
const clientState = {}
|
||||
const clientState = { streams: [], customStreams: [], views: [] }
|
||||
const getInitialState = () => clientState
|
||||
let broadcastState = () => {}
|
||||
const onMessage = (msg) => {
|
||||
@@ -62,6 +64,11 @@ async function main() {
|
||||
streamWindow.setViews(new Map(msg.views))
|
||||
} else if (msg.type === 'set-listening-view') {
|
||||
streamWindow.setListeningView(msg.viewIdx)
|
||||
} else if (msg.type === 'set-custom-streams') {
|
||||
const customIDGen = new StreamIDGenerator(idGen)
|
||||
clientState.customStreams = customIDGen.process(msg.streams)
|
||||
streamWindow.send('state', clientState)
|
||||
broadcastState(clientState)
|
||||
} else if (msg.type === 'reload-view') {
|
||||
streamWindow.reloadView(msg.viewIdx)
|
||||
} else if (msg.type === 'browse') {
|
||||
@@ -90,8 +97,8 @@ async function main() {
|
||||
}
|
||||
|
||||
streamWindow.on('state', (viewStates) => {
|
||||
streamWindow.send('view-states', viewStates)
|
||||
clientState.views = viewStates
|
||||
streamWindow.send('state', clientState)
|
||||
broadcastState(clientState)
|
||||
})
|
||||
|
||||
@@ -102,9 +109,10 @@ async function main() {
|
||||
dataGen = pollPublicData()
|
||||
}
|
||||
|
||||
for await (const streams of processData(dataGen)) {
|
||||
streamWindow.send('stream-data', streams)
|
||||
for await (const rawStreams of dataGen) {
|
||||
const streams = idGen.process(rawStreams)
|
||||
clientState.streams = streams
|
||||
streamWindow.send('state', clientState)
|
||||
broadcastState(clientState)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user