xfyun-client
Advanced tools
Comparing version 1.2.1 to 1.3.0
import { BehaviorSubject, Subject, Observable } from 'rxjs'; | ||
import { WebSocketSubject } from 'rxjs/webSocket'; | ||
import { ApiConnectionStatus } from './status.js'; | ||
@@ -9,4 +10,4 @@ import { ApiOption, AuthOption } from './option.js'; | ||
protected option: O; | ||
protected webSocket: WebSocket; | ||
protected response: Res; | ||
protected $webSocket: WebSocketSubject<Req | Res>; | ||
protected sid: string; | ||
@@ -23,6 +24,2 @@ protected $status: BehaviorSubject<ApiConnectionStatus>; | ||
protected $chunked: Observable<Uint8Array>; | ||
/** | ||
* Messages to send to WebSocket | ||
*/ | ||
protected $message: Subject<string>; | ||
protected Option(): O; | ||
@@ -29,0 +26,0 @@ protected Response(): Res; |
@@ -1,1 +0,1 @@ | ||
import{a}from"../chunk-OIGXPLZC.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{a as ApiConnection}; | ||
import{a}from"../chunk-NGEEV3H4.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{a as ApiConnection}; |
@@ -7,1 +7,2 @@ export { ApiConnection } from './connection.js'; | ||
import 'rxjs'; | ||
import 'rxjs/webSocket'; |
@@ -1,1 +0,1 @@ | ||
import"../chunk-JZND3VTD.js";import{a as d}from"../chunk-OIGXPLZC.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import{a as b}from"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import{a as c}from"../chunk-TU3JZGTL.js";import{a}from"../chunk-LIPHC4AO.js";export{d as ApiConnection,a as ApiConnectionStatus,b as ApiOption,c as ApiResponse}; | ||
import"../chunk-JZND3VTD.js";import{a as d}from"../chunk-NGEEV3H4.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import{a as b}from"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import{a as c}from"../chunk-TU3JZGTL.js";import{a}from"../chunk-LIPHC4AO.js";export{d as ApiConnection,a as ApiConnectionStatus,b as ApiOption,c as ApiResponse}; |
@@ -6,2 +6,3 @@ import { IatRequest, IatRequestBusinessAccent, IatRequestBusinessLanguage, IatRequestBusinessDomain } from './request.js'; | ||
import 'rxjs'; | ||
import 'rxjs/webSocket'; | ||
import '../api/status.js'; | ||
@@ -8,0 +9,0 @@ import '../api/option.js'; |
@@ -1,1 +0,1 @@ | ||
import{a}from"../chunk-YAWKRTZW.js";import"../chunk-EQKNTHBH.js";import"../chunk-UYF2DHYU.js";import"../chunk-JZND3VTD.js";import"../chunk-OIGXPLZC.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{a as IatConnection}; | ||
import{a}from"../chunk-XAVWGTGE.js";import"../chunk-EQKNTHBH.js";import"../chunk-UYF2DHYU.js";import"../chunk-JZND3VTD.js";import"../chunk-NGEEV3H4.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{a as IatConnection}; |
@@ -7,2 +7,3 @@ export { IatConnection } from './connection.js'; | ||
import 'rxjs'; | ||
import 'rxjs/webSocket'; | ||
import '../api/status.js'; | ||
@@ -9,0 +10,0 @@ import '../api/option.js'; |
@@ -1,1 +0,1 @@ | ||
import"../chunk-E5GULNMT.js";import"../chunk-D55QM667.js";import{a as d}from"../chunk-YAWKRTZW.js";import{a}from"../chunk-EQKNTHBH.js";import{a as b,b as c}from"../chunk-UYF2DHYU.js";import"../chunk-JZND3VTD.js";import"../chunk-OIGXPLZC.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{d as IatConnection,a as IatOption,c as IatResponse,b as IatResponseDataStatus}; | ||
import"../chunk-E5GULNMT.js";import"../chunk-D55QM667.js";import{a as d}from"../chunk-XAVWGTGE.js";import{a}from"../chunk-EQKNTHBH.js";import{a as b,b as c}from"../chunk-UYF2DHYU.js";import"../chunk-JZND3VTD.js";import"../chunk-NGEEV3H4.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{d as IatConnection,a as IatOption,c as IatResponse,b as IatResponseDataStatus}; |
@@ -1,1 +0,1 @@ | ||
import{a,b}from"../chunk-UYF2DHYU.js";import"../chunk-JZND3VTD.js";import"../chunk-OIGXPLZC.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{b as IatResponse,a as IatResponseDataStatus}; | ||
import{a,b}from"../chunk-UYF2DHYU.js";import"../chunk-JZND3VTD.js";import"../chunk-NGEEV3H4.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{b as IatResponse,a as IatResponseDataStatus}; |
@@ -20,1 +20,2 @@ export { ApiConnection } from './api/connection.js'; | ||
import 'rxjs'; | ||
import 'rxjs/webSocket'; |
@@ -1,1 +0,1 @@ | ||
import"./chunk-E5GULNMT.js";import"./chunk-D55QM667.js";import"./chunk-DGPTPROM.js";import{a as i}from"./chunk-2LTLCENN.js";import{a as g,b as h}from"./chunk-GU2EGRFS.js";import{a as d}from"./chunk-HMTOY2UQ.js";import"./chunk-BSEC2ZXW.js";import{a as n}from"./chunk-YAWKRTZW.js";import{a as j}from"./chunk-EQKNTHBH.js";import{a as k,b as l}from"./chunk-UYF2DHYU.js";import"./chunk-JZND3VTD.js";import{a as c}from"./chunk-OIGXPLZC.js";import{a,b}from"./chunk-W4BRMK4G.js";import{a as o}from"./chunk-7ZEMB3HS.js";import{a as f}from"./chunk-N5NFW233.js";import{a as r,b as e}from"./chunk-IMAYVM2Y.js";import{a as x}from"./chunk-NP4EEY2K.js";import{a as p}from"./chunk-JDCMXEEN.js";import"./chunk-DYKUDQHN.js";import{a as t}from"./chunk-TU3JZGTL.js";import{a as m}from"./chunk-LIPHC4AO.js";export{c as ApiConnection,m as ApiConnectionStatus,p as ApiOption,t as ApiResponse,n as IatConnection,j as IatOption,l as IatResponse,k as IatResponseDataStatus,i as IseConnection,d as IseOption,h as IseResponse,g as IseResponseDataStatus,b as chuckDelay,a as chuckLength,e as from16BitPCM,o as resample,f as splitInChunks,r as to16BitPCM,x as toBase64}; | ||
import"./chunk-E5GULNMT.js";import"./chunk-D55QM667.js";import"./chunk-DGPTPROM.js";import{a as i}from"./chunk-REFWFXPX.js";import{a as g,b as h}from"./chunk-GU2EGRFS.js";import{a as d}from"./chunk-HMTOY2UQ.js";import"./chunk-BSEC2ZXW.js";import{a as n}from"./chunk-XAVWGTGE.js";import{a as j}from"./chunk-EQKNTHBH.js";import{a as k,b as l}from"./chunk-UYF2DHYU.js";import"./chunk-JZND3VTD.js";import{a as c}from"./chunk-NGEEV3H4.js";import{a,b}from"./chunk-W4BRMK4G.js";import{a as o}from"./chunk-7ZEMB3HS.js";import{a as f}from"./chunk-N5NFW233.js";import{a as r,b as e}from"./chunk-IMAYVM2Y.js";import{a as x}from"./chunk-NP4EEY2K.js";import{a as p}from"./chunk-JDCMXEEN.js";import"./chunk-DYKUDQHN.js";import{a as t}from"./chunk-TU3JZGTL.js";import{a as m}from"./chunk-LIPHC4AO.js";export{c as ApiConnection,m as ApiConnectionStatus,p as ApiOption,t as ApiResponse,n as IatConnection,j as IatOption,l as IatResponse,k as IatResponseDataStatus,i as IseConnection,d as IseOption,h as IseResponse,g as IseResponseDataStatus,b as chuckDelay,a as chuckLength,e as from16BitPCM,o as resample,f as splitInChunks,r as to16BitPCM,x as toBase64}; |
@@ -7,2 +7,3 @@ import { IseRequest, IseRequestBusinessCategory, IseRequestBusinessGroup, IseRequestBusinessLanguage } from './request.js'; | ||
import 'rxjs'; | ||
import 'rxjs/webSocket'; | ||
import '../api/status.js'; | ||
@@ -9,0 +10,0 @@ import '../api/request.js'; |
@@ -1,1 +0,1 @@ | ||
import{a}from"../chunk-2LTLCENN.js";import"../chunk-GU2EGRFS.js";import"../chunk-HMTOY2UQ.js";import"../chunk-JZND3VTD.js";import"../chunk-OIGXPLZC.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{a as IseConnection}; | ||
import{a}from"../chunk-REFWFXPX.js";import"../chunk-GU2EGRFS.js";import"../chunk-HMTOY2UQ.js";import"../chunk-JZND3VTD.js";import"../chunk-NGEEV3H4.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{a as IseConnection}; |
@@ -7,2 +7,3 @@ export { IseConnection } from './connection.js'; | ||
import 'rxjs'; | ||
import 'rxjs/webSocket'; | ||
import '../api/status.js'; | ||
@@ -9,0 +10,0 @@ import '../api/option.js'; |
@@ -1,1 +0,1 @@ | ||
import"../chunk-DGPTPROM.js";import{a as d}from"../chunk-2LTLCENN.js";import{a as b,b as c}from"../chunk-GU2EGRFS.js";import{a}from"../chunk-HMTOY2UQ.js";import"../chunk-BSEC2ZXW.js";import"../chunk-JZND3VTD.js";import"../chunk-OIGXPLZC.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{d as IseConnection,a as IseOption,c as IseResponse,b as IseResponseDataStatus}; | ||
import"../chunk-DGPTPROM.js";import{a as d}from"../chunk-REFWFXPX.js";import{a as b,b as c}from"../chunk-GU2EGRFS.js";import{a}from"../chunk-HMTOY2UQ.js";import"../chunk-BSEC2ZXW.js";import"../chunk-JZND3VTD.js";import"../chunk-NGEEV3H4.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{d as IseConnection,a as IseOption,c as IseResponse,b as IseResponseDataStatus}; |
@@ -1,1 +0,1 @@ | ||
import{a,b}from"../chunk-GU2EGRFS.js";import"../chunk-JZND3VTD.js";import"../chunk-OIGXPLZC.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{b as IseResponse,a as IseResponseDataStatus}; | ||
import{a,b}from"../chunk-GU2EGRFS.js";import"../chunk-JZND3VTD.js";import"../chunk-NGEEV3H4.js";import"../chunk-W4BRMK4G.js";import"../chunk-7ZEMB3HS.js";import"../chunk-N5NFW233.js";import"../chunk-IMAYVM2Y.js";import"../chunk-NP4EEY2K.js";import"../chunk-JDCMXEEN.js";import"../chunk-DYKUDQHN.js";import"../chunk-TU3JZGTL.js";import"../chunk-LIPHC4AO.js";export{b as IseResponse,a as IseResponseDataStatus}; |
{ | ||
"name": "xfyun-client", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Arumi Sakura", |
@@ -107,6 +107,18 @@ import { setTimeout } from 'timers/promises'; | ||
it('should throw error', async () => { | ||
it('should throw connection error', async () => { | ||
const statusSubscriber = jest.fn(); | ||
connection = new ApiConnection({ appId: 'abc', wsUrl: 'ws://notexist' }); | ||
connection.getStatus().subscribe(statusSubscriber); | ||
await expect(connection.connect()).rejects.toThrow(new Error('unable to connect')); | ||
expect(statusSubscriber).toHaveBeenNthCalledWith(1, ApiConnectionStatus.null); | ||
expect(statusSubscriber).toHaveBeenNthCalledWith(2, ApiConnectionStatus.init); | ||
expect(statusSubscriber).toHaveBeenNthCalledWith(3, ApiConnectionStatus.error); | ||
}); | ||
it('should throw error send by server', async () => { | ||
const statusSubscriber = jest.fn(); | ||
connection.getStatus().subscribe(statusSubscriber); | ||
await connection.connect(); | ||
@@ -113,0 +125,0 @@ |
@@ -1,2 +0,3 @@ | ||
import { BehaviorSubject, concatMap, delay, delayWhen, filter, finalize, firstValueFrom, Observable, of, Subject } from 'rxjs'; | ||
import { BehaviorSubject, concatMap, delay, filter, finalize, firstValueFrom, Observable, of, Subject } from 'rxjs'; | ||
import { webSocket, WebSocketSubject } from 'rxjs/webSocket'; | ||
import { resample } from '../utils/resample'; | ||
@@ -14,4 +15,4 @@ import { to16BitPCM } from '../utils/to16BitPCM'; | ||
protected option: O; | ||
protected webSocket!: WebSocket; | ||
protected response!: Res; | ||
protected $webSocket!: WebSocketSubject<Req | Res>; | ||
protected sid = ''; | ||
@@ -31,7 +32,2 @@ protected $status = new BehaviorSubject<ApiConnectionStatus>(ApiConnectionStatus.null); | ||
/** | ||
* Messages to send to WebSocket | ||
*/ | ||
protected $message = new Subject<string>(); | ||
protected Option(): O { | ||
@@ -55,10 +51,2 @@ return new ApiOption() as O; | ||
this.$chunked.subscribe((buffer) => this.sendAudio(buffer)); | ||
this.$message | ||
.pipe( | ||
delayWhen(() => this.$status.pipe(filter((status) => status === ApiConnectionStatus.ready || status === ApiConnectionStatus.ing))), | ||
) | ||
.subscribe((message) => { | ||
this.webSocket.send(message); | ||
}); | ||
} | ||
@@ -139,21 +127,23 @@ | ||
return new Promise<void>((resolve, reject) => { | ||
try { | ||
this.webSocket = new WebSocket(this.option.wsUrl); | ||
} catch (e: unknown) { | ||
reject(e); | ||
} | ||
this.setStatus(ApiConnectionStatus.init); | ||
this.$webSocket = webSocket({ | ||
url: this.option.wsUrl, | ||
openObserver: { | ||
next: () => { | ||
this.setStatus(ApiConnectionStatus.ready); | ||
resolve(); | ||
}, | ||
}, | ||
}); | ||
this.webSocket.onopen = () => { | ||
this.setStatus(ApiConnectionStatus.ready); | ||
resolve(); | ||
}; | ||
this.webSocket.onmessage = (event: MessageEvent<string>) => { | ||
const response = Object.assign(this.Response(), JSON.parse(event.data) as Res); | ||
this.setResponse(response); | ||
}; | ||
this.webSocket.onerror = () => { | ||
this.setStatus(ApiConnectionStatus.error); | ||
reject(new Error('unable to connect')); | ||
}; | ||
this.$webSocket.subscribe({ | ||
next: (msg) => { | ||
const response = Object.assign(this.Response(), msg); | ||
this.setResponse(response); | ||
}, | ||
error: () => { | ||
this.setStatus(ApiConnectionStatus.error); | ||
reject((this.error = new Error('unable to connect'))); | ||
}, | ||
}); | ||
}); | ||
@@ -192,3 +182,3 @@ } | ||
protected sendRequest(request: Req): void { | ||
this.$message.next(JSON.stringify(request)); | ||
this.$webSocket.next(request); | ||
} | ||
@@ -251,6 +241,6 @@ | ||
this.webSocket?.close(); | ||
this.$webSocket?.complete(); | ||
} | ||
} else { | ||
this.webSocket?.close(); | ||
this.$webSocket?.complete(); | ||
this.setStatus(ApiConnectionStatus.error); | ||
@@ -257,0 +247,0 @@ try { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances in 1 package
105105
1520