|
@@ -17,6 +17,7 @@ class Client {
|
17
|
17
|
private _enableLogger: boolean;
|
18
|
18
|
private static instance: Client;
|
19
|
19
|
private listeners: EventEmitter;
|
|
20
|
+ private binaryType: BinaryType;
|
20
|
21
|
private requestHeader: string;
|
21
|
22
|
private responseHeader: string;
|
22
|
23
|
private url: string;
|
|
@@ -30,7 +31,8 @@ class Client {
|
30
|
31
|
* @param url websocket链接地址
|
31
|
32
|
* @param readyStateCallback 链接状态回调,可以处理onOpen、onClose、onError
|
32
|
33
|
*/
|
33
|
|
- private constructor(url: string, readyStateCallback: ReadyStateCallback) {
|
|
34
|
+ private constructor(url: string, readyStateCallback: ReadyStateCallback, binaryType?: BinaryType) {
|
|
35
|
+ this.binaryType = binaryType || 'blob';
|
34
|
36
|
this.listeners = new EventEmitter();
|
35
|
37
|
this.requestHeader = '';
|
36
|
38
|
this.requestHeader = '';
|
|
@@ -47,9 +49,9 @@ class Client {
|
47
|
49
|
* @param url websocket链接地址
|
48
|
50
|
* @param readyStateCallback 链接状态回调,可以处理onOpen、onClose、onError
|
49
|
51
|
*/
|
50
|
|
- public static getInstance(url: string, callback: ReadyStateCallback): Client {
|
|
52
|
+ public static getInstance(url: string, callback: ReadyStateCallback, binaryType?: BinaryType): Client {
|
51
|
53
|
if (!Client.instance) {
|
52
|
|
- Client.instance = new Client(url, callback);
|
|
54
|
+ Client.instance = new Client(url, callback, binaryType);
|
53
|
55
|
}
|
54
|
56
|
|
55
|
57
|
return Client.instance;
|
|
@@ -254,7 +256,7 @@ class Client {
|
254
|
256
|
const readyStateCallback = this.readyStateCallback;
|
255
|
257
|
let ws = new WebSocket(this.url);
|
256
|
258
|
|
257
|
|
- ws.binaryType = 'blob';
|
|
259
|
+ ws.binaryType = this.binaryType;
|
258
|
260
|
|
259
|
261
|
ws.onopen = (ev): void => {
|
260
|
262
|
if (this._enableLogger) {
|