forked from Blendman974/faceclaw
Add cloud voice model support for iOS
This commit is contained in:
1 parent
5df873e5b1
commit
920cce6a26
24 files changed
+518
-176
No files matched your search
@@ -1,7 +1,7 @@
|
||||
export type SocketListener = { onOpen(): void; onTextMessage(message: string): void; onClosed(code: number, reason: string): void; onFailure(message: string): void }
|
||||
import type { SocketConnection, SocketHeader, SocketListener } from './socket'
|
||||
declare const FaceclawSocket: any
|
||||
export function openSocket(url: string, listener: SocketListener): { sendText(text: string): void; close(code: number, reason: string): void } {
|
||||
const native = FaceclawSocket.alloc().initWithURL(url)
|
||||
export function openSocket(url: string, listener: SocketListener, header?: SocketHeader): SocketConnection {
|
||||
const native = FaceclawSocket.alloc().initWithURLHeaderNameHeaderValue(url, header?.name ?? null, header?.value ?? null)
|
||||
let ended = false
|
||||
const close = () => { if (ended) return; ended = true; clearInterval(timer); native.close() }
|
||||
const timer = setInterval(() => {
|
||||
@@ -12,5 +12,15 @@ export function openSocket(url: string, listener: SocketListener): { sendText(te
|
||||
else { close(); if (event.kind === 'closed') listener.onClosed(event.code, event.text); else listener.onFailure(event.text) }
|
||||
}
|
||||
}, 25)
|
||||
return { sendText: text => { if (!ended) native.sendText(text) }, close }
|
||||
// NSURLSession queues every send; a failed one surfaces as an error event.
|
||||
return {
|
||||
sendText: text => { if (!ended) native.sendText(text); return !ended },
|
||||
sendBinary: bytes => {
|
||||
if (ended) return false
|
||||
const copy = bytes.slice()
|
||||
native.sendData(NSData.dataWithBytesLength(interop.handleof(copy.buffer), copy.byteLength))
|
||||
return true
|
||||
},
|
||||
close,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user