我在流媒体的nimo频道上编写了一个警报程序,但是我不知道如何以及在哪里添加队列。
我对Thomas Dondorf发布的代码有疑问,我用它来为我的nimo频道发出警报,但是该程序不会等待警报结束,因此我想知道是否有办法输入错字在队列中,我不太了解我的代码流程,而是添加了socket.io,因此,首先,当那里的代码只是看着每条评论时,然后当评论说有人订阅了我的频道时,浏览器便会启动并带有操纵符并打开mi localhost,在此处将文本添加到文本框中,然后按一个按钮(用于不同操作(例如订阅,捐赠等)的按钮不同),然后localhost将信号发送到我的.js文件中的套接字,然后是我的.js文件中向我的localhost:port / screen.html发送另一个信号,在这里html显示gif 5秒钟,然后将其隐藏,问题在于,如果有人在5秒钟之前订阅了我的频道,则重复该过程,并且我的gif重新启动,并且当第一个调用的进程隐藏了重新启动的gif时,这是一个一团糟。
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: false });
const [page] = await browser.pages();
// call a handler when a mutation happens
async function mutationListener(addedText) {
//Here i analyze addedText with cheerio and get if someone subscribe or something then i run another puppeteer launcher for the localhost
console.log(`Added text: ${addedText}`);
// insert data into database
await client.query('INSERT INTO users(text) VALUES($1)', [addedText]);
}
page.exposeFunction('mutationListener', mutationListener);
await page.goto('http://...');
await page.waitForSelector('.msg-nickname');
await page.evaluate(() => {
// wait for any mutations inside a specific element (e.g. the chatbox)
const observerTarget = document.querySelector('ELEMENT-TO-MONITOR');
const mutationObserver = new MutationObserver((mutationsList) => {
// handle change by checking which elements were added and which were deleted
for (const mutation of mutationsList) {
const { removedNodes, addedNodes } = mutation;
// example: pass innerText of first added element to our mutationListener
mutationListener(addedNodes[0].innerHTML);
}
});
mutationObserver.observe( // start observer
observerTarget,
{ childList: true }, // wait for new child nodes to be added/removed
);
});
})();
所以我的预期结果就是我在那儿告诉我的:我只想添加一个队列。