Skip to content

Commit

Permalink
Merge pull request #43 from project-slippi/fix/enet-import
Browse files Browse the repository at this point in the history
Dynamically import enet
  • Loading branch information
NikhilNarayana authored Nov 26, 2020
2 parents e28e309 + aeaeb89 commit e73e193
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slippi/slippi-js",
"version": "5.1.0",
"version": "5.1.1",
"description": "Official Project Slippi Javascript SDK",
"license": "LGPL-3.0-or-later",
"repository": "project-slippi/slippi-js",
Expand Down
30 changes: 14 additions & 16 deletions src/console/dolphinConnection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import enet from "enet";

import { EventEmitter } from "events";
import { Connection, ConnectionStatus, ConnectionSettings, ConnectionDetails, Ports, ConnectionEvent } from "./types";

Expand All @@ -19,21 +17,12 @@ export class DolphinConnection extends EventEmitter implements Connection {
private gameCursor = 0;
private nickname = "unknown";
private version = "";
private client: enet.Host;
private peer: enet.Peer | null = null;
private peer: any | null = null;

public constructor() {
super();
this.ipAddress = "0.0.0.0";
this.port = Ports.DEFAULT;

// Create the enet client
this.client = enet.createClient({ peers: MAX_PEERS, channels: 3, down: 0, up: 0 }, (err) => {
if (err) {
console.error(err);
return;
}
});
}

/**
Expand Down Expand Up @@ -61,19 +50,28 @@ export class DolphinConnection extends EventEmitter implements Connection {
};
}

public connect(ip: string, port: number): void {
public async connect(ip: string, port: number): Promise<void> {
console.log(`Connecting to: ${ip}:${port}`);
this.ipAddress = ip;
this.port = port;

this.peer = this.client.connect(
const enet = await import("enet");
// Create the enet client
const client = enet.createClient({ peers: MAX_PEERS, channels: 3, down: 0, up: 0 }, (err) => {
if (err) {
console.error(err);
return;
}
});

this.peer = client.connect(
{
address: this.ipAddress,
port: this.port,
},
3,
1337, // Data to send, not sure what this is or what this represents
(err, newPeer) => {
(err: any, newPeer: any) => {
if (err) {
console.error(err);
return;
Expand All @@ -98,7 +96,7 @@ export class DolphinConnection extends EventEmitter implements Connection {
this.peer.send(0, packet);
});

this.peer.on("message", (packet: enet.Packet) => {
this.peer.on("message", (packet: any) => {
const data = packet.data();
if (data.length === 0) {
return;
Expand Down
18 changes: 8 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
"compilerOptions": {
"declaration": true,
"declarationDir": "./dist",
"module": "es6",
"module": "esnext",
"noImplicitAny": true,
"moduleResolution": "node",
"outDir": "./dist",
"target": "es5",
"esModuleInterop": true
"target": "es2018",
"esModuleInterop": true,
"sourceMap": true,
"lib": ["esnext"]
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}
"include": ["src/**/*"],
"exclude": ["node_modules"]
}

0 comments on commit e73e193

Please sign in to comment.