-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbinding.js
33 lines (29 loc) · 1.1 KB
/
binding.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const helper = require('./helpers/buildPath.js')
const fs = require('fs')
const debug = require('debug')('raknet')
if (!process.versions.electron) {
// Electron has its own crash handler, and segfault-handler
// uses NAN which is a hassle, so only load outside electron
// Note: Need to be using debug release to make use of this! Run `npm run clean` then `npm test` to get a debug build
try {
const SegfaultHandler = require('segfault-handler')
SegfaultHandler.registerHandler('crash.log')
} catch (e) {
debug('[raknet] segfault handler is not installed. If you run into crashing issues, install it with `npm i -D segfault-handler` to get debug info on native crashes')
}
}
let bindings
const pathsToSearch = [helper.getPath(), helper.getFallbackPath()]
for (const importPath of pathsToSearch) {
try {
bindings = require(importPath)
} catch (e) {
debug("Didn't find in", importPath)
debug(e)
}
}
// We want to use the built release if available
if (!bindings || fs.existsSync('./build/Release')) {
bindings = require('bindings')('node-raknet.node')
}
module.exports = bindings