How to use the webtorrent-fixtures.alice function in webtorrent-fixtures

To help you get started, we’ve selected a few webtorrent-fixtures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webtorrent / webtorrent / test / client-add-duplicate-trackers.js View on Github external
test('client.add: duplicate trackers (including in .torrent file), multiple torrents', function (t) {
  t.plan(5)

  // Re-use this object, in case webtorrent is changing it
  var opts = {
    announce: ['wss://example.com', 'wss://example.com', 'wss://example.com']
  }

  // Include the duplicate trackers in the .torrent files
  var parsedTorrentLeaves = Object.assign({}, fixtures.leaves.parsedTorrent)
  parsedTorrentLeaves.announce = ['wss://example.com', 'wss://example.com', 'wss://example.com']

  var parsedTorrentAlice = Object.assign({}, fixtures.alice.parsedTorrent)
  parsedTorrentAlice.announce = ['wss://example.com', 'wss://example.com', 'wss://example.com']

  var client = new WebTorrent({ dht: false, tracker: false })

  client.on('error', function (err) { t.fail(err) })
  client.on('warning', function (err) { t.fail(err) })

  var torrent1 = client.add(parsedTorrentLeaves, opts)

  torrent1.on('ready', function () {
    t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))

    var torrent2 = client.add(parsedTorrentAlice, opts)

    torrent2.on('ready', function () {
      t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))
github webtorrent / bittorrent-tracker / test / client-ws-socket-pool.js View on Github external
client1.once('update', function () {
      t.pass('got client1 update')
      // second ws client using same announce url will re-use the same websocket
      var client2 = new Client({
        infoHash: fixtures.alice.parsedTorrent.infoHash, // different info hash
        announce: announceUrl,
        peerId: peerId,
        port: port,
        wrtc: {}
      })

      common.mockWebsocketTracker(client2)
      client2.on('error', function (err) { t.error(err) })
      client2.on('warning', function (err) { t.error(err) })

      client2.start()

      client2.once('update', function () {
        t.pass('got client2 update')
        client1.destroy(function (err) {
          t.error(err, 'got client1 destroy callback')
github webtorrent / bittorrent-tracker / test / filter.js View on Github external
common.createServer(t, opts, function (server, announceUrl) {
    var client1 = new Client({
      infoHash: fixtures.alice.parsedTorrent.infoHash,
      announce: announceUrl,
      peerId: peerId,
      port: 6881,
      wrtc: {}
    })

    client1.on('error', function (err) { t.error(err) })
    if (serverType === 'ws') common.mockWebsocketTracker(client1)

    client1.once('warning', function (err) {
      t.ok(err.message.includes('disallowed info_hash (Alice)'), 'got client warning')

      client1.destroy(function () {
        t.pass('client1 destroyed')

        var client2 = new Client({
github webtorrent / bittorrent-tracker / test / scrape.js View on Github external
function clientScrapeMulti (t, serverType) {
  var infoHash1 = fixtures.leaves.parsedTorrent.infoHash
  var infoHash2 = fixtures.alice.parsedTorrent.infoHash

  commonTest.createServer(t, serverType, function (server, announceUrl) {
    Client.scrape({
      infoHash: [infoHash1, infoHash2],
      announce: announceUrl
    }, function (err, results) {
      t.error(err)

      t.equal(results[infoHash1].announce, announceUrl)
      t.equal(results[infoHash1].infoHash, infoHash1)
      t.equal(typeof results[infoHash1].complete, 'number')
      t.equal(typeof results[infoHash1].incomplete, 'number')
      t.equal(typeof results[infoHash1].downloaded, 'number')

      t.equal(results[infoHash2].announce, announceUrl)
      t.equal(results[infoHash2].infoHash, infoHash2)
github webtorrent / webtorrent / test / node / seed-while-download.js View on Github external
function (cb) {
      client1.add(fixtures.alice.magnetURI, { store: MemoryChunkStore })

      client1.on('torrent', function (torrent) {
        torrent.files[0].getBuffer(function (err, buf) {
          t.error(err)
          t.deepEqual(buf, fixtures.alice.content, 'client1 downloaded correct content')
          gotBuffer1 = true
          maybeDone()
        })

        torrent.once('done', function () {
          t.pass('client1 downloaded torrent from client2')
          gotDone1 = true
          maybeDone()
        })
      })
github webtorrent / bittorrent-tracker / test / request-handler.js View on Github external
common.createServer(t, opts, function (server, announceUrl) {
    var client1 = new Client({
      infoHash: fixtures.alice.parsedTorrent.infoHash,
      announce: announceUrl,
      peerId: peerId,
      port: 6881,
      wrtc: {}
    })

    client1.on('error', function (err) { t.error(err) })
    if (serverType === 'ws') common.mockWebsocketTracker(client1)

    server.once('start', function () {
      t.pass('got start message from client1')
    })

    client1.once('update', function (data) {
      t.equal(data.complete, 246)
      t.equal(data.extraData.toString(), 'hi')
github webtorrent / webtorrent / test / node / seed-while-download.js View on Github external
torrent.files[0].getBuffer(function (err, buf) {
          t.error(err)
          t.deepEqual(buf, fixtures.alice.content, 'client1 downloaded correct content')
          gotBuffer1 = true
          maybeDone()
        })
github webtorrent / webtorrent / test / client-add-duplicate-trackers.js View on Github external
torrent1.on('ready', function () {
    t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))

    var torrent2 = client.add(fixtures.alice.torrent, opts)

    torrent2.on('ready', function () {
      t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))

      torrent1.destroy(function (err) { t.error(err, 'torrent1 destroyed') })
      torrent2.destroy(function (err) { t.error(err, 'torrent2 destroyed') })
      client.destroy(function (err) { t.error(err, 'client destroyed') })
    })
  })
})
github webtorrent / bittorrent-tracker / test / filter.js View on Github external
process.nextTick(function () {
      if (infoHash === fixtures.alice.parsedTorrent.infoHash) {
        cb(new Error('disallowed info_hash (Alice)'))
      } else {
        cb(null)
      }
    })
  }