Skip to content

Commit

Permalink
remove lodash dependency from rtp and common packages
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Nov 9, 2023
1 parent 098e723 commit 0f85c86
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 44 deletions.
9 changes: 0 additions & 9 deletions packages/common/src/array.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ export * from "./binary";
export * from "./number";
export * from "./promise";
export * from "./network";
export * from "./array";
export * from "./type";
export * from "./log";
2 changes: 0 additions & 2 deletions packages/rtp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
"buffer": "^6.0.3",
"debug": "^4.3.4",
"jspack": "^0.0.4",
"lodash": "^4.17.21",
"rx.mini": "^1.2.2"
},
"devDependencies": {
"@types/aes-js": "^3.1.1",
"@types/debug": "^4.1.7",
"@types/lodash": "^4.14.191",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"react": "^18.2.0",
Expand Down
9 changes: 6 additions & 3 deletions packages/rtp/src/processor/nack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import debug from "debug";
import range from "lodash/range";
import Event from "rx.mini";

import {
Expand Down Expand Up @@ -110,9 +109,13 @@ export class NackHandlerBase
this.newEstSeqNum = sequenceNumber;
} else if (sequenceNumber > uint16Add(this.newEstSeqNum, 1)) {
// packet lost detected
range(uint16Add(this.newEstSeqNum, 1), sequenceNumber).forEach((seq) => {
for (
let seq = uint16Add(this.newEstSeqNum, 1);
seq < sequenceNumber;
seq++
) {
this.setLost(seq, 1);
});
}
// this.receiver.sendRtcpPLI(this.mediaSourceSsrc);

this.newEstSeqNum = sequenceNumber;
Expand Down
6 changes: 2 additions & 4 deletions packages/rtp/src/rtcp/rr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import range from "lodash/range";

import { bufferReader, bufferWriter } from "../../../common/src";
import { RtcpPacketConverter } from "./rtcp";

Expand Down Expand Up @@ -31,10 +29,10 @@ export class RtcpRrPacket {
const [ssrc] = bufferReader(data, [4]);
let pos = 4;
const reports: RtcpReceiverInfo[] = [];
range(count).forEach(() => {
for (let _ = 0; _ < count; _++) {
reports.push(RtcpReceiverInfo.deSerialize(data.slice(pos, pos + 24)));
pos += 24;
});
}
return new RtcpRrPacket({ ssrc, reports });
}
}
Expand Down
26 changes: 11 additions & 15 deletions packages/rtp/src/rtcp/rtpfb/nack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import range from "lodash/range";

import { bufferReader, bufferWriter } from "../../../../common/src";
import { RtcpHeader } from "../header";
import { RtcpTransportLayerFeedback } from ".";
Expand Down Expand Up @@ -42,19 +40,17 @@ export class GenericNack {

static deSerialize(data: Buffer, header: RtcpHeader) {
const [senderSsrc, mediaSourceSsrc] = bufferReader(data, [4, 4]);
const lost = range(8, data.length, 4)
.map((pos) => {
const lost: number[] = [];
const [pid, blp] = bufferReader(data.subarray(pos), [2, 2]);
lost.push(pid);
range(0, 16).forEach((diff) => {
if ((blp >> diff) & 1) {
lost.push(pid + diff + 1);
}
});
return lost;
})
.flatMap((v) => v);

const lost: number[] = [];
for (let pos = 8; pos < data.length; pos += 4) {
const [pid, blp] = bufferReader(data.subarray(pos), [2, 2]);
lost.push(pid);
for (let diff = 0; diff < 16; diff++) {
if ((blp >> diff) & 1) {
lost.push(pid + diff + 1);
}
}
}

return new GenericNack({
header,
Expand Down
19 changes: 12 additions & 7 deletions packages/rtp/src/rtcp/rtpfb/twcc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import debug from "debug";
import range from "lodash/range";

import {
BitWriter2,
Expand Down Expand Up @@ -105,11 +104,11 @@ export class TransportWideCC {
packetStatus.packetStatus ===
PacketStatus.TypeTCCPacketReceivedLargeDelta
) {
range(packetNumberToProcess).forEach(() => {
for (let _ = 0; _ < packetNumberToProcess; _++) {
recvDeltas.push(
new RecvDelta({ type: packetStatus.packetStatus as any })
);
});
}
}
processedPacketNum += packetNumberToProcess;
}
Expand Down Expand Up @@ -313,14 +312,20 @@ export class StatusVectorChunk {
let symbolSize = getBit(data[0], 1, 1);
const symbolList: number[] = [];

function range(n: number, cb: (i: number) => void) {
for (let i = 0; i < n; i++) {
cb(i);
}
}

switch (symbolSize) {
case 0:
range(6).forEach((_, i) => symbolList.push(getBit(data[0], 2 + i, 1)));
range(8).forEach((_, i) => symbolList.push(getBit(data[1], i, 1)));
range(6, (i) => symbolList.push(getBit(data[0], 2 + i, 1)));
range(8, (i) => symbolList.push(getBit(data[1], i, 1)));
break;
case 1:
range(3).forEach((i) => symbolList.push(getBit(data[0], 2 + i * 2, 2)));
range(4).forEach((i) => symbolList.push(getBit(data[1], i * 2, 2)));
range(6, (i) => symbolList.push(getBit(data[0], 2 + i * 2, 2)));
range(6, (i) => symbolList.push(getBit(data[1], i * 2, 2)));
break;
default:
symbolSize = (getBit(data[0], 2, 6) << 8) + data[1];
Expand Down
4 changes: 1 addition & 3 deletions packages/rtp/src/rtcp/sr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import range from "lodash/range";

import { bufferReader, bufferWriter } from "../../../common/src";
import { RtcpReceiverInfo } from "./rr";
import { RtcpPacketConverter } from "./rtcp";
Expand Down Expand Up @@ -81,7 +79,7 @@ export class RtcpSrPacket {
const senderInfo = RtcpSenderInfo.deSerialize(payload.subarray(4, 24));
let pos = 24;
const reports: RtcpReceiverInfo[] = [];
for (const _ of range(count)) {
for (let _ = 0; _ < count; _++) {
reports.push(
RtcpReceiverInfo.deSerialize(payload.subarray(pos, pos + 24))
);
Expand Down
9 changes: 9 additions & 0 deletions packages/webrtc/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable prefer-const */
import { createHash } from "crypto";
import debug from "debug";
import mergeWith from "lodash/mergeWith";
import { performance } from "perf_hooks";

import {
Expand Down Expand Up @@ -131,3 +132,11 @@ export class RtpBuilder {
*/
export const createSelfSignedCertificate =
CipherContext.createSelfSignedCertificateWithKey;

export const deepMerge = <T>(dst: T, src: T) =>
mergeWith(dst, src, (obj, src) => {
if (!(src == undefined)) {
return src;
}
return obj;
});

0 comments on commit 0f85c86

Please sign in to comment.