Skip to content

Commit

Permalink
Port as number, fixed returns
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Aug 1, 2023
1 parent c7ca0fd commit 6e8b315
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-beers-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ccat-api": patch
---

Now the port is a number
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const cat = new CatClient({
|:------------:|:--------:|:------------:|:--------------------------------------------------------------------------------:|
| **baseUrl** | string | **Required** | The same of **CORE_HOST** |
| **authKey** | string | '' | The same of **API_KEY** |
| **port** | string | '1865' | The same of the **CORE_PORT** |
| **port** | number | 1865 | The same of the **CORE_PORT** |
| **instant** | boolean | true | Instantly initialize the websocket and the API client, or later with **.init()** |
| **secure** | boolean | false | The same of the **CORE_USE_SECURE_PROTOCOLS** |
| **timeout** | number | 10000 | Timeout for the endpoints, in milliseconds |
Expand Down
12 changes: 8 additions & 4 deletions api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CatClient {
secure: false,
instant: true,
timeout: 10000,
port: '1865',
port: 1865,
...settings
}
if (this.config.instant) this.init()
Expand Down Expand Up @@ -76,11 +76,12 @@ export class CatClient {
}
}

reset() {
reset(): CatClient {
this.retried = 0
this.close()
this.ws = undefined
this.apiClient = undefined
return this
}

/**
Expand Down Expand Up @@ -118,9 +119,10 @@ export class CatClient {
/**
* Closes the WebSocket connection
*/
close() {
close(): CatClient {
this.ws?.close()
this.explicitlyClosed = true
return this
}

/**
Expand All @@ -135,18 +137,20 @@ export class CatClient {
* @param message The message to pass
* @param settings The prompt settings to pass
*/
send(message: string, settings?: Partial<PromptSettings>) {
send(message: string, settings?: Partial<PromptSettings>): CatClient {
if (this.ws?.readyState !== WebSocket.OPEN) {
this.errorHandler?.({
name: 'SocketClosed',
description: 'The connection to the server was closed'
})
return this
}
const jsonMessage = JSON.stringify({
text: message,
prompt_settings: settings
})
this.ws?.send(jsonMessage)
return this
}

/**
Expand Down
4 changes: 2 additions & 2 deletions api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export interface CatSettings {
authKey?: string
/**
* The port to which connect to the Cat
* @default '1865'
* @default 1865
*/
port?: string
port?: number
/**
* Choose to either initialize the client instantly or not
* @default true
Expand Down
2 changes: 1 addition & 1 deletion catapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@
}
}
},
"security": null
"security": []
},
"put": {
"tags": [
Expand Down

0 comments on commit 6e8b315

Please sign in to comment.