mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
sockjs-client
This commit is contained in:
parent
ffceea9dd1
commit
b6bde6b97d
48
sockjs-client/sockjs-client-tests.ts
Normal file
48
sockjs-client/sockjs-client-tests.ts
Normal file
@ -0,0 +1,48 @@
|
||||
/// <reference path="./sockjs-client.d.ts" />
|
||||
|
||||
import * as SockJS from 'sockjs-client';
|
||||
import BaseEvent = __SockJSClient.BaseEvent;
|
||||
import SockJSClass = __SockJSClient.SockJSClass;
|
||||
|
||||
let sockJs: SockJSClass;
|
||||
|
||||
sockJs = new SockJS('url');
|
||||
sockJs = SockJS('url');
|
||||
sockJs = SockJS('url', null, {
|
||||
server: '1233445',
|
||||
sessionId: 23,
|
||||
transports: 'websocket'
|
||||
});
|
||||
sockJs = SockJS('url', null, {
|
||||
sessionId: () => 'SID',
|
||||
transports: ['websocket', 'eventsource']
|
||||
});
|
||||
|
||||
let listener = (e: BaseEvent) => e;
|
||||
let listenerObj = {
|
||||
handleEvent: (e: BaseEvent) => e
|
||||
};
|
||||
|
||||
sockJs.addEventListener('onopen', listener);
|
||||
sockJs.addEventListener('onclose', listener, true);
|
||||
sockJs.addEventListener('onopen', listenerObj);
|
||||
sockJs.addEventListener('onclose', listenerObj, true);
|
||||
|
||||
sockJs.removeEventListener('onopen', listener);
|
||||
sockJs.removeEventListener('onclose', listener, true);
|
||||
sockJs.removeEventListener('onopen', listenerObj);
|
||||
sockJs.removeEventListener('onclose', listenerObj, true);
|
||||
|
||||
sockJs.onopen = e => console.log(e);
|
||||
sockJs.onmessage = e => console.log(e.data);
|
||||
sockJs.onclose = e => console.log(e.code, e.reason, e.wasClean);
|
||||
|
||||
let testStates = SockJS.CONNECTING !== -1 && SockJS.OPEN !== -1 &&
|
||||
SockJS.CLOSING !== -1 && SockJS.CLOSED !== -1;
|
||||
|
||||
sockJs.send('send');
|
||||
sockJs.send({x: 1});
|
||||
|
||||
sockJs.close(100, 'reason');
|
||||
sockJs.close(200);
|
||||
sockJs.close();
|
||||
65
sockjs-client/sockjs-client.d.ts
vendored
Normal file
65
sockjs-client/sockjs-client.d.ts
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// Type definitions for sockjs-client 1.0.3
|
||||
// Project: https://github.com/sockjs/sockjs-client
|
||||
// Definitions by: Emil Ivanov <https://github.com/vladev>, Alexander Rusakov <https://github.com/arusakov/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare namespace __SockJSClient {
|
||||
interface BaseEvent {
|
||||
type: string;
|
||||
}
|
||||
|
||||
interface OpenEvent extends BaseEvent {}
|
||||
|
||||
interface CloseEvent extends BaseEvent {
|
||||
code: number;
|
||||
reason: string;
|
||||
wasClean: boolean;
|
||||
}
|
||||
|
||||
interface MessageEvent extends BaseEvent {
|
||||
data: string;
|
||||
}
|
||||
|
||||
interface SessionGenerator {
|
||||
(): string;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
server?: string;
|
||||
sessionId?: number | SessionGenerator;
|
||||
transports?: string | string[]
|
||||
}
|
||||
|
||||
enum State {
|
||||
CONNECTING = 0, OPEN, CLOSING, CLOSED
|
||||
}
|
||||
|
||||
interface SockJSClass extends EventTarget {
|
||||
readyState: State;
|
||||
protocol: string;
|
||||
url: string;
|
||||
onopen: (e: OpenEvent) => any;
|
||||
onclose: (e: CloseEvent) => any;
|
||||
onmessage: (e: MessageEvent) => any;
|
||||
send(data: any): void;
|
||||
close(code?: number, reason?: string): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'sockjs-client' {
|
||||
import SockJSClass = __SockJSClient.SockJSClass;
|
||||
import Options = __SockJSClient.Options;
|
||||
import State = __SockJSClient.State;
|
||||
|
||||
var SockJS: {
|
||||
new(url: string, _reserved?: any, options?: Options): SockJSClass;
|
||||
(url: string, _reserved?: any, options?: Options): SockJSClass;
|
||||
prototype: SockJSClass;
|
||||
CONNECTING: State;
|
||||
OPEN: State;
|
||||
CLOSING: State;
|
||||
CLOSED: State;
|
||||
};
|
||||
|
||||
export = SockJS;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user