Create proxies for Minecraft
Install the package:
$ npm install @minecraft-js/proxiesAnd then import it in your JavaScript/TypeScript file
constProxies=require('@minecraft-js/proxies');// CommonJSimport*asProxiesfrom'@minecraft-js/proxies';// ES6Read only proxies are proxies where you can only read packets. Create a read only proxy like so
constproxy=newProxies.ReadOnlyProxy({serverHostname: 'localhost',// Target server hostnameport: 8080,// Proxy port});And then you can use the ReadOnlyProxy#on method to listen for different events:
raw_listening- When the TCP server is listeningraw_connect- When a client opens a connectionraw_disconnect- When a client closes a connectionraw_close- When the TCP server is closederror- When an error occursoutgoing_data- When data is sent to the target serverincoming_data- When data is received from the target server
If you are using TypeScript or you want type checking make sure to install the typed-emitter package!
$ npm install typed-emitter