-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add js client to demonstrate transaction receipts
- Loading branch information
Showing
7 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,3 +113,6 @@ $RECYCLE.BIN/ | |
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
# Node modules | ||
/jsclient/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
This is a simple js client that demonstrates transaction receipts. | ||
|
||
after run `mage start` in the parent directory (to start cardinal and nakama), run: | ||
|
||
` | ||
npm install | ||
node main.mjs | ||
` | ||
|
||
The js client will attempt to join the singleton match and then will print any transaciton receipts that cardinal generates. | ||
|
||
Transactions can be sent in via the Nakama API Explorer (localhost:7351/#/apiexplorer) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {Client} from '@heroiclabs/nakama-js'; | ||
import {WebSocket} from 'ws'; | ||
Object.assign(global, { WebSocket: WebSocket }); | ||
|
||
console.log(WebSocket); | ||
|
||
var client = new Client("defaultkey", "127.0.0.1", 7350); | ||
|
||
console.log(client); | ||
|
||
var randomString = function() { | ||
let str = "" | ||
for (let i = 0; i < 13; i++) { | ||
str += Math.floor(10 * Math.random()) | ||
} | ||
return str | ||
} | ||
|
||
var device_id = randomString(); | ||
var username = device_id; | ||
|
||
var create = true | ||
var session = await client.authenticateDevice(device_id, create, username) | ||
console.log("auth success", session); | ||
|
||
const account = await client.getAccount(session); | ||
console.log("account is", account) | ||
|
||
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); | ||
}; | ||
|
||
var appearOnline = true | ||
session = await socket.connect(session, appearOnline); | ||
|
||
console.log("session is", session) | ||
|
||
let result = await client.listMatches(session) | ||
|
||
let dec = new TextDecoder() | ||
socket.onmatchdata = (result) => { | ||
console.log("tx receipt: ", dec.decode(result.data)); | ||
} | ||
|
||
let match_id = result.matches[0].match_id | ||
let match = await socket.joinMatch(match_id) | ||
console.log("i joined the match: ", match) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "module", | ||
"dependencies": { | ||
"@heroiclabs/nakama-js": "^2.6.1", | ||
"ws": "^8.13.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Arguments: | ||
/opt/homebrew/Cellar/node/20.3.0/bin/node /opt/homebrew/Cellar/yarn/1.22.19/libexec/bin/yarn.js add @herioclabs/nakama-js | ||
|
||
PATH: | ||
/opt/homebrew/Cellar/go/1.20.3/libexec/bin:/Users/jer/go/bin:/Users/jer/go/bin/:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Applications/Wireshark.app/Contents/MacOS:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/jer/.foundry/bin | ||
|
||
Yarn version: | ||
1.22.19 | ||
|
||
Node version: | ||
20.3.0 | ||
|
||
Platform: | ||
darwin arm64 | ||
|
||
Trace: | ||
Error: https://registry.yarnpkg.com/@herioclabs%2fnakama-js: Not found | ||
at params.callback [as _callback] (/opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js:66145:18) | ||
at self.callback (/opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js:140890:22) | ||
at Request.emit (node:events:511:28) | ||
at Request.<anonymous> (/opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js:141862:10) | ||
at Request.emit (node:events:511:28) | ||
at IncomingMessage.<anonymous> (/opt/homebrew/Cellar/yarn/1.22.19/libexec/lib/cli.js:141784:12) | ||
at Object.onceWrapper (node:events:625:28) | ||
at IncomingMessage.emit (node:events:523:35) | ||
at endReadableNT (node:internal/streams/readable:1367:12) | ||
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) | ||
|
||
npm manifest: | ||
No manifest | ||
|
||
yarn manifest: | ||
No manifest | ||
|
||
Lockfile: | ||
No lockfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@heroiclabs/nakama-js@^2.6.1": | ||
version "2.6.1" | ||
resolved "https://registry.npmjs.org/@heroiclabs/nakama-js/-/nakama-js-2.6.1.tgz" | ||
integrity sha512-akuHr42rUdKGli0un6+ok7HDC2KarHs3lGRF1pIn5Mc7ALRZ46Cnx0kRX7jqj4mj5FuMD5wBtIY8CEcJGP+Oaw== | ||
dependencies: | ||
"@scarf/scarf" "^1.1.1" | ||
base64-arraybuffer "^1.0.2" | ||
js-base64 "^3.7.4" | ||
whatwg-fetch "^3.6.2" | ||
|
||
"@scarf/scarf@^1.1.1": | ||
version "1.1.1" | ||
resolved "https://registry.npmjs.org/@scarf/scarf/-/scarf-1.1.1.tgz" | ||
integrity sha512-VGbKDbk1RFIaSmdVb0cNjjWJoRWRI/Weo23AjRCC2nryO0iAS8pzsToJfPVPtVs74WHw4L1UTADNdIYRLkirZQ== | ||
|
||
base64-arraybuffer@^1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-1.0.2.tgz" | ||
integrity sha512-I3yl4r9QB5ZRY3XuJVEPfc2XhZO6YweFPI+UovAzn+8/hb3oJ6lnysaFcjVpkCPfVWFUDvoZ8kmVDP7WyRtYtQ== | ||
|
||
js-base64@^3.7.4: | ||
version "3.7.5" | ||
resolved "https://registry.npmjs.org/js-base64/-/js-base64-3.7.5.tgz" | ||
integrity sha512-3MEt5DTINKqfScXKfJFrRbxkrnk2AxPWGBL/ycjz4dK8iqiSJ06UxD8jh8xuh6p10TX4t2+7FsBYVxxQbMg+qA== | ||
|
||
whatwg-fetch@^3.6.2: | ||
version "3.6.17" | ||
resolved "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.17.tgz" | ||
integrity sha512-c4ghIvG6th0eudYwKZY5keb81wtFz9/WeAHAoy8+r18kcWlitUIrmGFQ2rWEl4UCKUilD3zCLHOIPheHx5ypRQ== | ||
|
||
ws@^8.13.0: | ||
version "8.13.0" | ||
resolved "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz" | ||
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== |