mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-09-03 13:29:11 +00:00
add frame id paramter for encoder
This commit is contained in:
+27
-7
@@ -20,7 +20,17 @@ export class Encoder {
|
|||||||
this.versionLow = versionLow;
|
this.versionLow = versionLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
getInfoPackets(timestamp: bigint, trackers: Tracker[]) {
|
getInfoPackets(timestamp: bigint, trackers: Tracker[], frameId?: number) {
|
||||||
|
if (frameId !== undefined) {
|
||||||
|
if (!Number.isInteger(frameId)) {
|
||||||
|
throw new Error('frame id must be an integer');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frameId > 255 || frameId < 0) {
|
||||||
|
throw new Error('frame id must be >= 0 and <= 255');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const systemNameChunk = infoSystemNameChunk(this.systemName);
|
const systemNameChunk = infoSystemNameChunk(this.systemName);
|
||||||
|
|
||||||
const trackerChunks = trackers.map((tracker: Tracker) => tracker.getInfoChunk());
|
const trackerChunks = trackers.map((tracker: Tracker) => tracker.getInfoChunk());
|
||||||
@@ -46,20 +56,30 @@ export class Encoder {
|
|||||||
timestamp,
|
timestamp,
|
||||||
this.versionHigh,
|
this.versionHigh,
|
||||||
this.versionLow,
|
this.versionLow,
|
||||||
this.infoFrameId,
|
frameId ? frameId : this.infoFrameId,
|
||||||
trackerChunksLists.length
|
trackerChunksLists.length
|
||||||
);
|
);
|
||||||
trackerChunksLists.forEach((trackerChunkList) => {
|
trackerChunksLists.forEach((trackerChunkList) => {
|
||||||
infoPackets.push(infoPacketChunk(header, systemNameChunk, infoTrackerListChunk(trackerChunkList)));
|
infoPackets.push(infoPacketChunk(header, systemNameChunk, infoTrackerListChunk(trackerChunkList)));
|
||||||
});
|
});
|
||||||
this.dataFrameId += 1;
|
this.infoFrameId += 1;
|
||||||
if (this.dataFrameId > 255) {
|
if (this.infoFrameId > 255) {
|
||||||
this.dataFrameId = 0;
|
this.infoFrameId = 0;
|
||||||
}
|
}
|
||||||
return infoPackets;
|
return infoPackets;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDataPackets(timestamp: bigint, trackers: Tracker[]) {
|
getDataPackets(timestamp: bigint, trackers: Tracker[], frameId?: number) {
|
||||||
|
if (frameId !== undefined) {
|
||||||
|
if (!Number.isInteger(frameId)) {
|
||||||
|
throw new Error('frame id must be an integer');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frameId > 255 || frameId < 0) {
|
||||||
|
throw new Error('frame id must be >= 0 and <= 255');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const allTrackerChunks = trackers.map((tracker) => tracker.getDataChunk());
|
const allTrackerChunks = trackers.map((tracker) => tracker.getDataChunk());
|
||||||
const dataPackets: Buffer[] = [];
|
const dataPackets: Buffer[] = [];
|
||||||
|
|
||||||
@@ -83,7 +103,7 @@ export class Encoder {
|
|||||||
timestamp,
|
timestamp,
|
||||||
this.versionHigh,
|
this.versionHigh,
|
||||||
this.versionLow,
|
this.versionLow,
|
||||||
this.dataFrameId,
|
frameId ? frameId : this.dataFrameId,
|
||||||
trackerChunksLists.length
|
trackerChunksLists.length
|
||||||
);
|
);
|
||||||
trackerChunksLists.forEach((trackerChunks) => {
|
trackerChunksLists.forEach((trackerChunks) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user