A heroic labs - nakama js wrapper for playcanvas game engine.
you don't need to import the nakama-js.umd.js file, this wrapper uses the 2.1.5 version inside
-
server_ip : your nakama server ip
-
nakama_port : your nakama server port (by default is 443 when using SSL connection)
-
useSSL : this is a bool, use true if your server uses HTTPS.
This nakama wrapper uses only custom authentication, other auth methods will be supported in further updates.
-
customId : the user's customId
-
clientUsername : the user's username
This wrapper executes this options automaticaly:
- Auto-import of the nakama.js client
- Creates the client
- CheckSession and Authenticate your users
- Establish the socket connection
- Retrieve and Update the oponents list without process the match-presence events.
For more information about Custom Authentication see the documentation
Import the library like any ES6 module in your html file.
<script type="module">
import NakamaJs from "./pc-nakama.js";
var nakama = new NakamaJs(<server_ip>, <nakama_port>,<useSSL>, <customId>, <clientUsername>);
</script>
<script type="module">
import NakamaJs from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/prod/pc-nakama.min.js';
var nk = new NakamaJs("192.168.100.1","443",true,"123","gamedev.js");
nk.initiate();
</script>
-
Import the file in the editor, don't drop the file into the editor the drop option doesn't load well the file, instead use the 'upload' option.
-
uncheck the 'preload' option in the file editor options.
-
you can create an empty script, attach the script as the first in the 'script loading order', don't attach it to a component or entity
var module;
(function() {
var asset = pc.Application.getApplication().assets.find('pc-nakama.min.js');
async function load() {
module = await import(asset.getFileUrl());
var nakama = new NakamaJs(<server_ip>, <nakama_port>,<useSSL>, <customId>, <clientUsername>);
}
load();
})();
To create a tunel in ngrok
ngrok start --config ./ngrok.yml --all