15
15
* limitations under the License.
16
16
*/
17
17
18
- // TODO(mikelehen): Flesh out proper types (or figure out how to generate via
19
- // clutz or something).
20
- export class XhrIo { }
21
- export const ErrorCode : any ;
22
- export const EventType : any ;
18
+ export enum EventType {
19
+ OPEN = 'open' ,
20
+ CLOSE = 'close' ,
21
+ ERROR = 'error' ,
22
+ MESSAGE = 'message' ,
23
+ COMPLETE = 'complete'
24
+ }
25
+
23
26
export namespace WebChannel {
24
- export type EventType = any ;
25
- export const EventType : any ;
27
+ export const EventType : EventType ;
28
+ }
29
+
30
+ export enum ErrorCode {
31
+ NO_ERROR = 0 ,
32
+ ACCESS_DENIED ,
33
+ FILE_NOT_FOUND ,
34
+ FF_SILENT_ERROR ,
35
+ CUSTOM_ERROR ,
36
+ EXCEPTION ,
37
+ HTTP_ERROR ,
38
+ ABORT ,
39
+ TIMEOUT ,
40
+ OFFLINE
41
+ }
42
+
43
+ export interface Headers {
44
+ [ name : string ] : string | number ;
45
+ }
46
+
47
+ export class XhrIo {
48
+ send (
49
+ url : string ,
50
+ method ?: string ,
51
+ body ?: ArrayBufferView | Blob | string | null ,
52
+ headers ?: Headers ,
53
+ timeoutInterval ?: number
54
+ ) : Promise < XhrIo > ;
55
+
56
+ getLastErrorCode ( ) : ErrorCode ;
57
+
58
+ getLastError ( ) : string ;
59
+
60
+ getStatus ( ) : number ;
61
+
62
+ getResponseText ( ) : string ;
63
+
64
+ getResponseJson ( ) : Object | any ;
65
+
66
+ abort ( ) : void ;
67
+
68
+ getResponseHeader ( header : string ) : { [ key : string ] : string } ;
69
+
70
+ listenOnce < T > ( type : EventType , cb : ( param : T ) => void ) : void ;
26
71
}
27
72
28
73
type StringMap = { [ key : string ] : string } ;
@@ -31,7 +76,9 @@ export interface WebChannelOptions {
31
76
messageHeaders ?: StringMap ;
32
77
initMessageHeaders ?: StringMap ;
33
78
messageContentType ?: string ;
34
- messageUrlParams ?: StringMap ;
79
+ messageUrlParams ?: {
80
+ database ?: string ;
81
+ } ;
35
82
clientProtocolHeaderRequired ?: boolean ;
36
83
concurrentRequestLimit ?: number ;
37
84
supportsCrossDomainXhr ?: boolean ;
@@ -44,13 +91,23 @@ export interface WebChannelOptions {
44
91
fastHandshake ?: boolean ;
45
92
disableRedac ?: boolean ;
46
93
clientProfile ?: string ;
47
- internalChannelParams ?: { [ key : string ] : boolean | number } ;
94
+ internalChannelParams ?: {
95
+ forwardChannelRequestTimeoutMs ?: number ;
96
+ } ;
48
97
xmlHttpFactory ?: unknown ;
49
98
requestRefreshThresholds ?: { [ key : string ] : number } ;
50
99
}
51
100
101
+ export interface WebChannel {
102
+ open ( ) : void ;
103
+ close ( ) : void ;
104
+ halfClose ( ) : void ;
105
+ listen < T > ( type : EventType , cb : ( param : T ) => void ) : void ;
106
+ send < T > ( msg : T ) : void ;
107
+ }
108
+
52
109
export interface WebChannelTransport {
53
- createWebChannel ( url : string , options : WebChannelOptions ) : any ;
110
+ createWebChannel ( url : string , options : WebChannelOptions ) : WebChannel ;
54
111
}
55
112
56
113
export function createWebChannelTransport ( ) : WebChannelTransport ;
0 commit comments