added typings for atmosphere

This commit is contained in:
Kai Toedter
2014-05-18 21:37:47 +02:00
parent bb59fade92
commit 11179de660
3 changed files with 153 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ All definitions files include a header with the author and editors, so at some p
* [asciify](https://github.com/olizilla/asciify) (by [Alan](http://alan.norbauer.com))
* [assert](https://github.com/Jxck/assert) (by [vvakame](https://github.com/vvakame))
* [async](https://github.com/caolan/async) (by [Boris Yankov](https://github.com/borisyankov))
* [atmosphere](https://github.com/Atmosphere/atmosphere-javascript) (by [Kai Toedter](https://github.com/toedter))
* [Atom](https://atom.io/) (by [vvakame](https://github.com/vvakame))
* [aws-sdk-js](https://github.com/aws/aws-sdk-js) (by [midknight41](https://github.com/midknight41))
* [Backbone.js](http://backbonejs.org/) (by [Boris Yankov](https://github.com/borisyankov))

View File

@@ -0,0 +1,46 @@
/// <reference path="atmosphere.d.ts" />
var socket = atmosphere;
var request1:Atmosphere.Request = new atmosphere.AtmosphereRequest();
request1.url = document.location.toString() + 'chat';
request1.contentType = "application/json";
request1.transport = 'websocket';
request1.fallbackTransport = 'long-polling';
var request2:Atmosphere.Request = {
url: 'http://localhost:8080/chat',
contentType: "application/json",
logLevel: 'debug',
transport: 'websocket',
fallbackTransport: 'long-polling'
};
request1.onError = function (response?:Atmosphere.Response) {};
request1.onClose = function (response?:Atmosphere.Response) {};
request1.onOpen = function (response?:Atmosphere.Response) {};
request1.onMessage = function (response:Atmosphere.Response) {};
request1.onReopen = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {};
request1.onReconnect = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {};
request1.onMessagePublished = function (response?:Atmosphere.Response) {};
request1.onTransportFailure = function (reason?:string, response?:Atmosphere.Response) {};
request1.onLocalMessage = function (request?:Atmosphere.Request) {};
request1.onFailureToReconnect = function (request?:Atmosphere.Request, response?:Atmosphere.Response) {};
request1.onClientTimeout = function (request?:Atmosphere.Request) {};
request1.subscribe = function (options:Atmosphere.Request) {};
request1.execute = function () {};
request1.close = function () {};
request1.disconnect = function () {};
request1.getUrl = function ():string { return "http://www.toedter.com" };
request1.push = function (message:string, dispatchUrl?:string) {};
request1.getUUID = function () {};
request1.pushLocal = function (message:string) {};
var subSocket:Atmosphere.Request = socket.subscribe(request1);
var subSocket2:Atmosphere.Request = socket.subscribe('http://chat.com', function() {}, request2);
subSocket2.close();
subSocket.push("test");
socket.unsubscribe();

106
atmosphere/atmosphere.d.ts vendored Normal file
View File

@@ -0,0 +1,106 @@
// Type definitions for Atmosphere v2.1.5
// Project: https://github.com/Atmosphere/atmosphere-javascript
// Definitions by: Kai Toedter <https://github.com/toedter/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module Atmosphere {
interface Atmosphere {
/**
* The atmosphere API is a little bit special here: the first parameter can either be
* a URL string or a Request object. If it is a URL string, then the additional parameters are expected.
*/
subscribe?: (requestOrUrl:any, callback?:Function, request?:Request) => Request;
unsubscribe?: () => void;
AtmosphereRequest?: AtmosphereRequest;
}
// needed to fit JavaScript "new atmosphere.AtmosphereRequest()"
// and compile with --noImplicitAny
interface AtmosphereRequest {
new(): Request;
}
interface Request {
timeout?: number;
method?: string;
headers?: any;
contentType?: string;
callback?: Function;
url?: string;
data?: string;
suspend?: boolean;
maxRequest?: number;
reconnect?: boolean;
maxStreamingLength?: number;
lastIndex?: number;
logLevel?: string;
requestCount?: number;
fallbackMethod?: string;
fallbackTransport?: string;
transport?: string;
webSocketImpl?: any;
webSocketBinaryType?: any;
dispatchUrl?: string;
webSocketPathDelimiter?: string;
enableXDR?: boolean;
rewriteURL?: boolean;
attachHeadersAsQueryString?: boolean;
executeCallbackBeforeReconnect?: boolean;
readyState?: number;
lastTimestamp?: number;
withCredentials?: boolean;
trackMessageLength?: boolean;
messageDelimiter?: string;
connectTimeout?: number;
reconnectInterval?: number;
dropHeaders?: boolean;
uuid?: number;
async?: boolean;
shared?: boolean;
readResponsesHeaders?: boolean;
maxReconnectOnClose?: number;
enableProtocol?: boolean;
pollingInterval?: number;
onError?: (response?:Response) => void;
onClose?: (response?:Response) => void;
onOpen?: (response?:Response) => void;
onMessage?: (response:Response) => void;
onReopen?: (request?:Request, response?:Response) => void;
onReconnect?: (request?:Request, response?:Response) => void;
onMessagePublished?: (response?:Response) => void;
onTransportFailure?: (reason?:string, response?:Response) => void;
onLocalMessage?: (request?:Request) => void;
onFailureToReconnect?: (request?:Request, response?:Response) => void;
onClientTimeout?: (request?:Request) => void;
subscribe?: (options:Request) => void;
execute?: () => void;
close?: () => void;
disconnect?: () => void;
getUrl?: () => string;
push?: (message:string, dispatchUrl?:string) => void;
getUUID?: () => void;
pushLocal?: (message:string) => void;
}
interface Response {
status?: number;
reasonPhrase?: string;
responseBody?: string;
messages?: string[];
headers?: string[];
state?: string;
transport?: string;
error?: string;
request?: Request;
partialMessage?: string;
errorHandled?: boolean;
closedByClientTimeout?: boolean;
}
}
declare var atmosphere:Atmosphere.Atmosphere;