simulate-many-viewers-worker.ts 550 B

1234567891011121314151617
  1. import Bluebird from 'bluebird'
  2. import { PeerTubeServer } from '@peertube/peertube-server-commands'
  3. module.exports = async function sendViews (options: {
  4. url: string
  5. videoId: number
  6. viewers: { xForwardedFor: string }[]
  7. }) {
  8. const { url, videoId, viewers } = options
  9. const server = new PeerTubeServer({ url })
  10. await Bluebird.map(viewers, viewer => {
  11. return server.views.simulateView({ id: videoId, xForwardedFor: viewer.xForwardedFor })
  12. .catch(err => console.error('Cannot simulate viewer', err))
  13. }, { concurrency: 500 })
  14. }