diff --git a/types/mosca/index.d.ts b/types/mosca/index.d.ts index aee3625d10..a1fbd9a5ef 100644 --- a/types/mosca/index.d.ts +++ b/types/mosca/index.d.ts @@ -2,8 +2,33 @@ // Project: https://github.com/mcollina/mosca // Definitions by: Joao Gabriel Gouveia // Jerray Fu +// Ran // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TODO add detailed definition. +// http://www.mosca.io/docs/lib/server.js.html#Server currently has no more description about this. +export interface ServerOptions { + port?: number; + host?: string; + backend?: any; + ascoltatore?: any; + maxInflightMessages?: number; + logger?: any; + persistence?: any; + secure?: { + port: number; + keyPath: string; + certPath: string; + }; + allowNonSecure?: boolean; + http?: { + port: number; + }; + bundle?: any; + static?: any; + stats?: any; +} + export class Server { id: string; opts: any; @@ -11,9 +36,12 @@ export class Server { clients: any; closed: boolean; - constructor(opts: any, callback?: () => void); + constructor(opts: ServerOptions, callback?: () => void); on(when: string, callback: (() => void) | ((client: Client) => void) | ((packet: Packet, client: Client) => void)): void; + on(when: 'clientConnected' | 'clientDisconnecting' | 'clientDisconnected', callback: (client: Client) => void): void; + on(when: 'subscribed' | 'unsubscribed', callback: (topic: string, client: Client) => void): void; + on(when: 'published', callback: (packet: Packet, client: Client) => void): void; once(when: string, callback: () => void): void; toString(): string; subscribe(topic: string, callback: () => void, done: () => void): void; diff --git a/types/mosca/mosca-tests.ts b/types/mosca/mosca-tests.ts index e03b664b1b..337129d573 100644 --- a/types/mosca/mosca-tests.ts +++ b/types/mosca/mosca-tests.ts @@ -1,6 +1,6 @@ -import { Server, Client, Packet } from 'mosca'; +import { Server, Client, Packet, ServerOptions } from 'mosca'; -const settings = { +const settings: ServerOptions = { port: 1883, host: '0.0.0.0' }; @@ -14,3 +14,5 @@ server.on('clientConnected', (client: Client) => {}); server.on('clientDisconnected', (client: Client) => {}); server.on('published', (packet: Packet, client: Client) => {}); + +server.on('subscribed', (topic: string, client: Client) => {});