koajs / koa-range

[MAINTAINERS WANTED] range request implementation for koa, see http://tools.ietf.org/html/rfc7233
50 stars 12 forks source link

Doesn't work with chrome on video files #14

Open talha-asad opened 6 years ago

talha-asad commented 6 years ago

With small video (mp4) files, chrome has no issues. However if I use a 34 mbish sort of a video file. It will sometimes play the first 2 secs, like (5%) of the file or just stay stuck in limbo and not respond to the request. The code I have is pretty simple:

import fs from 'fs';
import Koa from 'koa';
import koaLogger from 'koa-logger';
import koaRange from 'koa-range';

const app = new Koa();
const router = new koaRouter();

app
  .use(koaLogger())
  .use(koaRange)

   /*
   * TEST VIDEO STREAM
   */
  router.get('/test', async (ctx, next) => {
    ctx.type = 'video/mp4';
    ctx.body = fs.createReadStream(__dirname + '/test.mp4');
  });

app
  .use(router.routes())
  .use(router.allowedMethods())
  .listen('3000');

It works fine on firefox, but I think firefox doesn't even use ranges for video. It also works fine when koaRange is removed as a middleware but then it would not seek, as expected. Using the latest version of koa and koa-range

talha-asad commented 6 years ago

It seems to work fine, if ctx.length is set

If the stream is sliced but the total length is determined then this could work with streams where total length is not known before hand

It falls in the section marked as // FIXME(Calle Svensson) in the code.

talha-asad commented 6 years ago

If I set the ctx.length in my middleware, than it doesn't work right for smaller video files. confused ...

vdegenne commented 4 years ago

I have the exact same issue, also in the console I have these error messages :

  Error: write ECONNRESET
      at afterWriteDispatched (internal/stream_base_commons.js:154:25)
      at writeGeneric (internal/stream_base_commons.js:145:3)
      at Socket._writeGeneric (net.js:786:11)
      at Socket._write (net.js:798:8)
      at doWrite (_stream_writable.js:397:12)
      at clearBuffer (_stream_writable.js:550:7)
      at Socket.Writable.uncork (_stream_writable.js:332:7)
      at connectionCorkNT (_http_outgoing.js:707:8)
      at processTicksAndRejections (internal/process/task_queues.js:83:21)

Could it be related ?

yorkie commented 4 years ago

@vdegenne What you reported error seems like the connection is reset, it should be not relevant.

vdegenne commented 4 years ago

@yorkie Yes but this message occurs only when I use koa-range. Isn't that odd ?

masx200 commented 3 years ago

https://github.com/koajs/koa-range/issues/20

It seems that these two issues are the same. I have fixed it.

masx200 commented 3 years ago

https://github.com/koajs/koa-range/pull/24

colinSnake commented 1 year ago

Hello, This problem is not solved,Can you tell me a solution?

      at afterWriteDispatched (node:internal/stream_base_commons:160:15)
      at writeGeneric (node:internal/stream_base_commons:151:3)
      at Socket._writeGeneric (node:net:817:11)
      at Socket._write (node:net:829:8)
      at doWrite (node:internal/streams/writable:408:12)
      at clearBuffer (node:internal/streams/writable:569:7)
      at Socket.Writable.uncork (node:internal/streams/writable:348:7)
      at connectionCorkNT (node:_http_outgoing:797:8)
      at processTicksAndRejections (node:internal/process/task_queues:82:21)

https://github.com/koajs/koa-range/issues/14#issuecomment-624787616

mreinstein commented 1 year ago

hey, What version of koa-range are you using? I merged the fixes to git, but never published a new npm version. So unless you're referencing the latest git commit, you won't see the fixes.

colinSnake commented 1 year ago

sorry,i forgot this question, I used the version of "^0.3.0" for koa-range,how can i get this fix. https://github.com/koajs/koa-range/issues/14#issuecomment-1285710696

mreinstein commented 1 year ago

I haven't been able to publish this new code because: a) noone leftover from koa org is around anymore to review it b) PRs that I'm waiting on in other dependencies are not getting merged.

I'm planning to just publish this change, probably as 0.4.0 at some point this week, after I get a chance to do some more testing on my own, and bake in the updated deps.

colinSnake commented 1 year ago

ok, I expect to the new version, thank you for your reply. @mreinstein

mreinstein commented 1 year ago

@colinSnake I've merged my code to the master branch, so you can test this code by doing npm install koajs/koa-range.

I was going to publish these changes to npm as 0.4.0-beta but unfortunately I don't have npm rights on the koajs org, so I can't make this happen. Hopefully installing from github will be something you can test with.

If you're able to provide any feedback I'm happy to make adjustments.

Sorry it took so long!