Add stompjs types 2.0 definitions. (#12605)

This commit is contained in:
Jimi (Dimitris) Charalampidis
2016-11-10 12:09:38 -08:00
committed by Andy
parent 67be572c32
commit 0fe09ccd9d
3 changed files with 173 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
// Type definitions for stompjs 2.3
// Project: https://github.com/jmesnil/stomp-websocket
// Definitions by: Jimi Charalampidis <https://github.com/jimic>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export const VERSIONS: {
V1_0: string,
V1_1: string,
V1_2: string,
supportedVersions: () => Array<string>
};
export class Client {
connected: boolean;
counter: number;
heartbeat: {
incoming: number,
outgoing: number
};
maxWebSocketFrameSize: number;
subscriptions: {};
ws: WebSocket;
debug(...args: string[]): any;
connect(...args: any[]): any;
disconnect(disconnectCallback: () => any, headers?: {}): any;
send(destination: string, headers?: {}, body?: string): any;
subscribe(destination: string, callback?: (message: Message) => any, headers?: {}): any;
unsubscribe(): any;
begin(transaction: string): any;
commit(transaction: string): any;
abort(transaction: string): any;
ack(messageID: string, subscription: string, headers?: {}): any;
nack(messageID: string, subscription: string, headers?: {}): any;
}
export interface Message {
command: string;
headers: {};
body: string;
ack(headers?: {}): any;
nack(headers?: {}): any;
}
export class Frame {
constructor(command: string, headers?: {}, body?: string);
toString(): string;
sizeOfUTF8(s: string): number;
unmarshall(datas: any): any;
marshall(command: string, headers?: {}, body?: string): any;
}
export function client(url: string, protocols?: string | Array<string>): Client;
export function over(ws: WebSocket): Client;
export function overTCP(host: string, port: number): Client;
export function overWS(url: string): Client;
export function setInterval(interval: number, f: (...args: any[]) => void): NodeJS.Timer;
export function clearInterval(id: NodeJS.Timer): void;
+87
View File
@@ -0,0 +1,87 @@
import * as Stomp from 'stompjs';
let interval = Stomp.setInterval(1000, () => { });
Stomp.clearInterval(interval);
let client: Stomp.Client;
client = Stomp.client('url');
client = Stomp.client('url', Stomp.VERSIONS.supportedVersions());
client = Stomp.client('url', Stomp.VERSIONS.V1_0);
client = Stomp.client('url', Stomp.VERSIONS.V1_1);
client = Stomp.over(new WebSocket('url'));
client = Stomp.over(new WebSocket('url', Stomp.VERSIONS.supportedVersions()));
client = Stomp.over(new WebSocket('url', Stomp.VERSIONS.V1_0));
client = Stomp.over(new WebSocket('url', Stomp.VERSIONS.V1_1));
client = Stomp.overTCP('host', 0);
client = Stomp.overWS('url');
client.connected = false;
client.counter = 0;
client.heartbeat = { incoming: 20000, outgoing: 20000 };
client.maxWebSocketFrameSize = 16 * 1024;
client.subscriptions = { 'sub-0': {}, 'sub-1': () => { } };
client.ws = new WebSocket('url');
client.debug();
client.connect();
client.connect('', () => { }, {});
client.disconnect(() => { });
client.disconnect(() => { }, {});
client.send('destination');
client.send('destination', {});
client.send('destination', {}, 'body');
client.subscribe('destination', (message) => { });
client.subscribe('destination', (message) => { }, {});
client.unsubscribe();
client.begin('transaction');
client.commit('transaction');
client.abort('transaction');
client.ack('messageID', 'subscription');
client.nack('messageID', 'subscription', {});
let message: Stomp.Message = {
command: 'command',
headers: {},
body: 'body',
ack({}) { },
nack({}) { }
}
message.ack();
message.ack({});
message.nack();
message.nack({});
let frame: Stomp.Frame;
frame = new Stomp.Frame('command');
frame = new Stomp.Frame('command', {});
frame = new Stomp.Frame('command', {}, 'body');
frame.toString();
frame.sizeOfUTF8('abc');
frame.unmarshall(0);
frame.unmarshall('data');
frame.unmarshall({});
frame.unmarshall([{}, {}]);
frame.marshall('command');
frame.marshall('command', {});
frame.marshall('command', {}, 'body');
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"stompjs-tests.ts"
]
}