add scout
This commit is contained in:
parent
57179e600e
commit
53908bc666
144
services/scout/.gitignore
vendored
Normal file
144
services/scout/.gitignore
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/node
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=node
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
.temp
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
### Node Patch ###
|
||||
# Serverless Webpack directories
|
||||
.webpack/
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
# SvelteKit build / generate output
|
||||
.svelte-kit
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/node
|
8
services/scout/README.md
Normal file
8
services/scout/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
## Scout
|
||||
|
||||
### Project requirements
|
||||
|
||||
* [x] listen to Chaturbate chat
|
||||
* [x] touch a file when stream is live
|
||||
* [x] JS (not TS)
|
||||
* [x] commonjs
|
19
services/scout/package.json
Normal file
19
services/scout/package.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "scout",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@dotenvx/dotenvx": "^1.44.1",
|
||||
"puppeteer": "^24.11.0",
|
||||
"puppeteer-extra": "^3.3.6",
|
||||
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
||||
"zod": "^3.25.49"
|
||||
}
|
||||
}
|
1417
services/scout/pnpm-lock.yaml
generated
Normal file
1417
services/scout/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
89
services/scout/src/browser.js
Normal file
89
services/scout/src/browser.js
Normal file
@ -0,0 +1,89 @@
|
||||
const { env } = require('./config.js');
|
||||
const puppeteer = require('puppeteer-extra');
|
||||
|
||||
// add stealth plugin and use defaults (all evasion techniques)
|
||||
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
||||
puppeteer.use(StealthPlugin());
|
||||
|
||||
|
||||
function createWebSocketIterator() {
|
||||
const queue = [];
|
||||
let resolve;
|
||||
let done = false;
|
||||
|
||||
const push = (value) => {
|
||||
if (resolve) {
|
||||
resolve({ value, done: false });
|
||||
resolve = null;
|
||||
} else {
|
||||
queue.push(value);
|
||||
}
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
done = true;
|
||||
if (resolve) {
|
||||
resolve({ value: undefined, done: true });
|
||||
resolve = null;
|
||||
}
|
||||
};
|
||||
|
||||
const iterator = {
|
||||
async next() {
|
||||
if (queue.length > 0) {
|
||||
return { value: queue.shift(), done: false };
|
||||
}
|
||||
if (done) {
|
||||
return { value: undefined, done: true };
|
||||
}
|
||||
return new Promise((res) => {
|
||||
resolve = res;
|
||||
});
|
||||
},
|
||||
[Symbol.asyncIterator]() {
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
|
||||
const client = await page.target().createCDPSession();
|
||||
await client.send('Network.enable');
|
||||
|
||||
client.on('Network.webSocketCreated', ({ requestId, url }) => {
|
||||
console.debug('webSocketCreated:', url);
|
||||
});
|
||||
|
||||
client.on('Network.webSocketClosed', ({ requestId, timestamp }) => {
|
||||
console.debug('webSocketClosed:', requestId);
|
||||
});
|
||||
|
||||
client.on('Network.webSocketFrameReceived', ({ requestId, timestamp, response }) => {
|
||||
// console.debug('FrameReceived:', response.payloadData);
|
||||
push(response.payloadData);
|
||||
});
|
||||
|
||||
client.on('Network.webSocketFrameSent', ({ requestId, timestamp, response }) => {
|
||||
console.debug('FrameSent:', response.payloadData);
|
||||
});
|
||||
|
||||
await page.goto(env.CB_ROOM);
|
||||
await page.setViewport({ width: 1080, height: 1024 });
|
||||
|
||||
// Optional: close iterator when page closes
|
||||
page.on('close', () => {
|
||||
close();
|
||||
});
|
||||
|
||||
})().catch((err) => {
|
||||
console.error('Fatal error:', err);
|
||||
close();
|
||||
});
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
||||
|
||||
module.exports = createWebSocketIterator
|
19
services/scout/src/config.js
Normal file
19
services/scout/src/config.js
Normal file
@ -0,0 +1,19 @@
|
||||
// ./config/env.ts
|
||||
require('@dotenvx/dotenvx').config()
|
||||
const { z } = require('zod');
|
||||
|
||||
const EnvSchema = z.object({
|
||||
VODDO_RETRY_FILE: z.string(),
|
||||
CB_ROOM: z.string(),
|
||||
});
|
||||
|
||||
const parsed = EnvSchema.safeParse(process.env);
|
||||
|
||||
if (!parsed.success) {
|
||||
console.error('❌ Invalid environment variables:', parsed.error.flatten().fieldErrors);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
env: parsed.data
|
||||
}
|
31
services/scout/src/index.js
Normal file
31
services/scout/src/index.js
Normal file
@ -0,0 +1,31 @@
|
||||
const { env } = require('./config.js');
|
||||
const browser = require('./browser.js');
|
||||
const fs = require('fs/promises');
|
||||
|
||||
|
||||
function parseEvent(evt) {
|
||||
if (evt?.action) {
|
||||
if (evt.action === 0) return false; // heartbeat
|
||||
if (evt.action === 15) return true; // chat message
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
(async function main() {
|
||||
const gen = browser(); // this is an async generator
|
||||
|
||||
for await (const event of gen) {
|
||||
console.log('Received event from browser:', event);
|
||||
|
||||
const signal = parseEvent(event)
|
||||
|
||||
if (signal) {
|
||||
try {
|
||||
await fs.writeFile(env.VODDO_RETRY_FILE, `reset ${Date.now()}\n`);
|
||||
console.log(`Touched retry file at ${env.VODDO_RETRY_FILE}`);
|
||||
} catch (err) {
|
||||
console.error(`Failed to write retry file: ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user