diff --git a/node-xmpp-client/index.d.ts b/node-xmpp-client/index.d.ts new file mode 100644 index 0000000000..874df37de7 --- /dev/null +++ b/node-xmpp-client/index.d.ts @@ -0,0 +1,71 @@ +// Type definitions for node-xmpp-client 3.1 +// Project: https://github.com/node-xmpp/node-xmpp/tree/master/packages/node-xmpp-client/ +// Definitions by: PJakcson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +export declare class Client { + static Stanza: Stanza; + + constructor(options: XmppOptions); + + connect(): void; + + disconnect(): void; + + on(event: string, c: (e: any, d: any) => any): void; + + send(stanza: any): void; +} + +interface Stanza extends Element { + // This has to be used for the static class initializer new Client.Stanza(..). If there is a better way feel free to + // contribute. + // tslint:disable-next-line + new(name: string, attr: any): Stanza; + from: string; + to: string; + id: string; + type: string; +} + +interface Element { + is(name: string, xmlns: string): boolean; + getName(): string; + getNS(): string; + findNS(prefix: string): string; + getXmlns(): string; + setAttrs(attrs: any): void; + getAttrs(): any; + + up(): Element; + c(name: string, attrs?: any): Element; + cnode(child: Element): Element; + t(text: string): Element; + remove(el: Element, xmnls: string): Element; + attr(attr: any, val: any): any; + + toString(): string; + toJSON(): any; +} + +interface XmppOptions { + jid: string; + password: string; + host?: string; + port?: number; + reconnect?: boolean; + autostart?: boolean; // if we start connecting to a given port + register?: boolean; // register account before authentication + legacySSL?: boolean; // connect to the legacy SSL port, requires at least the host to be specified + credentials?: any; // Dictionary (optional) - TLS or SSL key and certificate credentials + actAs?: string; // if admin user act on behalf of another user (just user) + disallowTLS?: boolean; // prevent upgrading the connection to a secure one via TLS + preferred?: string; // Preferred SASL mechanism to use + bosh?: Bosh; +} + +interface Bosh { + url?: string; + prebind?: (error: any, data: any) => void; +} diff --git a/node-xmpp-client/node-xmpp-client-tests.ts b/node-xmpp-client/node-xmpp-client-tests.ts new file mode 100644 index 0000000000..52a54a0453 --- /dev/null +++ b/node-xmpp-client/node-xmpp-client-tests.ts @@ -0,0 +1,22 @@ +import {Client} from './index'; + +let client = new Client({ + jid: 'user@example.com', + password: 'password' +}); + +client.connect(); + +client.on('online', function () { +}); + +client.on('stanza', function (stanza) { + let _ = stanza; +}); + +let stanza = new Client.Stanza('chat', {}) + .c('show').t('chat').up() + .c('status').t('message'); +client.send(stanza); + +client.disconnect(); diff --git a/node-xmpp-client/tsconfig.json b/node-xmpp-client/tsconfig.json new file mode 100644 index 0000000000..c76db9a985 --- /dev/null +++ b/node-xmpp-client/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "node-xmpp-client-tests.ts" + ] +} diff --git a/node-xmpp-client/tslint.json b/node-xmpp-client/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/node-xmpp-client/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +}