Skip to content

Commit

Permalink
Fixed PreConnect typescript definition (#308)
Browse files Browse the repository at this point in the history
* Fixed PreConnect typescript definition

* Added preConnect typescript test
  • Loading branch information
gnought authored and mcollina committed Sep 2, 2019
1 parent bc7f768 commit ab89b23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions test/typescript/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const broker = Server({
concurrency: 100,
heartbeatInterval: 60000,
connectTimeout: 30000,
preConnect: (client: Client, callback) => {
if (client.conn.remoteAddress === '::1') {
callback(null, true)
} else {
callback(new Error('connection error'), false)
}
},
authenticate: (client: Client, username: string, password: string, callback) => {
if (username === 'test' && password === 'test') {
callback(null, true)
Expand Down
4 changes: 3 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { IPublishPacket, ISubscribePacket, ISubscription, IUnsubscribePacket } from 'mqtt-packet'
import { Duplex } from 'stream'
import { Socket } from 'net'
import EventEmitter = NodeJS.EventEmitter

declare function aedes (options?: aedes.AedesOptions): aedes.Aedes
Expand All @@ -22,6 +23,7 @@ declare namespace aedes {
export interface Client extends EventEmitter {
id: string
clean: boolean
conn: Socket

on (event: 'error', cb: (err: Error) => void): this

Expand All @@ -34,7 +36,7 @@ declare namespace aedes {
close (callback?: () => void): void
}

export type PreConnectCallback = (client: Client) => boolean
export type PreConnectCallback = (client: Client, done: (err: Error | null, success: boolean) => void) => void

export type AuthenticateError = Error & { returnCode: AuthErrorCode }

Expand Down

0 comments on commit ab89b23

Please sign in to comment.