• Stars
    star
    131
  • Rank 270,308 (Top 6 %)
  • Language
    Dart
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pure Dart Client for Nakama Server

Nakama Dart/Flutter Client

Nakama is an open-source server designed to power modern games and apps. Features include user accounts, chat, social, matchmaker, realtime multiplayer, and much more.

This is a Flutter client for Nakama written in pure Dart and supports cross platform gaming on iOS, Android, Web and more.

GitHub issues GitHub last commit Pub Version


🚀 Getting Started

You'll need to setup the server and database before you can connect with the client. The simplest way is to use Docker but have a look at the server documentation for other options.

Installing the SDK

  1. To use an official release, download source from the releases page and import it into your project.

  2. Add flutter_nakama to your pubspec.yaml:

name: your_game
dependencies:
    flutter:
        sdk: flutter
    nakama: ^1.0.0-dev.6
  1. Use the connection credentials to build a client object:
final client = getNakamaClient(
  host: '127.0.0.1',
  ssl: false,
  serverKey: 'defaultkey',
  grpcPort: 7349, // optional
  httpPort: 7350, // optional
);

Usage

The client object has many methods to execute various features in the server or open realtime socket connections with the server.

Authenticate

There's a variety of ways to authenticate with the server. Authentication can create a user if they don't already exist with those credentials. It's also easy to authenticate with a social profile from Google Play Games, Facebook, Game Center, etc.

final session = await getNakamaClient().authenticateEmail(
    email: '[email protected]',
    password: 'mySecurePassword!',
);

print('Hey, you are logged in! UserID: ${session.userId}');

Sessions

When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a Session object.

session.AuthToken // raw JWT token
session.UserId // User ID
session.Username // Username
session.IsExpired // Boolean indicating session status
session.ExpireTime // in seconds.

It is recommended to store the auth token from the session and check at startup if it has expired. If the token has expired you must reauthenticate. The expiry time of the token can be changed as a setting in the server.

final inOneHour = DateTime.now().add(Duration(hours: 1));

// Check whether a session has expired or is close to expiry.
if (session.isExpired || session.hasExpired(inOneHour)) {
    try {
        // Attempt to refresh the existing session.
        session = await client.sessionRefresh(session);
    } catch (e) {
        // Couldn't refresh the session so reauthenticate.
        session = await client.authenticateDevice(deviceId: deviceId);
    }
}

Requests

The client includes lots of builtin APIs for various features of the game server. These can be accessed with the async methods. It can also call custom logic as RPC functions on the server. These can also be executed with a socket object.

All requests are sent with a session object which authorizes the client.

final account = await client.getAccount(session);
final username = account.user.username;
final avatarUrl = account.user.avatarUrl;
final userId = account.user.id;

Socket

The client can create one or more sockets with the server. Each socket can have it's own event listeners registered for responses received from the server.

NakamaWebsocketClient.init(
    host: '127.0.0.1',
    ssl: false,
    token: _session.token,
);

Remember to close the connection after disposing of the app widget:

NakamaWebsocketClient.instance.close();

Documentation

Dart/Flutter SDK Docs: https://heroiclabs.com/docs/nakama/client-libraries/dart/

Nakama Docs: https://heroiclabs.com/docs/nakama/

Special Thanks

Thanks to Oliver Brunsmann (@obrunsmann) for his excellent contribution and maintenance of this library.

More Repositories

1

nakama

Distributed server for social and realtime games and apps.
Go
7,860
star
2

nakama-godot

Godot client for Nakama server written in GDScript.
GDScript
510
star
3

nakama-unity

Unity client for Nakama server.
C#
363
star
4

nakama-godot-demo

A demo project with Godot engine and Nakama server.
GDScript
265
star
5

fishgame-godot

"Fish Game" for Godot is a 2-4 player online multiplayer game created as a demo of Nakama; an open-source scalable game server, using the Godot game engine.
GDScript
205
star
6

nakama-unreal

Unreal client for Nakama server.
C++
171
star
7

nakama-js

JavaScript client for Nakama server written in TypeScript.
TypeScript
164
star
8

fishgame-macroquad

"Fish Game" for Macroquad is an online multiplayer game, created as a demonstration of Nakama, an open-source scalable game server, using Rust-lang and the Macroquad game engine.
Rust
136
star
9

unity-sampleproject

A sample game called Pirate Panic for Unity engine built with Nakama server.
C#
132
star
10

nakama-dotnet

.NET client for Nakama server written in C#.
C#
99
star
11

nakama-project-template

An example project on how to set up and write custom server code in Nakama server.
Go
81
star
12

nakama-defold

Defold client for Nakama server.
Lua
74
star
13

nakama-cpp

Generic C/C++ client for Nakama server.
C++
67
star
14

nakama-rs

Rust
65
star
15

nakama-common

The runtime framework for Nakama server.
Go
44
star
16

nakama-docs

Documentation for Nakama social and realtime server.
Shell
43
star
17

fishgame-unity

"Fish Game" for Unity is a 2-4 player online multiplayer game created as a demo of Nakama; an open-source scalable game server, using the Unity game engine.
C#
43
star
18

nakama-java

Java client for the Nakama and Satori servers.
Java
29
star
19

nakama-cocos2d-x

Cocos2d-x client for Nakama server.
C++
27
star
20

nakama-examples

A mono repo with project examples for the Nakama client libraries.
C#
24
star
21

nakama-swift

Swift client for Nakama server.
Swift
24
star
22

pulse

Service registration and discovery library for Elixir. Relies on etcd as an external service registry.
Elixir
16
star
23

hiro

The server interface for the Hiro game framework.
Go
14
star
24

sonic

etcd library and bindings for Elixir.
Elixir
10
star
25

nakama-cocos2d-x-javascript

Cocos2d-x client for Nakama server written in JavaScript
JavaScript
7
star
26

reconstructing-fun

C#
6
star
27

xoxo-phaserjs

JavaScript
5
star