mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-08-08 02:02:49 +00:00
Receivers: Added unified logger module
This commit is contained in:
parent
7f9d7939bc
commit
b24b3f0c55
17 changed files with 351 additions and 117 deletions
|
@ -1,10 +1,10 @@
|
|||
import * as net from 'net';
|
||||
import * as log4js from "modules/log4js";
|
||||
import { EventEmitter } from 'events';
|
||||
import { Opcode, PlaybackErrorMessage, PlaybackUpdateMessage, PlayMessage, SeekMessage, SetSpeedMessage, SetVolumeMessage, VersionMessage, VolumeUpdateMessage } from 'common/Packets';
|
||||
import { Logger, LoggerType } from 'common/Logger';
|
||||
import { WebSocket } from 'modules/ws';
|
||||
import { v4 as uuidv4 } from 'modules/uuid';
|
||||
const logger = log4js.getLogger();
|
||||
const logger = new Logger('FCastSession', LoggerType.BACKEND);
|
||||
|
||||
enum SessionState {
|
||||
Idle = 0,
|
||||
|
@ -100,7 +100,7 @@ export class FCastSession {
|
|||
return;
|
||||
}
|
||||
|
||||
logger.info(`${receivedBytes.length} bytes received`);
|
||||
logger.debug(`${receivedBytes.length} bytes received`);
|
||||
|
||||
switch (this.state) {
|
||||
case SessionState.WaitingForLength:
|
||||
|
@ -110,7 +110,7 @@ export class FCastSession {
|
|||
this.handlePacketBytes(receivedBytes);
|
||||
break;
|
||||
default:
|
||||
logger.info(`Data received is unhandled in current session state ${this.state}.`);
|
||||
logger.warn(`Data received is unhandled in current session state ${this.state}.`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -121,20 +121,20 @@ export class FCastSession {
|
|||
receivedBytes.copy(this.buffer, this.bytesRead, 0, bytesToRead);
|
||||
this.bytesRead += bytesToRead;
|
||||
|
||||
logger.info(`handleLengthBytes: Read ${bytesToRead} bytes from packet`);
|
||||
logger.debug(`handleLengthBytes: Read ${bytesToRead} bytes from packet`);
|
||||
|
||||
if (this.bytesRead >= LENGTH_BYTES) {
|
||||
this.state = SessionState.WaitingForData;
|
||||
this.packetLength = this.buffer.readUInt32LE(0);
|
||||
this.bytesRead = 0;
|
||||
logger.info(`Packet length header received from: ${this.packetLength}`);
|
||||
logger.debug(`Packet length header received from: ${this.packetLength}`);
|
||||
|
||||
if (this.packetLength > MAXIMUM_PACKET_LENGTH) {
|
||||
throw new Error(`Maximum packet length is 32kB: ${this.packetLength}`);
|
||||
}
|
||||
|
||||
if (bytesRemaining > 0) {
|
||||
logger.info(`${bytesRemaining} remaining bytes pushed to handlePacketBytes`);
|
||||
logger.debug(`${bytesRemaining} remaining bytes pushed to handlePacketBytes`);
|
||||
this.handlePacketBytes(receivedBytes.slice(bytesToRead));
|
||||
}
|
||||
}
|
||||
|
@ -146,10 +146,10 @@ export class FCastSession {
|
|||
receivedBytes.copy(this.buffer, this.bytesRead, 0, bytesToRead);
|
||||
this.bytesRead += bytesToRead;
|
||||
|
||||
logger.info(`handlePacketBytes: Read ${bytesToRead} bytes from packet`);
|
||||
logger.debug(`handlePacketBytes: Read ${bytesToRead} bytes from packet`);
|
||||
|
||||
if (this.bytesRead >= this.packetLength) {
|
||||
logger.info(`Packet finished receiving from of ${this.packetLength} bytes.`);
|
||||
logger.debug(`handlePacketBytes: Finished handling packet with ${this.packetLength} bytes. Total bytes read ${this.bytesRead}.`);
|
||||
this.handleNextPacket();
|
||||
|
||||
this.state = SessionState.WaitingForLength;
|
||||
|
@ -157,7 +157,7 @@ export class FCastSession {
|
|||
this.bytesRead = 0;
|
||||
|
||||
if (bytesRemaining > 0) {
|
||||
logger.info(`${bytesRemaining} remaining bytes pushed to handleLengthBytes`);
|
||||
logger.debug(`${bytesRemaining} remaining bytes pushed to handleLengthBytes`);
|
||||
this.handleLengthBytes(receivedBytes.slice(bytesToRead));
|
||||
}
|
||||
}
|
||||
|
@ -206,11 +206,8 @@ export class FCastSession {
|
|||
}
|
||||
|
||||
private handleNextPacket() {
|
||||
logger.info(`Processing packet of ${this.bytesRead} bytes from`);
|
||||
|
||||
const opcode = this.buffer[0];
|
||||
const body = this.packetLength > 1 ? this.buffer.toString('utf8', 1, this.packetLength) : null;
|
||||
logger.info('body', body);
|
||||
this.handlePacket(opcode, body);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue