-
Notifications
You must be signed in to change notification settings - Fork 8
Extension base
WiredSpast edited this page Feb 20, 2022
·
4 revisions
G-Node is written using ES modules, so the easiest way to use G-Node in your project is create your project as an ES module itself. To do so follow the following steps.
- Open the
package.jsonfile, it should now look somewhat like this:
{
"name": "extensionname",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"gnode-api": "^0.2.1"
}
}- Add in `"type": "module", somewhere at base level in to the file, for example:
{
"name": "extensionname",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"gnode-api": "^0.2.1"
}
}In Node.js you can use a package installed with npm as a library in the following way:
import * as GNode from 'gnode-api';You can access a component in the following way:
GNode.Extension
GNode.HPacketimport { Extension, HPacket } from 'gnode-api';const extensionInfo = {
name: "My Extension",
description: "My first G-Node extension",
version: "0.1",
author: "Your name"
}const ext = new Extension(extensionInfo);
ext.run();
At this point your javascript file should look something like this
import { Extension, HPacket } from 'gnode-api';
const extensionInfo = {
name: "My Extension",
description: "My first G-Node extension",
version: "0.1",
author: "Your name"
}
let ext = new Extension(extensionInfo);
ext.run();This current script allows you to connect to G-Earth if you run it with the following command
$ node [filename] -p [port]
Example:
$ node index.js -p 9092
Read the other wiki pages to learn how to intercept packets or create and send packets