@neko-net/rusty-enet 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/index.d.ts +205 -0
- package/index.js +318 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @neko-net/rusty-enet
|
|
2
|
+
|
|
3
|
+
Node.js binding for [ENet](http://enet.bespin.org/) via [rusty_enet](https://github.com/neko-net/rusty_enet), built with [napi-rs](https://napi.rs).
|
|
4
|
+
|
|
5
|
+
ENet is a thin UDP networking layer designed for real-time applications like games, providing optional reliable, sequenced packet delivery over multiple channels.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @neko-net/rusty-enet
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Prebuilt binaries for Linux (x64, arm64), macOS (x64, arm64), and Windows (x64, arm64).
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const { EnetHost, PacketKind } = require('@neko-net/rusty-enet');
|
|
19
|
+
|
|
20
|
+
async function main() {
|
|
21
|
+
// Server
|
|
22
|
+
const server = new EnetHost('127.0.0.1:0', { peerLimit: 1, channelLimit: 2 });
|
|
23
|
+
const port = (await server.getLocalAddr()).split(':').pop();
|
|
24
|
+
|
|
25
|
+
// Client
|
|
26
|
+
const client = new EnetHost('127.0.0.1:0', { peerLimit: 1, channelLimit: 2 });
|
|
27
|
+
await client.connect(`127.0.0.1:${port}`, 2, 0);
|
|
28
|
+
|
|
29
|
+
// Connect events fire on both sides
|
|
30
|
+
await server.service(); // { eventType: 'Connect', peerId: 0, data: 0 }
|
|
31
|
+
await client.service(); // { eventType: 'Connect', peerId: 0 }
|
|
32
|
+
|
|
33
|
+
// Send a reliable packet
|
|
34
|
+
await client.send(0, 0, Buffer.from('hello'), PacketKind.Reliable);
|
|
35
|
+
const recv = await server.service();
|
|
36
|
+
console.log(recv.packet.toString()); // "hello"
|
|
37
|
+
|
|
38
|
+
server.close();
|
|
39
|
+
client.close();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
main();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
MIT
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
/** Packet delivery guarantees. */
|
|
7
|
+
export const enum PacketKind {
|
|
8
|
+
/**
|
|
9
|
+
* No reliability or sequencing. Packets may be dropped and are not
|
|
10
|
+
* retransmitted. Duplicate packets are discarded.
|
|
11
|
+
*/
|
|
12
|
+
Unreliable = 'Unreliable',
|
|
13
|
+
/**
|
|
14
|
+
* No reliability, no sequencing, and no duplicate suppression. Packets may
|
|
15
|
+
* be dropped and duplicates are delivered as-is.
|
|
16
|
+
*/
|
|
17
|
+
UnreliableUnsequenced = 'UnreliableUnsequenced',
|
|
18
|
+
/**
|
|
19
|
+
* Guaranteed delivery and ordering. Packets are retransmitted until
|
|
20
|
+
* acknowledged.
|
|
21
|
+
*/
|
|
22
|
+
Reliable = 'Reliable',
|
|
23
|
+
/**
|
|
24
|
+
* Like `Unreliable` but never fragmented; dropped entirely if larger
|
|
25
|
+
* than the MTU.
|
|
26
|
+
*/
|
|
27
|
+
AlwaysUnreliable = 'AlwaysUnreliable',
|
|
28
|
+
/** Like `UnreliableUnsequenced` but never fragmented. */
|
|
29
|
+
AlwaysUnreliableUnsequenced = 'AlwaysUnreliableUnsequenced'
|
|
30
|
+
}
|
|
31
|
+
/** Event returned by `host.service()`. */
|
|
32
|
+
export const enum EventType {
|
|
33
|
+
/** A new peer connected. */
|
|
34
|
+
Connect = 'Connect',
|
|
35
|
+
/** A peer disconnected. */
|
|
36
|
+
Disconnect = 'Disconnect',
|
|
37
|
+
/** A packet was received. */
|
|
38
|
+
Receive = 'Receive'
|
|
39
|
+
}
|
|
40
|
+
/** Connection lifecycle state of a peer. */
|
|
41
|
+
export const enum PeerState {
|
|
42
|
+
/** Peer is not connected. */
|
|
43
|
+
Disconnected = 'Disconnected',
|
|
44
|
+
/** Connection request has been sent. */
|
|
45
|
+
Connecting = 'Connecting',
|
|
46
|
+
/** Acknowledging a connection request. */
|
|
47
|
+
AcknowledgingConnect = 'AcknowledgingConnect',
|
|
48
|
+
/** Connection is pending acceptance. */
|
|
49
|
+
ConnectionPending = 'ConnectionPending',
|
|
50
|
+
/** Connection has succeeded (handshake complete). */
|
|
51
|
+
ConnectionSucceeded = 'ConnectionSucceeded',
|
|
52
|
+
/** Peer is fully connected and can send/receive. */
|
|
53
|
+
Connected = 'Connected',
|
|
54
|
+
/** Peer will disconnect after all queued outgoing packets are sent. */
|
|
55
|
+
DisconnectLater = 'DisconnectLater',
|
|
56
|
+
/** Disconnect request has been sent, waiting for acknowledgment. */
|
|
57
|
+
Disconnecting = 'Disconnecting',
|
|
58
|
+
/** Acknowledging a disconnect request. */
|
|
59
|
+
AcknowledgingDisconnect = 'AcknowledgingDisconnect',
|
|
60
|
+
/** Peer has been disconnected but freed. Should no longer be referenced. */
|
|
61
|
+
Zombie = 'Zombie'
|
|
62
|
+
}
|
|
63
|
+
/** Settings passed to the `EnetHost` constructor. */
|
|
64
|
+
export interface HostSettings {
|
|
65
|
+
/** Maximum number of connected peers (default: 64). */
|
|
66
|
+
peerLimit?: number
|
|
67
|
+
/** Maximum number of channels per peer (default: 0). */
|
|
68
|
+
channelLimit?: number
|
|
69
|
+
/** Downstream bandwidth limit in bytes/second (default: 0 = unlimited). */
|
|
70
|
+
incomingBandwidth?: number
|
|
71
|
+
/** Upstream bandwidth limit in bytes/second (default: 0 = unlimited). */
|
|
72
|
+
outgoingBandwidth?: number
|
|
73
|
+
/** PRNG seed for ENet's internal random number generator. */
|
|
74
|
+
seed?: number
|
|
75
|
+
}
|
|
76
|
+
/** An event delivered by `host.service()`. */
|
|
77
|
+
export interface EnetEvent {
|
|
78
|
+
/** What kind of event occurred. */
|
|
79
|
+
eventType: EventType
|
|
80
|
+
/** The peer this event relates to. */
|
|
81
|
+
peerId: number
|
|
82
|
+
/**
|
|
83
|
+
* Event-specific data: connect data on `Connect`, disconnect reason on
|
|
84
|
+
* `Disconnect`.
|
|
85
|
+
*/
|
|
86
|
+
data?: number
|
|
87
|
+
/** Channel the packet arrived on (`Receive` only). */
|
|
88
|
+
channelId?: number
|
|
89
|
+
/** Received packet data (`Receive` only). */
|
|
90
|
+
packet?: Buffer
|
|
91
|
+
}
|
|
92
|
+
/** Snapshot of a peer's current state and statistics. */
|
|
93
|
+
export interface PeerInfo {
|
|
94
|
+
/** Current connection lifecycle state. */
|
|
95
|
+
state: PeerState
|
|
96
|
+
/** Number of channels this peer has open. */
|
|
97
|
+
channelCount: number
|
|
98
|
+
/** Smoothed round-trip time in milliseconds. */
|
|
99
|
+
roundTripTimeMs: number
|
|
100
|
+
/** Variance of the round-trip time in milliseconds. */
|
|
101
|
+
roundTripTimeVarianceMs: number
|
|
102
|
+
/** Packet loss as a fixed-point 32.32 value (0 = none, 1<<32 = 100%). */
|
|
103
|
+
packetLoss: number
|
|
104
|
+
/** Total packets sent to this peer. */
|
|
105
|
+
packetsSent: number
|
|
106
|
+
/** Total packets lost (not acknowledged by this peer). */
|
|
107
|
+
packetsLost: number
|
|
108
|
+
/** Current incoming bandwidth limit in bytes/second. */
|
|
109
|
+
incomingBandwidth: number
|
|
110
|
+
/** Current outgoing bandwidth limit in bytes/second. */
|
|
111
|
+
outgoingBandwidth: number
|
|
112
|
+
/** Remote IP address and port, if known. */
|
|
113
|
+
address?: string
|
|
114
|
+
}
|
|
115
|
+
export declare class EnetHost {
|
|
116
|
+
constructor(bindAddr: string, settings?: HostSettings | undefined | null)
|
|
117
|
+
/**
|
|
118
|
+
* Waits for the next event from this host.
|
|
119
|
+
*
|
|
120
|
+
* Returns `null` after the host has been closed via `close()` or when the
|
|
121
|
+
* host is dropped.
|
|
122
|
+
*/
|
|
123
|
+
service(): Promise<EnetEvent | null>
|
|
124
|
+
/**
|
|
125
|
+
* Shuts down the host and its background thread.
|
|
126
|
+
*
|
|
127
|
+
* After calling `close()`, `service()` will return `null`.
|
|
128
|
+
*/
|
|
129
|
+
close(): void
|
|
130
|
+
/** Flushes all queued outgoing packets immediately. */
|
|
131
|
+
flush(): Promise<void>
|
|
132
|
+
/**
|
|
133
|
+
* Initiates a connection to a remote host.
|
|
134
|
+
*
|
|
135
|
+
* `channel_count` is the number of channels to allocate for this peer.
|
|
136
|
+
* `data` is sent along with the connection request and delivered as the
|
|
137
|
+
* `data` field on the `Connect` event at the remote host.
|
|
138
|
+
*
|
|
139
|
+
* Returns the assigned peer ID.
|
|
140
|
+
*/
|
|
141
|
+
connect(addr: string, channelCount: number, data: number): Promise<number>
|
|
142
|
+
/** Returns the current `PeerState` of the given peer. */
|
|
143
|
+
getPeerState(peerId: number): Promise<PeerState>
|
|
144
|
+
/** Returns a snapshot of the peer's state, timing, and bandwidth stats. */
|
|
145
|
+
getPeerInfo(peerId: number): Promise<PeerInfo>
|
|
146
|
+
/** Sends a packet to a peer on a given channel. */
|
|
147
|
+
send(peerId: number, channelId: number, data: Buffer, kind: PacketKind): Promise<void>
|
|
148
|
+
/** Sends a packet to all connected peers on a given channel. */
|
|
149
|
+
broadcast(channelId: number, data: Buffer, kind: PacketKind): Promise<void>
|
|
150
|
+
/**
|
|
151
|
+
* Requests a graceful disconnect. The peer will be disconnected once all
|
|
152
|
+
* queued outgoing packets are sent. `data` is delivered as the disconnect
|
|
153
|
+
* reason.
|
|
154
|
+
*/
|
|
155
|
+
disconnect(peerId: number, data: number): Promise<void>
|
|
156
|
+
/**
|
|
157
|
+
* Disconnects the peer immediately, discarding any queued outgoing
|
|
158
|
+
* packets. `data` is delivered as the disconnect reason.
|
|
159
|
+
*/
|
|
160
|
+
disconnectNow(peerId: number, data: number): Promise<void>
|
|
161
|
+
/**
|
|
162
|
+
* Marks the peer for disconnection after all queued outgoing packets are
|
|
163
|
+
* sent. `data` is delivered as the disconnect reason.
|
|
164
|
+
*/
|
|
165
|
+
disconnectLater(peerId: number, data: number): Promise<void>
|
|
166
|
+
/**
|
|
167
|
+
* Sends a ping to the peer. The round-trip time will be updated in
|
|
168
|
+
* `get_peer_info()`.
|
|
169
|
+
*/
|
|
170
|
+
ping(peerId: number): Promise<void>
|
|
171
|
+
/**
|
|
172
|
+
* Sets the timeout parameters for a peer.
|
|
173
|
+
*
|
|
174
|
+
* `limit` timeout limit in milliseconds before the peer is disconnected
|
|
175
|
+
* after an unacknowledged packet.
|
|
176
|
+
* `min` minimum timeout in milliseconds.
|
|
177
|
+
* `max` maximum timeout in milliseconds.
|
|
178
|
+
*/
|
|
179
|
+
setTimeout(peerId: number, limit: number, min: number, max: number): Promise<void>
|
|
180
|
+
/** Sets how often pings are sent to the peer (in milliseconds). */
|
|
181
|
+
setPingInterval(peerId: number, interval: number): Promise<void>
|
|
182
|
+
/**
|
|
183
|
+
* Controls the throttle mechanism for a peer.
|
|
184
|
+
*
|
|
185
|
+
* `interval` interval in milliseconds between throttle adjustments.
|
|
186
|
+
* `accel` acceleration factor.
|
|
187
|
+
* `decel` deceleration factor.
|
|
188
|
+
*/
|
|
189
|
+
setThrottle(peerId: number, interval: number, accel: number, decel: number): Promise<void>
|
|
190
|
+
/** Sets the maximum number of channels for future connections. */
|
|
191
|
+
setChannelLimit(limit: number): Promise<void>
|
|
192
|
+
/**
|
|
193
|
+
* Sets the bandwidth limits for the host in bytes/second.
|
|
194
|
+
* Pass `null`/`undefined` to leave a limit unchanged.
|
|
195
|
+
*/
|
|
196
|
+
setBandwidthLimit(incoming?: number | undefined | null, outgoing?: number | undefined | null): Promise<void>
|
|
197
|
+
/** Sets the maximum transmission unit (MTU) in bytes. */
|
|
198
|
+
setMtu(mtu: number): Promise<void>
|
|
199
|
+
/** Returns the maximum number of peers this host allows. */
|
|
200
|
+
getPeerLimit(): Promise<number>
|
|
201
|
+
/** Returns the maximum number of channels per peer. */
|
|
202
|
+
getChannelLimit(): Promise<number>
|
|
203
|
+
/** Returns the local address this host is bound to (e.g. `"127.0.0.1:12345"`). */
|
|
204
|
+
getLocalAddr(): Promise<string>
|
|
205
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* prettier-ignore */
|
|
4
|
+
|
|
5
|
+
/* auto-generated by NAPI-RS */
|
|
6
|
+
|
|
7
|
+
const { existsSync, readFileSync } = require('fs')
|
|
8
|
+
const { join } = require('path')
|
|
9
|
+
|
|
10
|
+
const { platform, arch } = process
|
|
11
|
+
|
|
12
|
+
let nativeBinding = null
|
|
13
|
+
let localFileExisted = false
|
|
14
|
+
let loadError = null
|
|
15
|
+
|
|
16
|
+
function isMusl() {
|
|
17
|
+
// For Node 10
|
|
18
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
19
|
+
try {
|
|
20
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
21
|
+
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
27
|
+
return !glibcVersionRuntime
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case 'android':
|
|
33
|
+
switch (arch) {
|
|
34
|
+
case 'arm64':
|
|
35
|
+
localFileExisted = existsSync(join(__dirname, 'rusty-enet.android-arm64.node'))
|
|
36
|
+
try {
|
|
37
|
+
if (localFileExisted) {
|
|
38
|
+
nativeBinding = require('./rusty-enet.android-arm64.node')
|
|
39
|
+
} else {
|
|
40
|
+
nativeBinding = require('@neko-net/rusty-enet-android-arm64')
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
loadError = e
|
|
44
|
+
}
|
|
45
|
+
break
|
|
46
|
+
case 'arm':
|
|
47
|
+
localFileExisted = existsSync(join(__dirname, 'rusty-enet.android-arm-eabi.node'))
|
|
48
|
+
try {
|
|
49
|
+
if (localFileExisted) {
|
|
50
|
+
nativeBinding = require('./rusty-enet.android-arm-eabi.node')
|
|
51
|
+
} else {
|
|
52
|
+
nativeBinding = require('@neko-net/rusty-enet-android-arm-eabi')
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
loadError = e
|
|
56
|
+
}
|
|
57
|
+
break
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
60
|
+
}
|
|
61
|
+
break
|
|
62
|
+
case 'win32':
|
|
63
|
+
switch (arch) {
|
|
64
|
+
case 'x64':
|
|
65
|
+
localFileExisted = existsSync(
|
|
66
|
+
join(__dirname, 'rusty-enet.win32-x64-msvc.node')
|
|
67
|
+
)
|
|
68
|
+
try {
|
|
69
|
+
if (localFileExisted) {
|
|
70
|
+
nativeBinding = require('./rusty-enet.win32-x64-msvc.node')
|
|
71
|
+
} else {
|
|
72
|
+
nativeBinding = require('@neko-net/rusty-enet-win32-x64-msvc')
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
loadError = e
|
|
76
|
+
}
|
|
77
|
+
break
|
|
78
|
+
case 'ia32':
|
|
79
|
+
localFileExisted = existsSync(
|
|
80
|
+
join(__dirname, 'rusty-enet.win32-ia32-msvc.node')
|
|
81
|
+
)
|
|
82
|
+
try {
|
|
83
|
+
if (localFileExisted) {
|
|
84
|
+
nativeBinding = require('./rusty-enet.win32-ia32-msvc.node')
|
|
85
|
+
} else {
|
|
86
|
+
nativeBinding = require('@neko-net/rusty-enet-win32-ia32-msvc')
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadError = e
|
|
90
|
+
}
|
|
91
|
+
break
|
|
92
|
+
case 'arm64':
|
|
93
|
+
localFileExisted = existsSync(
|
|
94
|
+
join(__dirname, 'rusty-enet.win32-arm64-msvc.node')
|
|
95
|
+
)
|
|
96
|
+
try {
|
|
97
|
+
if (localFileExisted) {
|
|
98
|
+
nativeBinding = require('./rusty-enet.win32-arm64-msvc.node')
|
|
99
|
+
} else {
|
|
100
|
+
nativeBinding = require('@neko-net/rusty-enet-win32-arm64-msvc')
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
loadError = e
|
|
104
|
+
}
|
|
105
|
+
break
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
108
|
+
}
|
|
109
|
+
break
|
|
110
|
+
case 'darwin':
|
|
111
|
+
localFileExisted = existsSync(join(__dirname, 'rusty-enet.darwin-universal.node'))
|
|
112
|
+
try {
|
|
113
|
+
if (localFileExisted) {
|
|
114
|
+
nativeBinding = require('./rusty-enet.darwin-universal.node')
|
|
115
|
+
} else {
|
|
116
|
+
nativeBinding = require('@neko-net/rusty-enet-darwin-universal')
|
|
117
|
+
}
|
|
118
|
+
break
|
|
119
|
+
} catch {}
|
|
120
|
+
switch (arch) {
|
|
121
|
+
case 'x64':
|
|
122
|
+
localFileExisted = existsSync(join(__dirname, 'rusty-enet.darwin-x64.node'))
|
|
123
|
+
try {
|
|
124
|
+
if (localFileExisted) {
|
|
125
|
+
nativeBinding = require('./rusty-enet.darwin-x64.node')
|
|
126
|
+
} else {
|
|
127
|
+
nativeBinding = require('@neko-net/rusty-enet-darwin-x64')
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadError = e
|
|
131
|
+
}
|
|
132
|
+
break
|
|
133
|
+
case 'arm64':
|
|
134
|
+
localFileExisted = existsSync(
|
|
135
|
+
join(__dirname, 'rusty-enet.darwin-arm64.node')
|
|
136
|
+
)
|
|
137
|
+
try {
|
|
138
|
+
if (localFileExisted) {
|
|
139
|
+
nativeBinding = require('./rusty-enet.darwin-arm64.node')
|
|
140
|
+
} else {
|
|
141
|
+
nativeBinding = require('@neko-net/rusty-enet-darwin-arm64')
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
loadError = e
|
|
145
|
+
}
|
|
146
|
+
break
|
|
147
|
+
default:
|
|
148
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
149
|
+
}
|
|
150
|
+
break
|
|
151
|
+
case 'freebsd':
|
|
152
|
+
if (arch !== 'x64') {
|
|
153
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
|
154
|
+
}
|
|
155
|
+
localFileExisted = existsSync(join(__dirname, 'rusty-enet.freebsd-x64.node'))
|
|
156
|
+
try {
|
|
157
|
+
if (localFileExisted) {
|
|
158
|
+
nativeBinding = require('./rusty-enet.freebsd-x64.node')
|
|
159
|
+
} else {
|
|
160
|
+
nativeBinding = require('@neko-net/rusty-enet-freebsd-x64')
|
|
161
|
+
}
|
|
162
|
+
} catch (e) {
|
|
163
|
+
loadError = e
|
|
164
|
+
}
|
|
165
|
+
break
|
|
166
|
+
case 'linux':
|
|
167
|
+
switch (arch) {
|
|
168
|
+
case 'x64':
|
|
169
|
+
if (isMusl()) {
|
|
170
|
+
localFileExisted = existsSync(
|
|
171
|
+
join(__dirname, 'rusty-enet.linux-x64-musl.node')
|
|
172
|
+
)
|
|
173
|
+
try {
|
|
174
|
+
if (localFileExisted) {
|
|
175
|
+
nativeBinding = require('./rusty-enet.linux-x64-musl.node')
|
|
176
|
+
} else {
|
|
177
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-x64-musl')
|
|
178
|
+
}
|
|
179
|
+
} catch (e) {
|
|
180
|
+
loadError = e
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
localFileExisted = existsSync(
|
|
184
|
+
join(__dirname, 'rusty-enet.linux-x64-gnu.node')
|
|
185
|
+
)
|
|
186
|
+
try {
|
|
187
|
+
if (localFileExisted) {
|
|
188
|
+
nativeBinding = require('./rusty-enet.linux-x64-gnu.node')
|
|
189
|
+
} else {
|
|
190
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-x64-gnu')
|
|
191
|
+
}
|
|
192
|
+
} catch (e) {
|
|
193
|
+
loadError = e
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
break
|
|
197
|
+
case 'arm64':
|
|
198
|
+
if (isMusl()) {
|
|
199
|
+
localFileExisted = existsSync(
|
|
200
|
+
join(__dirname, 'rusty-enet.linux-arm64-musl.node')
|
|
201
|
+
)
|
|
202
|
+
try {
|
|
203
|
+
if (localFileExisted) {
|
|
204
|
+
nativeBinding = require('./rusty-enet.linux-arm64-musl.node')
|
|
205
|
+
} else {
|
|
206
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-arm64-musl')
|
|
207
|
+
}
|
|
208
|
+
} catch (e) {
|
|
209
|
+
loadError = e
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
localFileExisted = existsSync(
|
|
213
|
+
join(__dirname, 'rusty-enet.linux-arm64-gnu.node')
|
|
214
|
+
)
|
|
215
|
+
try {
|
|
216
|
+
if (localFileExisted) {
|
|
217
|
+
nativeBinding = require('./rusty-enet.linux-arm64-gnu.node')
|
|
218
|
+
} else {
|
|
219
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-arm64-gnu')
|
|
220
|
+
}
|
|
221
|
+
} catch (e) {
|
|
222
|
+
loadError = e
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
break
|
|
226
|
+
case 'arm':
|
|
227
|
+
if (isMusl()) {
|
|
228
|
+
localFileExisted = existsSync(
|
|
229
|
+
join(__dirname, 'rusty-enet.linux-arm-musleabihf.node')
|
|
230
|
+
)
|
|
231
|
+
try {
|
|
232
|
+
if (localFileExisted) {
|
|
233
|
+
nativeBinding = require('./rusty-enet.linux-arm-musleabihf.node')
|
|
234
|
+
} else {
|
|
235
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-arm-musleabihf')
|
|
236
|
+
}
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadError = e
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
localFileExisted = existsSync(
|
|
242
|
+
join(__dirname, 'rusty-enet.linux-arm-gnueabihf.node')
|
|
243
|
+
)
|
|
244
|
+
try {
|
|
245
|
+
if (localFileExisted) {
|
|
246
|
+
nativeBinding = require('./rusty-enet.linux-arm-gnueabihf.node')
|
|
247
|
+
} else {
|
|
248
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-arm-gnueabihf')
|
|
249
|
+
}
|
|
250
|
+
} catch (e) {
|
|
251
|
+
loadError = e
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
break
|
|
255
|
+
case 'riscv64':
|
|
256
|
+
if (isMusl()) {
|
|
257
|
+
localFileExisted = existsSync(
|
|
258
|
+
join(__dirname, 'rusty-enet.linux-riscv64-musl.node')
|
|
259
|
+
)
|
|
260
|
+
try {
|
|
261
|
+
if (localFileExisted) {
|
|
262
|
+
nativeBinding = require('./rusty-enet.linux-riscv64-musl.node')
|
|
263
|
+
} else {
|
|
264
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-riscv64-musl')
|
|
265
|
+
}
|
|
266
|
+
} catch (e) {
|
|
267
|
+
loadError = e
|
|
268
|
+
}
|
|
269
|
+
} else {
|
|
270
|
+
localFileExisted = existsSync(
|
|
271
|
+
join(__dirname, 'rusty-enet.linux-riscv64-gnu.node')
|
|
272
|
+
)
|
|
273
|
+
try {
|
|
274
|
+
if (localFileExisted) {
|
|
275
|
+
nativeBinding = require('./rusty-enet.linux-riscv64-gnu.node')
|
|
276
|
+
} else {
|
|
277
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-riscv64-gnu')
|
|
278
|
+
}
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadError = e
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
break
|
|
284
|
+
case 's390x':
|
|
285
|
+
localFileExisted = existsSync(
|
|
286
|
+
join(__dirname, 'rusty-enet.linux-s390x-gnu.node')
|
|
287
|
+
)
|
|
288
|
+
try {
|
|
289
|
+
if (localFileExisted) {
|
|
290
|
+
nativeBinding = require('./rusty-enet.linux-s390x-gnu.node')
|
|
291
|
+
} else {
|
|
292
|
+
nativeBinding = require('@neko-net/rusty-enet-linux-s390x-gnu')
|
|
293
|
+
}
|
|
294
|
+
} catch (e) {
|
|
295
|
+
loadError = e
|
|
296
|
+
}
|
|
297
|
+
break
|
|
298
|
+
default:
|
|
299
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
300
|
+
}
|
|
301
|
+
break
|
|
302
|
+
default:
|
|
303
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!nativeBinding) {
|
|
307
|
+
if (loadError) {
|
|
308
|
+
throw loadError
|
|
309
|
+
}
|
|
310
|
+
throw new Error(`Failed to load native binding`)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const { PacketKind, EventType, PeerState, EnetHost } = nativeBinding
|
|
314
|
+
|
|
315
|
+
module.exports.PacketKind = PacketKind
|
|
316
|
+
module.exports.EventType = EventType
|
|
317
|
+
module.exports.PeerState = PeerState
|
|
318
|
+
module.exports.EnetHost = EnetHost
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neko-net/rusty-enet",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+ssh://git@github.com/neko-net/rusty_enet_napi.git"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"index.js",
|
|
13
|
+
"index.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"napi": {
|
|
16
|
+
"name": "rusty-enet",
|
|
17
|
+
"triples": {
|
|
18
|
+
"defaults": false,
|
|
19
|
+
"additional": [
|
|
20
|
+
"x86_64-unknown-linux-gnu",
|
|
21
|
+
"aarch64-unknown-linux-gnu",
|
|
22
|
+
"x86_64-pc-windows-msvc",
|
|
23
|
+
"aarch64-pc-windows-msvc",
|
|
24
|
+
"aarch64-apple-darwin"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "napi build --release",
|
|
30
|
+
"build:debug": "napi build",
|
|
31
|
+
"test": "node --test tests/*.test.js",
|
|
32
|
+
"artifacts": "napi artifacts"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@napi-rs/cli": "^2.18.4"
|
|
36
|
+
},
|
|
37
|
+
"optionalDependencies": {
|
|
38
|
+
"@neko-net/rusty-enet-linux-x64-gnu": "0.1.3",
|
|
39
|
+
"@neko-net/rusty-enet-linux-arm64-gnu": "0.1.3",
|
|
40
|
+
"@neko-net/rusty-enet-win32-x64-msvc": "0.1.3",
|
|
41
|
+
"@neko-net/rusty-enet-win32-arm64-msvc": "0.1.3",
|
|
42
|
+
"@neko-net/rusty-enet-darwin-arm64": "0.1.3"
|
|
43
|
+
}
|
|
44
|
+
}
|