Files
DefinitelyTyped/pusher-js/index.d.ts
zhengbli c2a54db3e9 Merge branch 'master' into types-2.0
# Conflicts:
#	amcharts/AmCharts.d.ts
#	angular-gettext/angular-gettext.d.ts
#	angular-jwt/angular-jwt.d.ts
#	angular-material/angular-material.d.ts
#	angularjs/angular.d.ts
#	auth0-js/auth0-js.d.ts
#	aws-lambda/aws-lambda.d.ts
#	aws-sdk/aws-sdk.d.ts
#	azure-mobile-apps/azure-mobile-apps.d.ts
#	azure-mobile-services-client/AzureMobileServicesClient.d.ts
#	blessed/blessed-tests.ts
#	blessed/blessed.d.ts
#	bootbox/bootbox.d.ts
#	bowser/bowser.d.ts
#	cache-manager/cache-manager.d.ts
#	chai-things/chai-things.d.ts
#	colors/colors.d.ts
#	cordova/cordova-tests.ts
#	cordova/plugins/Contacts.d.ts
#	cordova/plugins/FileSystem.d.ts
#	couchbase/couchbase.d.ts
#	cucumber/cucumber-tests.ts
#	cucumber/cucumber.d.ts
#	d3/d3.d.ts
#	dojo/dojo.d.ts
#	dustjs-linkedin/dustjs-linkedin.d.ts
#	esprima/esprima.d.ts
#	express-serve-static-core/express-serve-static-core.d.ts
#	express-session/express-session.d.ts
#	fetch-mock/fetch-mock.d.ts
#	fs-extra/fs-extra.d.ts
#	fullCalendar/fullCalendar.d.ts
#	github-electron/github-electron.d.ts
#	gulp-uglify/gulp-uglify.d.ts
#	gulp/gulp.d.ts
#	highcharts/highcharts.d.ts
#	imap/imap.d.ts
#	incremental-dom/incremental-dom.d.ts
#	inversify/inversify.d.ts
#	ionic/ionic.d.ts
#	ioredis/ioredis.d.ts
#	isomorphic-fetch/isomorphic-fetch-tests.ts
#	jake/jake.d.ts
#	joi/joi.d.ts
#	jquery-mockjax/jquery-mockjax.d.ts
#	jquery/jquery.d.ts
#	js-data-http/js-data-http-tests.ts
#	js-data-http/js-data-http.d.ts
#	js-data/js-data.d.ts
#	jsdom/jsdom.d.ts
#	jsts/jsts-tests.ts
#	knex/knex.d.ts
#	koa-favicon/koa-favicon.d.ts
#	koa-router/koa-router-tests.ts
#	koa-router/koa-router.d.ts
#	lodash/lodash.d.ts
#	mailparser/mailparser.d.ts
#	maquette/maquette.d.ts
#	material-ui/material-ui.d.ts
#	matter-js/matter-js.d.ts
#	moment/moment.d.ts
#	mongoose-promise/mongoose-promise-tests.ts
#	mongoose/mongoose-tests.ts
#	mongoose/mongoose.d.ts
#	multer/multer.d.ts
#	ncp/ncp.d.ts
#	nock/nock.d.ts
#	node/node-tests.ts
#	node/node.d.ts
#	nvd3/nvd3.d.ts
#	object-assign/object-assign.d.ts
#	openlayers/openlayers.d.ts
#	parse/parse.d.ts
#	pdf/pdf.d.ts
#	pdfkit/pdfkit.d.ts
#	pg/pg.d.ts
#	pixi.js/pixi.js.d.ts
#	progress/progress.d.ts
#	pusher-js/pusher-js.d.ts
#	quill/quill-tests.ts
#	quill/quill.d.ts
#	radium/radium.d.ts
#	ravenjs/ravenjs-tests.ts
#	react-dropzone/react-dropzone.d.ts
#	react-mdl/react-mdl.d.ts
#	react-native/react-native.d.ts
#	react-notification-system/react-notification-system.d.ts
#	react-router/history-tests.ts
#	react-router/react-router-tests.tsx
#	react-router/react-router.d.ts
#	react-select/react-select-tests.tsx
#	react-select/react-select.d.ts
#	react/react.d.ts
#	redux-form/redux-form.d.ts
#	request-promise/request-promise.d.ts
#	resolve-from/resolve-from.d.ts
#	riot-api-nodejs/riot-api-nodejs.d.ts
#	sanitize-html/sanitize-html.d.ts
#	segment-analytics/segment-analytics.d.ts
#	simple-assign/simple-assign-tests.ts
#	simple-assign/simple-assign.d.ts
#	slate-irc/slate-irc.d.ts
#	soap/soap.d.ts
#	socket.io/socket.io.d.ts
#	sql.js/sql.js-tests.ts
#	sql.js/sql.js.d.ts
#	steam/steam.d.ts
#	stylus/stylus.d.ts
#	swiper/swiper.d.ts
#	tedious/tedious.d.ts
#	threejs/three.d.ts
#	twilio/twilio.d.ts
#	underscore/underscore.d.ts
#	ws/ws.d.ts
#	yeoman-generator/yeoman-generator.d.ts
2016-09-14 18:44:24 -07:00

231 lines
7.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Type definitions for pusher-js 3.0.0
// Project: https://github.com/pusher/pusher-js
// Definitions by: Qubo <https://github.com/tkqubo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace pusher {
interface PusherStatic {
new (apiKey: string, config?: Config): Pusher;
}
interface Pusher {
subscribe(name: string): Channel;
subscribeAll(): void;
unsubscribe(name: string): void;
channel(name: string): Channel;
allChannels(): Channel[];
bind(eventName: string, callback: Function): Pusher;
bind_all(callback: Function): Pusher;
disconnect(): void;
key: string;
config: Config; //TODO: add GlobalConfig typings
channels: any; //TODO: Type this
global_emitter: EventsDispatcher;
sessionID: number;
timeline: any; //TODO: Type this
connection: ConnectionManager;
}
interface Config {
/**
* Forces the connection to use encrypted transports.
*/
encrypted?: boolean;
/**
* Endpoint on your server that will return the authentication signature needed for private channels.
*/
authEndpoint?: string;
/**
* Defines how the authentication endpoint, defined using authEndpoint, will be called.
* There are two options available: ajax and jsonp.
*/
authTransport?: string;
/**
* Allows passing additional data to authorizers. Supports query string params and headers (AJAX only).
* For example, following will pass foo=bar via the query string and baz: boo via headers:
*/
auth?: AuthConfig;
/**
* Allows connecting to a different datacenter by setting up correct hostnames and ports for the connection.
*/
cluster?: string;
/**
* Disables stats collection, so that connection metrics are not submitted to Pushers servers.
*/
disableStats?: boolean;
/**
* Specifies which transports should be used by Pusher to establish a connection.
* Useful for applications running in controlled, well-behaving environments.
* Available transports: ws, wss, xhr_streaming, xhr_polling, sockjs.
* Additional transports may be added in the future and without adding them to this list, they will be disabled.
*/
enabledTransports?: string[];
/**
* Specified which transports must not be used by Pusher to establish a connection.
* This settings overwrites transports whitelisted via the enabledTransports options.
* Available transports: ws, wss, xhr_streaming, xhr_polling, sockjs.
* Additional transports may be added in the future and without adding them to this list, they will be enabled.
*/
disabledTransports?: string[];
/**
* Ignores null origin checks for HTTP fallbacks. Use with care, it should be disabled only if necessary (i.e. PhoneGap).
*/
ignoreNullOrigin?: boolean;
/**
* After this time (in miliseconds) without any messages received from the server,
* a ping message will be sent to check if the connection is still working.
* Default value is is supplied by the server, low values will result in unnecessary traffic.
*/
activityTimeout?: number;
/**
* Time before the connection is terminated after sending a ping message.
* Default is 30000 (30s). Low values will cause false disconnections, if latency is high.
*/
pongTimeout?: number;
wsHost?: string;
wsPort?: number;
wssPort?: number;
httpHost?: string;
httpPort?: number;
httpsPort?: number;
}
interface AuthConfig {
params?: { [key: string]: any };
headers?: { [key: string]: any };
}
interface GenericEventsDispatcher<Self extends EventsDispatcher> extends EventsDispatcher {
bind(eventName: string, callback: Function, context?: any): Self;
bind_all(callback: Function): Self;
unbind(eventName?: string, callback?: Function, context?: any): Self;
unbind_all(eventName?: string, callback?: Function): Self;
emit(eventName: string, data?: any): Self;
}
interface Channel extends GenericEventsDispatcher<Channel> {
/** Triggers an event */
trigger(eventName: string, data?: any): boolean;
pusher: Pusher;
name: string;
subscribed: boolean;
/**
* Authenticates the connection as a member of the channel.
* @param {String} socketId
* @param {Function} callback
*/
authorize(socketId: string, callback: (data: any) => void): void;
}
interface EventsDispatcher {
bind(eventName: string, callback: Function, context?: any): EventsDispatcher;
bind_all(callback: Function): EventsDispatcher;
unbind(eventName?: string, callback?: Function, context?: any): EventsDispatcher;
unbind_all(eventName?: string, callback?: Function): EventsDispatcher;
emit(eventName: string, data?: any): EventsDispatcher;
}
interface ConnectionManager extends GenericEventsDispatcher<ConnectionManager> {
key: string;
options: any; //TODO: Timeline.js
state: string;
connection: any; //TODO: Type this
encrypted: boolean;
timeline: any; //TODO: Type this
connectionCallbacks: {
message: (message: string) => void;
ping: () => void;
activity: () => void;
error: (error: any) => void;
closed: () => void;
};
errorCallbacks: {
ssl_only: () => void;
refused: () => void;
backoff: () => void;
retry: () => void;
};
handshakeCallbacks: {
ssl_only: () => void;
refused: () => void;
backoff: () => void;
retry: () => void;
connected: (handshake: any) => void; //TODO: Type this
};
/**
* Establishes a connection to Pusher.
*
* Does nothing when connection is already established. See top-level doc
* to find events emitted on connection attempts.
*/
connect(): void;
/**
* Sends raw data.
* @param {String} data
*/
send(data: string): boolean;
/** Sends an event.
*
* @param {String} name
* @param {String} data
* @param {String} [channel]
* @returns {Boolean} whether message was sent or not
*/
send_event(name: string, data: string, channel: string): boolean;
/** Closes the connection. */
disconnect(): void;
isEncrypted(): boolean;
}
interface PresenceChannel<T> extends Channel {
members: Members<T>;
}
interface Members<T> {
/**
* Returns member's info for given id.
*
* Resulting object containts two fields - id and info.
*
* @param {Number} id
* @return {Object} member's info or null
*/
get(id: number): T;
/**
* Calls back for each member in unspecified order.
*
* @param {Function} callback
*/
each(callback: (member: any) => void): void;
members: { [id: number]: UserInfo<T> };
count: number;
myID: number;
me: UserInfo<T>;
}
interface UserInfo<T> {
id: number;
info: T;
}
}
declare var pusher: pusher.PusherStatic;
export = pusher;