Commit b1b26209 authored by ali's avatar ali

feat: sdk

parent 3b84df78
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
<body> <body>
<div id="app"></div> <div id="app"></div>
</body> </body>
<!-- <script src="./utils/HWLLS_SDK_Web_2.3.0/lib/HWLLSPlayer.js"></script> -->
<script type="module" src="./main.ts"></script> <script type="module" src="./main.ts"></script>
</html> </html>
import HWLLSSDK from '@/renderer/utils/HWLLS_SDK_Web_2.3.0';
import EventEmitter from 'events'; import EventEmitter from 'events';
// import { HWLLSSDK } from '@/renderer/utils/HWLLS_SDK_Web_2.3.0/export';
const { createClient, setLogLevel } = HWLLSSDK; const { createClient, setLogLevel } = (window as any).HWLLSSDK.default;
/** /**
* *
...@@ -97,7 +97,7 @@ export class HwWebRTC extends EventEmitter { ...@@ -97,7 +97,7 @@ export class HwWebRTC extends EventEmitter {
*/ */
static async isBrowserSupport() { static async isBrowserSupport() {
let check = false; let check = false;
check = await HWLLSSDK.checkSystemRequirements(); check = await (window as any).HWLLSSDK.default.checkSystemRequirements();
return check; return check;
} }
......
...@@ -85,7 +85,7 @@ export class PhotoRole extends EventEmitter { ...@@ -85,7 +85,7 @@ export class PhotoRole extends EventEmitter {
private _liveStatus: 'init' | 'ready' | 'wait' | 'closing' | 'pushing' = 'closing'; private _liveStatus: 'init' | 'ready' | 'wait' | 'closing' | 'pushing' = 'closing';
private _pollTimeout = -1; private _pollTimeout = -1;
private _answerArgs: PhotoAnswer | null = null; answerArgs: PhotoAnswer | null = null;
readonly url: string; readonly url: string;
readonly sessionId = guid(); readonly sessionId = guid();
...@@ -100,7 +100,7 @@ export class PhotoRole extends EventEmitter { ...@@ -100,7 +100,7 @@ export class PhotoRole extends EventEmitter {
// type: 'photo', // type: 'photo',
// callbacks: { // callbacks: {
// chatConnect: (ans) => { // chatConnect: (ans) => {
// this._answerArgs = ans; // this.answerArgs = ans;
// console.time('chat'); // console.time('chat');
// }, // },
// chatEnd: (ans) => { // chatEnd: (ans) => {
...@@ -148,7 +148,7 @@ export class PhotoRole extends EventEmitter { ...@@ -148,7 +148,7 @@ export class PhotoRole extends EventEmitter {
while (this._liveTaskQueue.length) { while (this._liveTaskQueue.length) {
const task = this._liveTaskQueue.shift() as LiveOptions; const task = this._liveTaskQueue.shift() as LiveOptions;
console.time(task.text); console.time(task.text);
if (this._liveStatus === 'closing') await this._initLive(); if (this._liveStatus === 'closing') await this.initLive();
await this._createLive(task); await this._createLive(task);
...@@ -162,31 +162,31 @@ export class PhotoRole extends EventEmitter { ...@@ -162,31 +162,31 @@ export class PhotoRole extends EventEmitter {
} }
private async _liveStatusTrace() { private async _liveStatusTrace() {
if (!this._answerArgs) return; if (!this.answerArgs) return;
if (this._liveStatus === 'pushing') { if (this._liveStatus === 'pushing') {
this._answerArgs.playState = 'playing'; this.answerArgs.playState = 'playing';
this._typingOutAnswer(); this._typingOutAnswer();
return; return;
} }
if (this._liveStatus === 'wait') { if (this._liveStatus === 'wait') {
this._answerArgs.playState = 'pause'; this.answerArgs.playState = 'pause';
this.emit('asyncAnswer', this._answerArgs) this.emit('asyncAnswer', this.answerArgs)
} }
} }
private _typingRunner = false; private _typingRunner = false;
private async _typingOutAnswer() { private async _typingOutAnswer() {
if (!this._answerArgs || this._typingRunner) return; if (!this.answerArgs || this._typingRunner) return;
this._typingRunner = true; this._typingRunner = true;
// 加延迟是为了 playing 状态时,能跟声音保持相对同步 // 加延迟是为了 playing 状态时,能跟声音保持相对同步
await new Promise((resolve) => setTimeout(resolve, 2000)); await new Promise((resolve) => setTimeout(resolve, 2000));
while (this._answerArgs._typingAnswer.length) { while (this.answerArgs._typingAnswer.length) {
this._answerArgs.asyncAnswer += this._answerArgs._typingAnswer.shift(); this.answerArgs.asyncAnswer += this.answerArgs._typingAnswer.shift();
this.emit('asyncAnswer', this._answerArgs) this.emit('asyncAnswer', this.answerArgs)
await new Promise((resolve) => setTimeout(resolve, 100)); await new Promise((resolve) => setTimeout(resolve, 100));
} }
...@@ -195,28 +195,28 @@ export class PhotoRole extends EventEmitter { ...@@ -195,28 +195,28 @@ export class PhotoRole extends EventEmitter {
private _play(url: string) { private _play(url: string) {
return new Promise<void>((resolve) => { return new Promise<void>((resolve) => {
if (!this._rtc) return; // if (!this._rtc) return;
let isPlaying = false; // let isPlaying = false;
let timeout = -1; // let timeout = -1;
this._rtc.once('videoStart', () => { // this._rtc.once('videoStart', () => {
isPlaying = true; // isPlaying = true;
clearTimeout(timeout); // clearTimeout(timeout);
resolve(); // resolve();
}); // });
const keepCalling = async () => { // const keepCalling = async () => {
if (isPlaying) return; // if (isPlaying) return;
try { // try {
await this._rtc?.startPlay(url); // await this._rtc?.startPlay(url);
if (!isPlaying) { // if (!isPlaying) {
timeout = setTimeout(keepCalling, 400) as unknown as number; // timeout = setTimeout(keepCalling, 400) as unknown as number;
} // }
} catch (error) { // } catch (error) {
timeout = setTimeout(keepCalling, 200) as unknown as number; // timeout = setTimeout(keepCalling, 200) as unknown as number;
} // }
}; // };
keepCalling(); // keepCalling();
}); });
} }
...@@ -331,7 +331,7 @@ export class PhotoRole extends EventEmitter { ...@@ -331,7 +331,7 @@ export class PhotoRole extends EventEmitter {
keepCalling(); keepCalling();
} }
private async _initLive() { async initLive() {
console.time('init'); console.time('init');
console.time('init-_createLive'); console.time('init-_createLive');
...@@ -365,18 +365,18 @@ export class PhotoRole extends EventEmitter { ...@@ -365,18 +365,18 @@ export class PhotoRole extends EventEmitter {
} }
private _bindEvents() { private _bindEvents() {
this._rtc?.on('videoStart', () => { // this._rtc?.on('videoStart', () => {
this.emit('videoStart'); // this.emit('videoStart');
}); // });
this._rtc?.on('audioStart', () => { // this._rtc?.on('audioStart', () => {
this.emit('audioStart'); // this.emit('audioStart');
}); // });
this._rtc?.on('audioBroken', () => { // this._rtc?.on('audioBroken', () => {
this.emit('audioBroken'); // this.emit('audioBroken');
}); // });
this._rtc?.on('videoBroken', () => { // this._rtc?.on('videoBroken', () => {
this.emit('videoBroken'); // this.emit('videoBroken');
}); // });
} }
/** /**
...@@ -427,7 +427,7 @@ export class PhotoRole extends EventEmitter { ...@@ -427,7 +427,7 @@ export class PhotoRole extends EventEmitter {
this._rtc = new HwWebRTC(this._webRTCContainer.id); this._rtc = new HwWebRTC(this._webRTCContainer.id);
this._bindEvents(); this._bindEvents();
await this._initLive(); await this.initLive();
// this._pollStatus(this.sessionId); // this._pollStatus(this.sessionId);
} }
......
...@@ -11,6 +11,7 @@ import type { ...@@ -11,6 +11,7 @@ import type {
import { audioAiTTS, localTTS } from '../plugins/tts' import { audioAiTTS, localTTS } from '../plugins/tts'
import useStore from '@/renderer/store' import useStore from '@/renderer/store'
import flvjs from 'flv.js' import flvjs from 'flv.js'
import { PhotoRole } from '@/renderer/plugins/live/PhotoRole';
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()
...@@ -24,6 +25,7 @@ const url = route.query.url as string ...@@ -24,6 +25,7 @@ const url = route.query.url as string
const microphoneState = ref<'waitInput' | 'input' | 'loading' | 'disabled'>('waitInput') const microphoneState = ref<'waitInput' | 'input' | 'loading' | 'disabled'>('waitInput')
const videoElement = ref<HTMLVideoElement | null>(null) const videoElement = ref<HTMLVideoElement | null>(null)
const can = ref<HTMLCanvasElement | null>(null) const can = ref<HTMLCanvasElement | null>(null)
let photoRole: PhotoRole | null = null;
let flvPlayer: flvjs.Player | null = null let flvPlayer: flvjs.Player | null = null
onMounted(() => { onMounted(() => {
...@@ -49,6 +51,7 @@ async function init() { ...@@ -49,6 +51,7 @@ async function init() {
draw(ctx, img) draw(ctx, img)
canvasEle.width = img.naturalWidth canvasEle.width = img.naturalWidth
canvasEle.height = img.naturalHeight canvasEle.height = img.naturalHeight
photoRole = new PhotoRole(url, canvasEle);
// initPlayer(videoEle); // initPlayer(videoEle);
...@@ -71,6 +74,8 @@ async function init() { ...@@ -71,6 +74,8 @@ async function init() {
requestAnimationFrame(updateFrame) requestAnimationFrame(updateFrame)
} }
requestAnimationFrame(updateFrame) requestAnimationFrame(updateFrame)
await photoRole.initLive();
} }
function draw( function draw(
...@@ -448,19 +453,6 @@ async function runAudioPlay() { ...@@ -448,19 +453,6 @@ async function runAudioPlay() {
await audio.play() await audio.play()
} }
// eslint-disable-next-line no-unused-vars
async function xfTTS(text: string) {
const tone = settings.source.find(({ sourceId }) => settings.selectSource === sourceId)
if (!tone) return
const res = await audioAiTTS({
host: settings.ttsHost,
text,
speed: 3,
speaker: tone.sourceId,
provider: tone.provider
})
console.log('----------------> tts:', res)
}
</script> </script>
<template> <template>
......
export * from './lib/HWLLSPlayer';
\ No newline at end of file
export * as HWLLSSDK from './lib/HWLLSPlayer';
\ No newline at end of file
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"moduleResolution": "node", "moduleResolution": "node",
"jsx": "preserve", "jsx": "preserve",
"allowJs": true, "allowJs": true,
"checkJs": false,
"noImplicitAny": false, "noImplicitAny": false,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"declaration": true, "declaration": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment