소스 검색

add:增加ws的BinaryType配置

adam 3 년 전
부모
커밋
fc251f3f94
2개의 변경된 파일9개의 추가작업 그리고 7개의 파일을 삭제
  1. 3
    3
      package.json
  2. 6
    4
      src/index.ts

+ 3
- 3
package.json 파일 보기

1
 {
1
 {
2
-  "name": "linker-sdk",
3
-  "version": "1.0.0",
2
+  "name": "@bilingo.com/ts-linker-sdk",
3
+  "version": "1.0.3",
4
   "description": "linker's ts sdk",
4
   "description": "linker's ts sdk",
5
-  "main": "dist/index.js",
5
+  "main": "dist/umd/index.js",
6
   "types": "dist/types/index.d.ts",
6
   "types": "dist/types/index.d.ts",
7
   "scripts": {
7
   "scripts": {
8
     "type-check": "tsc --noEmit --project ./tsconfig.cjs.json",
8
     "type-check": "tsc --noEmit --project ./tsconfig.cjs.json",

+ 6
- 4
src/index.ts 파일 보기

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