-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db02f5f
commit 4f66064
Showing
6 changed files
with
182 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import HttpMethods from "../constants/HttpMethods"; | ||
import ErrorInfo from "../lib/types/errorinfo"; | ||
import TokenDetails from "./TokenDetails"; | ||
import TokenParams from "./TokenParams"; | ||
import TokenRequest from "./TokenRequest"; | ||
|
||
export default interface AuthOptions { | ||
/** | ||
* A function which is called when a new token is required. | ||
* The role of the callback is to either generate a signed TokenRequest which may then be submitted automatically | ||
* by the library to the Ably REST API requestToken; or to provide a valid token in as a TokenDetails object. | ||
**/ | ||
authCallback?: (data: TokenParams, callback: (error: ErrorInfo | string, tokenRequestOrDetails: TokenDetails | TokenRequest | string) => void) => void; | ||
authHeaders?: { [index: string]: string }; | ||
authMethod?: HttpMethods; | ||
authParams?: { [index: string]: string }; | ||
|
||
/** | ||
* A URL that the library may use to obtain a token string (in plain text format), or a signed TokenRequest or TokenDetails (in JSON format). | ||
**/ | ||
authUrl?: string; | ||
key?: string; | ||
queryTime?: boolean; | ||
token?: TokenDetails | string; | ||
tokenDetails?: TokenDetails; | ||
useTokenAuth?: boolean; | ||
|
||
/** | ||
* Optional clientId that can be used to specify the identity for this client. In most cases | ||
* it is preferable to instead specift a clientId in the token issued to this client. | ||
*/ | ||
clientId?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { LoggerOptions } from "../lib/util/logger"; | ||
import AuthOptions from "./AuthOptions"; | ||
import TokenParams from "./TokenParams"; | ||
import { Modify } from "./utils"; | ||
|
||
type Transport = 'web_socket' | 'xhr_streaming' | 'xhr_polling' | 'jsonp' | 'comet'; | ||
|
||
export default interface ClientOptions extends AuthOptions { | ||
/** | ||
* When true will automatically connect to Ably when library is instanced. This is true by default | ||
*/ | ||
autoConnect?: boolean; | ||
|
||
defaultTokenParams?: TokenParams; | ||
|
||
/** | ||
* When true, messages published on channels by this client will be echoed back to this client. | ||
* This is true by default | ||
*/ | ||
echoMessages?: boolean; | ||
|
||
/** | ||
* Use this only if you have been provided a dedicated environment by Ably | ||
*/ | ||
environment?: string; | ||
|
||
/** | ||
* Logger configuration | ||
*/ | ||
log?: LoggerOptions; | ||
port?: number; | ||
|
||
/** | ||
* When true, messages will be queued whilst the connection is disconnected. True by default. | ||
*/ | ||
queueMessages?: boolean; | ||
|
||
restHost?: string; | ||
realtimeHost?: string; | ||
fallbackHosts?: string[]; | ||
fallbackHostsUseDefault?: boolean; | ||
|
||
/** | ||
* Can be used to explicitly recover a connection. | ||
* See https://www.ably.com/documentation/realtime/connection#connection-state-recovery | ||
*/ | ||
recover?: boolean | null | string | ((lastConnectionDetails: { | ||
recoveryKey: string; | ||
disconnectedAt: number; | ||
location: string; | ||
clientId: string | null; | ||
}, callback: (shouldRecover: boolean) => void) => void); | ||
|
||
/** | ||
* Use a non-secure connection connection. By default, a TLS connection is used to connect to Ably | ||
*/ | ||
tls?: boolean; | ||
tlsPort?: number; | ||
|
||
/** | ||
* When true, the more efficient MsgPack binary encoding is used. | ||
* When false, JSON text encoding is used. | ||
*/ | ||
useBinaryProtocol?: boolean; | ||
|
||
disconnectedRetryTimeout?: number; | ||
suspendedRetryTimeout?: number; | ||
closeOnUnload?: boolean; | ||
idempotentRestPublishing?: boolean; | ||
transportParams?: {[k: string]: string}; | ||
transports?: Transport[]; | ||
|
||
httpMaxRetryCount?: number; | ||
restAgentOptions?: { keepAlive: boolean, maxSockets: number }; | ||
pushFullWait?: boolean; | ||
checkChannelsOnResume?: boolean; | ||
plugins?: Record<string, unknown>; | ||
} | ||
|
||
export type DeprecatedClientOptions = Modify<ClientOptions, { | ||
host?: string; | ||
wsHost?: string; | ||
queueEvents?: boolean; | ||
promises?: boolean; | ||
headers?: Record<string, string>; | ||
maxMessageSize?: number; | ||
timeouts?: Record<string, number>; | ||
}> | ||
|
||
export type NormalisedClientOptions = Modify<DeprecatedClientOptions, { | ||
realtimeHost: string; | ||
restHost: string; | ||
keyName?: string; | ||
keySecret?: string; | ||
timeouts: Record<string, number>; | ||
maxMessageSize: number; | ||
}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default interface TokenRequest { | ||
capability: string; | ||
clientId?: string; | ||
keyName: string; | ||
mac: string; | ||
nonce: string; | ||
timestamp: number; | ||
ttl?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export type StandardCallback<T> = (err?: ErrorInfo | null, result?: T) => void; | ||
export type ErrCallback = (err?: ErrorInfo | null) => void; | ||
export type PaginatedResultCallback<T> = StandardCallback<PaginatedResult<T>>; | ||
export type Modify<T, R> = Omit<T, keyof R> & R; |