GithubHelp home page GithubHelp logo

zentyk / pc.nakama Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 6 KB

playcanvas engine-only multiplayer game demo.

License: Do What The F*ck You Want To Public License

JavaScript 96.21% TypeScript 3.79%

pc.nakama's Introduction

pc.nakama

A heroic labs - nakama js wrapper for playcanvas game engine.

First Steps

you don't need to import the nakama-js.umd.js file, this wrapper uses the 2.1.5 version inside

variables:

  • 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

Use the playcanvas.js engine-only solution

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>

Use production-ready jsdelivr minified file

<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>

Use inside playcanvas editor script:

  1. 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.

  2. uncheck the 'preload' option in the file editor options.

  3. 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

pc.nakama's People

Contributors

zentyk avatar

Stargazers

 avatar

Watchers

 avatar

pc.nakama's Issues

Module not recognized

Hi, @zentyk ! I tried the 3rd method "Use inside playcanvas editor script" and I have the following error :

ReferenceError: NakamaJs is not defined

What can I do to fix it ?

Thanks a lot for answers !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.