Skip to content

Commit

Permalink
Merge branch 'master' into arraybuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceau committed Aug 16, 2021
2 parents 3836713 + 495258e commit f2ca230
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/console/consoleConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export type ConsoleConnectionOptions = typeof consoleConnectionOptions;
export class ConsoleConnection extends EventEmitter implements Connection {
private ipAddress: string;
private port: number;
private isRealtime: boolean;
private connectionStatus = ConnectionStatus.DISCONNECTED;
private connDetails: ConnectionDetails = { ...defaultConnectionDetails };
private client: net.Socket | null = null;
Expand All @@ -64,6 +65,7 @@ export class ConsoleConnection extends EventEmitter implements Connection {
super();
this.ipAddress = "0.0.0.0";
this.port = Ports.DEFAULT;
this.isRealtime = false;
this.options = Object.assign({}, consoleConnectionOptions, options);
}

Expand Down Expand Up @@ -95,12 +97,14 @@ export class ConsoleConnection extends EventEmitter implements Connection {
* Initiate a connection to the Wii or Slippi relay.
* @param ip The IP address of the Wii or Slippi relay.
* @param port The port to connect to.
* @param isRealtime Optional. A flag to tell the Wii to send data as quickly as possible
* @param timeout Optional. The timeout in milliseconds when attempting to connect
* to the Wii or relay.
*/
public connect(ip: string, port: number, timeout = DEFAULT_CONNECTION_TIMEOUT_MS): void {
public connect(ip: string, port: number, isRealtime = false, timeout = DEFAULT_CONNECTION_TIMEOUT_MS): void {
this.ipAddress = ip;
this.port = port;
this.isRealtime = isRealtime;
this._connectOnPort(ip, port, timeout);
}

Expand Down Expand Up @@ -196,6 +200,7 @@ export class ConsoleConnection extends EventEmitter implements Connection {
const handshakeMsgOut = consoleComms.genHandshakeOut(
this.connDetails.gameDataCursor as Uint8Array,
this.connDetails.clientToken ?? 0,
this.isRealtime,
);

client.write(handshakeMsgOut);
Expand All @@ -220,8 +225,10 @@ export class ConsoleConnection extends EventEmitter implements Connection {
// TODO: Connecting... forever
});

connection.on("error", (error) => {
console.error(`Connection on port ${port} encountered an error.`, error);
connection.on("error", (err) => {
console.warn(`Connection on port ${port} encountered an error.`, err);

this.emit(ConnectionEvent.ERROR, `Connection on port ${port} encountered an error.\n${err}`);
});

this.connection = connection;
Expand Down
1 change: 1 addition & 0 deletions src/console/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./communication";
export * from "./consoleConnection";
export * from "./dolphinConnection";
export * from "./types";

0 comments on commit f2ca230

Please sign in to comment.