Update mosca. (#41180)

* Add Server constructor options define.

* Add detailed event callback define.

* Add more test.
This commit is contained in:
冉
2019-12-26 10:39:59 -06:00
committed by Andrew Branch
parent a5bc0a0874
commit 7829740aac
2 changed files with 33 additions and 3 deletions
+29 -1
View File
@@ -2,8 +2,33 @@
// Project: https://github.com/mcollina/mosca
// Definitions by: Joao Gabriel Gouveia <https://github.com/GabrielGouv>
// Jerray Fu <https://github.com/jerray>
// Ran <https://github.com/ranto2012>
// 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;
+4 -2
View File
@@ -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) => {});