Skip to content

Commit 0b33a99

Browse files
committed
Fix VideoStreamer.js with proper corking
1 parent a37ac88 commit 0b33a99

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

examples/VideoStreamer.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* Try navigating to the adderss with Chrome and see the video
33
* in real time. */
44

5-
const uWS = require('../dist/uws.js');
5+
const uWS = require('uWebSockets.js');
66
const fs = require('fs');
77

88
const port = 9001;
9-
const fileName = 'C:\\Users\\Alex\\Downloads\\Sintel.2010.720p.mkv';
9+
const fileName = 'spritefright.mp4';
1010
const totalSize = fs.statSync(fileName).size;
1111

1212
let openStreams = 0;
@@ -46,7 +46,10 @@ function pipeStreamOverResponse(res, readStream, totalSize) {
4646
let lastOffset = res.getWriteOffset();
4747

4848
/* 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+
});
5053

5154
/* Did we successfully send last chunk? */
5255
if (done) {
@@ -96,7 +99,7 @@ const app = uWS./*SSL*/App({
9699
key_file_name: 'misc/key.pem',
97100
cert_file_name: 'misc/cert.pem',
98101
passphrase: '1234'
99-
}).get('/sintel.mkv', (res, req) => {
102+
}).get('/spritefright.mp4', (res, req) => {
100103
/* Log */
101104
console.time(res.id = ++streamIndex);
102105
console.log('Stream was opened, openStreams: ' + ++openStreams);

0 commit comments

Comments
 (0)