• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

project-slippi / slippi-js / 20256930381

16 Dec 2025 04:53AM UTC coverage: 80.865% (+0.05%) from 80.813%
20256930381

Pull #158

github

web-flow
Merge ec5cb46f6 into 414f15082
Pull Request #158: refactor: prefer undefined over null

690 of 921 branches covered (74.92%)

Branch coverage included in aggregate %.

70 of 90 new or added lines in 21 files covered. (77.78%)

1 existing line in 1 file now uncovered.

1854 of 2225 relevant lines covered (83.33%)

125903.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.81
/src/node/console/communication.ts
1
import { decode, encode } from "@shelacek/ubjson";
12✔
2

3
export enum CommunicationType {
12✔
4
  HANDSHAKE = 1,
12✔
5
  REPLAY = 2,
12✔
6
  KEEP_ALIVE = 3,
12✔
7
}
8

9
export type CommunicationMessage = {
10
  type: CommunicationType;
11
  payload: {
12
    cursor: Uint8Array;
13
    clientToken: Uint8Array;
14
    pos: Uint8Array;
15
    nextPos: Uint8Array;
16
    data: Uint8Array;
17
    nick: string | undefined;
18
    forcePos: boolean;
19
    nintendontVersion: string | undefined;
20
  };
21
};
22

23
// This class is responsible for handling the communication protocol between the Wii and the
24
// desktop app
25
export class ConsoleCommunication {
12✔
26
  private receiveBuf = Buffer.from([]);
×
NEW
27
  private messages: CommunicationMessage[] = [];
×
28

29
  public receive(data: Buffer): void {
30
    this.receiveBuf = Buffer.concat([this.receiveBuf, data]);
×
31

32
    while (this.receiveBuf.length >= 4) {
×
33
      // First get the size of the message we are expecting
34
      const msgSize = this.receiveBuf.readUInt32BE(0);
×
35

36
      if (this.receiveBuf.length < msgSize + 4) {
×
37
        // If we haven't received all the data yet, let's wait for more
38
        return;
×
39
      }
40

41
      // Here we have received all the data, so let's decode it
42
      const ubjsonArrayBuffer = this.receiveBuf.buffer.slice(
×
43
        this.receiveBuf.byteOffset + 4,
44
        this.receiveBuf.byteOffset + msgSize + 4,
45
      );
46
      this.messages.push(decode(ubjsonArrayBuffer));
×
47

48
      // Remove the processed data from receiveBuf
49
      this.receiveBuf = this.receiveBuf.subarray(msgSize + 4);
×
50
    }
51
  }
52

53
  public getReceiveBuffer(): Buffer {
54
    return this.receiveBuf;
×
55
  }
56

57
  public getMessages(): Array<CommunicationMessage> {
58
    const toReturn = this.messages;
×
59
    this.messages = [];
×
60

61
    return toReturn;
×
62
  }
63

64
  public genHandshakeOut(cursor: Uint8Array, clientToken: number, isRealtime = false): Buffer {
×
65
    const clientTokenBuf = Buffer.from([0, 0, 0, 0]);
×
66
    clientTokenBuf.writeUInt32BE(clientToken, 0);
×
67

68
    const message = {
×
69
      type: CommunicationType.HANDSHAKE,
70
      payload: {
71
        cursor: cursor,
72
        clientToken: Uint8Array.from(clientTokenBuf), // TODO: Use real instance token
73
        isRealtime: isRealtime,
74
      },
75
    };
76

77
    const buf = encode(message, {
×
78
      optimizeArrays: true,
79
    });
80

81
    const msg = Buffer.concat([Buffer.from([0, 0, 0, 0]), Buffer.from(buf)]);
×
82

83
    msg.writeUInt32BE(buf.byteLength, 0);
×
84

85
    return msg;
×
86
  }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc