@heroiclabs/nakama-js
Advanced tools
Comparing version 0.4.0 to 2.0.0
@@ -6,2 +6,12 @@ # Change Log | ||
## [2.0.0] - 2018-05-14 | ||
### Added | ||
- New browser headless test suite with Puppeteer. | ||
### Changed | ||
- All source code now written in TypeScript. | ||
- Rewrite client and socket model for Nakama 2.0. | ||
--- | ||
## [0.4.0] - 2018-02-02 | ||
@@ -8,0 +18,0 @@ ### Changed |
{ | ||
"name": "@heroiclabs/nakama-js", | ||
"version": "0.4.0", | ||
"description": "JavaScript client for Nakama server.", | ||
"version": "2.0.0", | ||
"description": "JavaScript client for Nakama server written in TypeScript.", | ||
"keywords": [ | ||
"app server", | ||
"client library", | ||
"game server", | ||
"nakama", | ||
"realtime", | ||
"realtime chat", | ||
"nakama", | ||
"game server" | ||
"realtime chat" | ||
], | ||
@@ -14,8 +16,6 @@ "homepage": "https://heroiclabs.com", | ||
"main": "dist/nakama-js.cjs.js", | ||
"types": "dist/index.d.ts", | ||
"module": "dist/nakama-js.esm.js", | ||
"browser": "dist/nakama-js.umd.js", | ||
"repository": { | ||
"url": "https://github.com/heroiclabs/nakama-js", | ||
"type": "git" | ||
}, | ||
"repository": "https://github.com/heroiclabs/nakama-js", | ||
"author": "Chris Molozian <chris@heroiclabs.com>", | ||
@@ -28,22 +28,27 @@ "contributors": [ | ||
"private": false, | ||
"dependencies": { | ||
"base-64": "^0.1.0", | ||
"whatwg-fetch": "^2.0.3" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"rollup": "^0.50.0", | ||
"rollup-plugin-babel": "^3.0.2", | ||
"rollup-plugin-commonjs": "^8.2.4", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-root-import": "^0.2.2" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w" | ||
"dev": "rollup -c -w", | ||
"test": "jest" | ||
}, | ||
"files": [ | ||
"dist" | ||
] | ||
"dist", | ||
"src" | ||
], | ||
"devDependencies": { | ||
"chalk": "^2.3.0", | ||
"jest": "^22.1.4", | ||
"jest-environment-node": "^22.1.4", | ||
"mkdirp": "^0.5.1", | ||
"puppeteer": "^1.0.0", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.55.1", | ||
"rollup-plugin-typescript2": "^0.10.0", | ||
"typedoc": "^0.10.0", | ||
"typescript": "^2.6.2" | ||
}, | ||
"dependencies": { | ||
"Base64": "^1.0.1", | ||
"whatwg-fetch": "^2.0.3" | ||
} | ||
} |
149
README.md
@@ -1,53 +0,156 @@ | ||
Nakama JS | ||
========= | ||
Nakama JavaScript client | ||
======================== | ||
> JavaScript client for Nakama server. For browser and React Native projects. | ||
> JavaScript client for Nakama server written in TypeScript. For browser and React Native projects. | ||
Nakama is an [open-source](https://github.com/heroiclabs/nakama) distributed server for social and realtime games and apps. For more information have a look at the [documentation](https://heroiclabs.com/docs/). | ||
[Nakama](https://github.com/heroiclabs/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](https://heroiclabs.com). | ||
This client implements the protocol and all features available in the server. It is compatible with modern browsers (supporting ES5) and React Native. If you experience any issues with the client, it can be useful to [enable trace](https://heroiclabs.com/docs/javascript-client-guide/#logs-and-errors) to produce detailed logs and [open an issue](https://github.com/heroiclabs/nakama-js/issues). | ||
This client implements the full API and socket options with the server. It's written in TypeScript with minimal dependencies to be compatible with all modern browsers and React Native. | ||
Full documentation is online - https://heroiclabs.com/docs/javascript-client-guide | ||
## 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](https://github.com/heroiclabs/nakama#getting-started) for other options. | ||
1. Install and run the servers. Follow these [instructions](https://heroiclabs.com/docs/install-docker-quickstart). | ||
2. Import the client into your project. It's available on NPM and can be also be added to a project with Bower or other package managers. | ||
```shell | ||
yarn add "@heroiclabs/nakama-js" | ||
``` | ||
You'll now see the code in the "node_modules" folder and package listed in your "package.json". | ||
3. Use the connection credentials to build a client object. | ||
```js | ||
// <script src="path/to/nakama-js.umd.js"></script> | ||
var client = new nakamajs.Client("defaultkey", "127.0.0.1", 7350); | ||
client.ssl = false; // enable if server is run with an SSL certificate | ||
``` | ||
## Usage | ||
You can add the client to your project with `yarn add @heroiclabs/nakama-js`. This will add the dependency to your `package.json`. You can also use NPM or Bower to download and add the dependency to your project. | ||
The client object has many methods to execute various features in the server and also create sockets to open connections with the server. | ||
We have a guide which covers how to use the client with lots of code examples: | ||
### Authenticate | ||
https://heroiclabs.com/docs/javascript-client-guide/ | ||
There's a variety of ways to [authenticate](https://heroiclabs.com/docs/authentication) 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. | ||
To create a client which can connect to the Nakama server in a webpage with UMD imports and default connection settings: | ||
```js | ||
var email = "super@heroes.com"; | ||
var password = "batsignal"; | ||
const session = await client.authenticateEmail({ email: email, password: password }); | ||
console.info(session); | ||
``` | ||
```html | ||
<script src="path/to/dist/nakama-js.umd.js"></script> | ||
### Sessions | ||
When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a `Session` object. | ||
```js | ||
console.info(session.token); // raw JWT token | ||
console.info(session.userId); | ||
console.info(session.username); | ||
console.info("Session has expired?", session.isexpired(Date.now() / 1000)); | ||
const expiresat = session.expires_at; | ||
console.warn("Session will expire at", new Date(expiresat * 1000).toISOString()); | ||
``` | ||
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. | ||
```js | ||
var client = new nakamajs.Client("defaultkey", "127.0.0.1", 7350); | ||
client.ssl = false; | ||
// Assume we've stored the auth token in browser Web Storage. | ||
const authtoken = window.localStorage.getItem("nkauthtoken"); | ||
const session = nakamajs.Session.restore(authtoken); | ||
if (session.isexpired(Date.now() / 1000)) { | ||
console.warn("Session has expired. Must reauthenticate."); | ||
} | ||
``` | ||
### Requests | ||
The client includes lots of builtin APIs for various features of the game server. These can be accessed with the methods which return Promise objects. It is also possible to call RPC functions for custom logic registered with the server as well as with a socket object. | ||
All requests are sent with a session object which authorizes the client. | ||
```js | ||
const account = await client.getAccount(session); | ||
console.info(account.user.id); | ||
console.info(account.user.username); | ||
console.info(account.wallet); | ||
``` | ||
### 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. | ||
```js | ||
const secure = false; // enable if server is run with an SSL certificate | ||
const trace = false; | ||
const socket = client.createSocket(secure, trace); | ||
socket.ondisconnect = (evt) => { | ||
console.info("Disconnected", evt); | ||
}; | ||
const session = await socket.connect(session); | ||
// Socket is open. | ||
``` | ||
There's many messages for chat, realtime, status events, notifications, etc. which can be sent or received from the socket. | ||
```js | ||
socket.onchannelmessage = (message) => { | ||
console.info("Message received from channel", message.channel_id); | ||
console.info("Received message", message); | ||
}; | ||
const roomname = "mychannel"; | ||
const channel = await socket.send({ channel_join: { | ||
type: 1, // 1 = room, 2 = Direct Message, 3 = Group | ||
target: roomname, | ||
persistence: false, | ||
hidden: false | ||
} }); | ||
const message = { "hello": "world" }; | ||
socket.send({ channel_message_send: { | ||
channel_id: channel.channel.id, | ||
content: message | ||
} }); | ||
``` | ||
## Contribute | ||
To build the codebase simply run the following to install the dependencies: | ||
The development roadmap is managed as GitHub issues and pull requests are welcome. If you're interested to enhance the code please open an issue to discuss the changes or drop in and discuss it in the [community chat](https://gitter.im/heroiclabs/nakama). | ||
### Source Builds | ||
The codebase is written in TypeScript with tests in JavaScript and can be built with [Rollup.js](https://rollupjs.org/guide/en). All dependencies are managed with NPM. | ||
```shell | ||
$> yarn install | ||
yarn install && yarn build | ||
``` | ||
## Development | ||
### Run Tests | ||
To run tests you will need to run the server and database. Most tests are written as integration tests which execute against the server. A quick approach we use with our test workflow is to use the Docker compose file described in the [documentation](https://heroiclabs.com/docs/install-docker-quickstart). | ||
```shell | ||
$> yarn run dev | ||
docker-compose -f ./docker-compose.yml up | ||
yarn build && yarn test | ||
``` | ||
## Production builds | ||
### Release Process | ||
To release onto NPM if you have access to the "@heroiclabs" organization you can use Yarn. | ||
```shell | ||
$> yarn run build | ||
yarn run build && yarn publish --access=public | ||
``` | ||
## For releases | ||
### License | ||
```shell | ||
$> yarn run build && yarn publish --access=public | ||
``` | ||
This project is licensed under the [Apache-2 License](https://github.com/heroiclabs/nakama-js/blob/master/LICENSE). |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
815200
18
18336
0
157
10
1
187
+ AddedBase64@^1.0.1
+ AddedBase64@1.3.0(transitive)
- Removedbase-64@^0.1.0
- Removedbase-64@0.1.0(transitive)