generated from GamingAPI/template-api-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b518b78
commit 375ba47
Showing
17 changed files
with
1,011 additions
and
193 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
<h1 align="center">TypeScript/Node.js NATS client wrapper</h1> | ||
<p align="center"> | ||
<em>This is a generated TypeScript/Node.js NATS client for the application - Rust public API.</em> | ||
</p> | ||
|
||
**We highly recommend you do not modify this client in any way since it is build for you to re-generate it when your AsyncAPI document changes.** | ||
|
||
test | ||
|
||
You can find the general information about the different aspects of this library by checking [the documentation folder](./docs/general.md). | ||
|
||
An [API document](./API.md) have also been generated which contains all the possible configurations and usages this client supports. | ||
|
||
## Example | ||
```ts | ||
import * as GeneratedClient from "./nats-client"; | ||
const natsClient = new GeneratedClient.NatsAsyncApiClient(); | ||
natsClient.connect(...).catch((e) => {}); | ||
``` | ||
|
||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"template_last_version": "0.5.15", | ||
"document_last_version": "0.1.0" | ||
"template_last_version": "0.5.21", | ||
"document_last_version": "0.4.0" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
src/channels/V0RustServersServerIdEventsPlayerSteamIdChatted.ts
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,62 @@ | ||
import ChatMessage from '../models/ChatMessage'; | ||
import * as Nats from 'nats'; | ||
import { | ||
ErrorCode, | ||
NatsTypescriptTemplateError | ||
} from '../NatsTypescriptTemplateError'; | ||
/** | ||
* Module which wraps functionality for the `v0/rust/servers/{server_id}/events/player/{steam_id}/chatted` channel | ||
* @module v0RustServersServerIdEventsPlayerSteamIdChatted | ||
*/ | ||
/** | ||
* Internal functionality to setup subscription on the `v0/rust/servers/{server_id}/events/player/{steam_id}/chatted` channel | ||
* | ||
* @param onDataCallback to call when messages are received | ||
* @param nc to subscribe with | ||
* @param codec used to convert messages | ||
* @param server_id parameter to use in topic | ||
* @param steam_id parameter to use in topic | ||
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified | ||
*/ | ||
export function subscribe( | ||
onDataCallback: ( | ||
err ? : NatsTypescriptTemplateError, | ||
msg ? : ChatMessage, server_id ? : string, steam_id ? : string) => void, | ||
nc: Nats.NatsConnection, | ||
codec: Nats.Codec < any > , server_id: string, steam_id: string, | ||
options ? : Nats.SubscriptionOptions | ||
): Promise < Nats.Subscription > { | ||
return new Promise(async (resolve, reject) => { | ||
let subscribeOptions: Nats.SubscriptionOptions = { | ||
...options | ||
}; | ||
try { | ||
let subscription = nc.subscribe(`v0.rust.servers.${server_id}.events.player.${steam_id}.chatted`, subscribeOptions); | ||
(async () => { | ||
for await (const msg of subscription) { | ||
const unmodifiedChannel = `v0.rust.servers.{server_id}.events.player.{steam_id}.chatted`; | ||
let channel = msg.subject; | ||
const serverIdSplit = unmodifiedChannel.split("{server_id}"); | ||
const steamIdSplit = serverIdSplit[1].split("{steam_id}"); | ||
const splits = [ | ||
serverIdSplit[0], | ||
steamIdSplit[0], | ||
steamIdSplit[1] | ||
]; | ||
channel = channel.substring(splits[0].length); | ||
const serverIdEnd = channel.indexOf(splits[1]); | ||
const serverIdParam = "" + channel.substring(0, serverIdEnd); | ||
channel = channel.substring(serverIdEnd + splits[1].length); | ||
const steamIdEnd = channel.indexOf(splits[2]); | ||
const steamIdParam = "" + channel.substring(0, steamIdEnd); | ||
let receivedData: any = codec.decode(msg.data); | ||
onDataCallback(undefined, ChatMessage.unmarshal(receivedData), serverIdParam, steamIdParam); | ||
} | ||
console.log("subscription closed"); | ||
})(); | ||
resolve(subscription); | ||
} catch (e: any) { | ||
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.INTERNAL_NATS_TS_ERROR, e)); | ||
} | ||
}) | ||
} |
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
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,56 @@ | ||
import ServerStopped from '../models/ServerStopped'; | ||
import * as Nats from 'nats'; | ||
import { | ||
ErrorCode, | ||
NatsTypescriptTemplateError | ||
} from '../NatsTypescriptTemplateError'; | ||
/** | ||
* Module which wraps functionality for the `v0/rust/servers/{server_id}/events/stopped` channel | ||
* @module v0RustServersServerIdEventsStopped | ||
*/ | ||
/** | ||
* Internal functionality to setup subscription on the `v0/rust/servers/{server_id}/events/stopped` channel | ||
* | ||
* @param onDataCallback to call when messages are received | ||
* @param nc to subscribe with | ||
* @param codec used to convert messages | ||
* @param server_id parameter to use in topic | ||
* @param options to subscribe with, bindings from the AsyncAPI document overwrite these if specified | ||
*/ | ||
export function subscribe( | ||
onDataCallback: ( | ||
err ? : NatsTypescriptTemplateError, | ||
msg ? : ServerStopped, server_id ? : string) => void, | ||
nc: Nats.NatsConnection, | ||
codec: Nats.Codec < any > , server_id: string, | ||
options ? : Nats.SubscriptionOptions | ||
): Promise < Nats.Subscription > { | ||
return new Promise(async (resolve, reject) => { | ||
let subscribeOptions: Nats.SubscriptionOptions = { | ||
...options | ||
}; | ||
try { | ||
let subscription = nc.subscribe(`v0.rust.servers.${server_id}.events.stopped`, subscribeOptions); | ||
(async () => { | ||
for await (const msg of subscription) { | ||
const unmodifiedChannel = `v0.rust.servers.{server_id}.events.stopped`; | ||
let channel = msg.subject; | ||
const serverIdSplit = unmodifiedChannel.split("{server_id}"); | ||
const splits = [ | ||
serverIdSplit[0], | ||
serverIdSplit[1] | ||
]; | ||
channel = channel.substring(splits[0].length); | ||
const serverIdEnd = channel.indexOf(splits[1]); | ||
const serverIdParam = "" + channel.substring(0, serverIdEnd); | ||
let receivedData: any = codec.decode(msg.data); | ||
onDataCallback(undefined, ServerStopped.unmarshal(receivedData), serverIdParam); | ||
} | ||
console.log("subscription closed"); | ||
})(); | ||
resolve(subscription); | ||
} catch (e: any) { | ||
reject(NatsTypescriptTemplateError.errorForCode(ErrorCode.INTERNAL_NATS_TS_ERROR, e)); | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.