Skip to content

Commit 5b577fe

Browse files
committed
[pkg] Remove native-duplexpair dev dependency
It seems to be no longer maintained.
1 parent 62521f2 commit 5b577fe

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"eslint-config-prettier": "^9.0.0",
5959
"eslint-plugin-prettier": "^5.0.0",
6060
"mocha": "^8.4.0",
61-
"native-duplexpair": "^1.0.0",
6261
"nyc": "^15.0.0",
6362
"prettier": "^3.0.0",
6463
"utf-8-validate": "^6.0.0"

test/duplex-pair.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// This code was copied from
3+
// https://github.com/nodejs/node/blob/c506660f3267/test/common/duplexpair.js
4+
//
5+
// Copyright Node.js contributors. All rights reserved.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to
9+
// deal in the Software without restriction, including without limitation the
10+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
11+
// sell copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23+
// IN THE SOFTWARE.
24+
//
25+
'use strict';
26+
27+
const assert = require('assert');
28+
const { Duplex } = require('stream');
29+
30+
const kCallback = Symbol('Callback');
31+
const kOtherSide = Symbol('Other');
32+
33+
class DuplexSocket extends Duplex {
34+
constructor() {
35+
super();
36+
this[kCallback] = null;
37+
this[kOtherSide] = null;
38+
}
39+
40+
_read() {
41+
const callback = this[kCallback];
42+
if (callback) {
43+
this[kCallback] = null;
44+
callback();
45+
}
46+
}
47+
48+
_write(chunk, encoding, callback) {
49+
assert.notStrictEqual(this[kOtherSide], null);
50+
assert.strictEqual(this[kOtherSide][kCallback], null);
51+
if (chunk.length === 0) {
52+
process.nextTick(callback);
53+
} else {
54+
this[kOtherSide].push(chunk);
55+
this[kOtherSide][kCallback] = callback;
56+
}
57+
}
58+
59+
_final(callback) {
60+
this[kOtherSide].on('end', callback);
61+
this[kOtherSide].push(null);
62+
}
63+
}
64+
65+
function makeDuplexPair() {
66+
const clientSide = new DuplexSocket();
67+
const serverSide = new DuplexSocket();
68+
clientSide[kOtherSide] = serverSide;
69+
serverSide[kOtherSide] = clientSide;
70+
return { clientSide, serverSide };
71+
}
72+
73+
module.exports = makeDuplexPair;

test/websocket-server.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const path = require('path');
1010
const net = require('net');
1111
const fs = require('fs');
1212
const os = require('os');
13-
const DuplexPair = require('native-duplexpair');
1413

14+
const makeDuplexPair = require('./duplex-pair');
1515
const Sender = require('../lib/sender');
1616
const WebSocket = require('..');
1717
const { NOOP } = require('../lib/constants');
@@ -526,15 +526,15 @@ describe('WebSocketServer', () => {
526526
//
527527
// Put a stream between the raw socket and our websocket processing.
528528
//
529-
const { socket1: stream1, socket2: stream2 } = new DuplexPair();
529+
const { clientSide, serverSide } = makeDuplexPair();
530530

531-
socket.pipe(stream1);
532-
stream1.pipe(socket);
531+
socket.pipe(clientSide);
532+
clientSide.pipe(socket);
533533

534534
//
535535
// Pass the other side of the stream as the socket to upgrade.
536536
//
537-
wss.handleUpgrade(req, stream2, head, (ws) => {
537+
wss.handleUpgrade(req, serverSide, head, (ws) => {
538538
ws.send('hello');
539539
ws.close();
540540
});

0 commit comments

Comments
 (0)