Skip to content

Getting Started

Dominique Debergue edited this page Jul 29, 2019 · 6 revisions

📘 Set-Up

Disclaimer: I do not have experience using Node or React, so the only method of installation listed for now will be embedding the script to an HTML document. If you have experience using Node, React, or any other JavaScript libraries, contributions to the Wiki (and installation/manifest files for the given JS library you use) are greatly appreciated and will help a lot of people!

Embed to HTML document

If you haven't done so already, download the gopher-client.js script from the project's src folder. If you wish to use the voice chat features, you will need to download the gopher-voice.js script as well. Optionally, you can use the minified scripts from the project's src/min folder.

Now we can use these scripts in an HTML document by putting the following lines into the <head>:

    <head>
        
        <script type="text/javascript" src="gopher-client.js"></script>
        <script type="text/javascript" src="gopher-voice.js"></script>
        
    </head>

It's important to make sure your own scripts wait for the page to load before using the Gopher client API, otherwise you will get JavaScript errors while loading. A simple example:

// Make a "loaded" listener
window.onload = init;

// Start using the Gopher client API only after page loads
function init(e){
	// ...
}

📘 Connecting to the Server

The Gopher client API is exposed with the global variable gopherClient. The gopherClient variable is a prototype instance of GopherServerClient. Using the gopherClient global variable and the window load listener from above, we can tell the API to connect to the server with the connect() function:

// Make a "loaded" listener
window.onload = init;

// Start using the Gopher client API only after page loads
function init(e){
	// Connect to the server
	gopherClient.connect("localhost", 8080, false);
}

The gopherClient.connect() function takes three parameters: ip (string), port (integer), and ssl (boolean). ip is the IP address of the Gopher Server currently running, port is the port that the Gopher server is currently running on, and ssl is a boolean that connects to the server with TLS if Gopher has TLS enabled in the core server settings (enabling example is in this section of the server wiki).

Connect/Disconnect Event Listeners

You can make event listeners for when the API connects and disconnects from the server with the events.connected and events.disconnected listeners:

function init(e){
	// Set connect/disconnect event listeners
	gopherClient.addEventListener(gopherClient.events.connected, connected);
	gopherClient.addEventListener(gopherClient.events.disconnected, disconnected);

	// Connect to the server
	gopherClient.connect("localhost", 8080, false);
}

function connected(){
	console.log("Connected to server successfully");
}

function disconnected(){
	console.log("Disconnected from server");
}

If you notice there is lacking information, missing features, or bad explanations, please open an issue. All requests are acceptable and will be taken into consideration, so don't be afraid to ask or report something!

Clone this wiki locally