-
Notifications
You must be signed in to change notification settings - Fork 13
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
f983940
commit c273848
Showing
8 changed files
with
57 additions
and
56 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Kient from 'Kient' | ||
import { Kient } from 'kient' | ||
import { inspect } from 'bun' | ||
|
||
const kient = new Kient() | ||
|
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
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,50 +1 @@ | ||
import defu from 'defu' | ||
import { getChannel } from './api/channels/get-channel' | ||
import { WSClient } from './ws.client' | ||
import { EventEmitter } from 'tseep' | ||
import type { KientEventEmitters } from './events' | ||
|
||
type DeepRequired<T> = { | ||
[P in keyof T]-?: DeepRequired<NonNullable<T[P]>> | ||
} | ||
|
||
export interface KientOptions { | ||
connectToWebsocket?: boolean | ||
pusher?: { | ||
appKey?: string | ||
cluster?: string | ||
} | ||
} | ||
|
||
const defaultKientOptions: DeepRequired<KientOptions> = { | ||
connectToWebsocket: true, | ||
pusher: { | ||
appKey: '32cbd69e4b950bf97679', | ||
cluster: 'us2', | ||
}, | ||
} | ||
|
||
export default class Kient extends EventEmitter<KientEventEmitters> { | ||
private readonly kientOptions!: DeepRequired<KientOptions> | ||
private wsClient?: WSClient | ||
|
||
constructor(options?: KientOptions) { | ||
super() | ||
this.kientOptions = defu(options, defaultKientOptions) | ||
|
||
this.kientOptions.connectToWebsocket ? this.connectWebsocket() : null | ||
} | ||
|
||
connectWebsocket() { | ||
this.wsClient = new WSClient(this, { | ||
pusher: { | ||
appKey: this.kientOptions.pusher.appKey, | ||
cluster: this.kientOptions.pusher.cluster, | ||
}, | ||
}) | ||
} | ||
|
||
api = { | ||
getChannel: (slugOrId: string) => getChannel(this, slugOrId), | ||
} | ||
} | ||
export { Kient } from './kient' |
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 defu from 'defu' | ||
import { getChannel } from './api/channels/get-channel' | ||
import { WSClient } from './ws.client' | ||
import { EventEmitter } from 'tseep' | ||
import type { KientEventEmitters } from './events' | ||
|
||
type DeepRequired<T> = { | ||
[P in keyof T]-?: DeepRequired<NonNullable<T[P]>> | ||
} | ||
|
||
export interface KientOptions { | ||
connectToWebsocket?: boolean | ||
pusher?: { | ||
appKey?: string | ||
cluster?: string | ||
} | ||
} | ||
|
||
const defaultKientOptions: DeepRequired<KientOptions> = { | ||
connectToWebsocket: true, | ||
pusher: { | ||
appKey: '32cbd69e4b950bf97679', | ||
cluster: 'us2', | ||
}, | ||
} | ||
|
||
export class Kient extends EventEmitter<KientEventEmitters> { | ||
private readonly kientOptions!: DeepRequired<KientOptions> | ||
private wsClient?: WSClient | ||
|
||
constructor(options?: KientOptions) { | ||
super() | ||
this.kientOptions = defu(options, defaultKientOptions) | ||
|
||
this.kientOptions.connectToWebsocket ? this.connectWebsocket() : null | ||
} | ||
|
||
connectWebsocket() { | ||
this.wsClient = new WSClient(this, { | ||
pusher: { | ||
appKey: this.kientOptions.pusher.appKey, | ||
cluster: this.kientOptions.pusher.cluster, | ||
}, | ||
}) | ||
} | ||
|
||
api = { | ||
getChannel: (slugOrId: string) => getChannel(this, slugOrId), | ||
} | ||
} |
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
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