|
2 | 2 | * Try navigating to the adderss with Chrome and see the video |
3 | 3 | * in real time. */ |
4 | 4 |
|
5 | | -const uWS = require('../dist/uws.js'); |
| 5 | +const uWS = require('uWebSockets.js'); |
6 | 6 | const fs = require('fs'); |
7 | 7 |
|
8 | 8 | const port = 9001; |
9 | | -const fileName = 'C:\\Users\\Alex\\Downloads\\Sintel.2010.720p.mkv'; |
| 9 | +const fileName = 'spritefright.mp4'; |
10 | 10 | const totalSize = fs.statSync(fileName).size; |
11 | 11 |
|
12 | 12 | let openStreams = 0; |
@@ -46,7 +46,10 @@ function pipeStreamOverResponse(res, readStream, totalSize) { |
46 | 46 | let lastOffset = res.getWriteOffset(); |
47 | 47 |
|
48 | 48 | /* Streaming a chunk returns whether that chunk was sent, and if that chunk was last */ |
49 | | - let [ok, done] = res.tryEnd(ab, totalSize); |
| 49 | + let ok, done; |
| 50 | + res.cork(() => { |
| 51 | + [ok, done] = res.tryEnd(ab, totalSize); |
| 52 | + }); |
50 | 53 |
|
51 | 54 | /* Did we successfully send last chunk? */ |
52 | 55 | if (done) { |
@@ -96,7 +99,7 @@ const app = uWS./*SSL*/App({ |
96 | 99 | key_file_name: 'misc/key.pem', |
97 | 100 | cert_file_name: 'misc/cert.pem', |
98 | 101 | passphrase: '1234' |
99 | | -}).get('/sintel.mkv', (res, req) => { |
| 102 | +}).get('/spritefright.mp4', (res, req) => { |
100 | 103 | /* Log */ |
101 | 104 | console.time(res.id = ++streamIndex); |
102 | 105 | console.log('Stream was opened, openStreams: ' + ++openStreams); |
|
0 commit comments