Skip to content

Commit

Permalink
Update js runtime TS definitions (#48)
Browse files Browse the repository at this point in the history
Introduce JS runtime stringToBinary and binaryToString functions.
Change JS runtime match message data from string to Uint8Array.
  • Loading branch information
sesposito authored Dec 13, 2021
1 parent e47c06d commit 692589b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr

## [Unreleased]
### Added
- Add ctx field to access http request headers in the runtimes.
- Add ctx field to access http request headers in the runtimes.
- New JS runtime stringToBinary and binaryToString functions.

### Changed
- JS runtime match data changed to Uint8Array.

## [1.20.0] - 2021-10-29
### Added
Expand Down
22 changes: 19 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ declare namespace nkruntime {
* @param reliable - Opt. Broadcast the message with delivery guarantees or not. Defaults to true.
* @throws {TypeError, GoError}
*/
broadcastMessage(opcode: number, data?: string | null, presences?: Presence[] | null, sender?: Presence | null, reliable?: boolean): void;
broadcastMessage(opcode: number, data?: Uint8Array | string | null, presences?: Presence[] | null, sender?: Presence | null, reliable?: boolean): void;

/**
* Defer message broadcast to match presences.
Expand All @@ -251,7 +251,7 @@ declare namespace nkruntime {
* @param reliable - Opt. Broadcast the message with delivery guarantees or not. Defaults to true.
* @throws {TypeError, GoError}
*/
broadcastMessageDeferred(opcode: number, data?: string | null, presences?: Presence[] | null, sender?: Presence, reliable?: boolean): void;
broadcastMessageDeferred(opcode: number, data?: Uint8Array | string | null, presences?: Presence[] | null, sender?: Presence, reliable?: boolean): void;

/**
* Kick presences from match.
Expand Down Expand Up @@ -280,7 +280,7 @@ declare namespace nkruntime {
persistence: boolean;
status: string;
opCode: number;
data: string;
data: Uint8Array;
reliable: boolean;
receiveTime: number;
}
Expand Down Expand Up @@ -2790,6 +2790,22 @@ declare namespace nkruntime {
* The server APIs available in the game server.
*/
export interface Nakama {
/**
* Convert binary data to string.
*
* @param data - Data to convert to string.
* @throws {TypeError}
*/
binaryToString(data: Uint8Array): string;

/**
* Convert a string to binary data.
*
* @param str - String to convert to binary data.
* @throws {TypeError}
*/
stringToBinary(str: string): Uint8Array;

/**
* Emit an event to be processed.
*
Expand Down

0 comments on commit 692589b

Please sign in to comment.