Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CharIP-Electron
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ali
CharIP-Electron
Commits
b1b26209
Commit
b1b26209
authored
Dec 13, 2023
by
ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: sdk
parent
3b84df78
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
64 deletions
+58
-64
index.html
src/renderer/index.html
+1
-0
HwWebRTC.ts
src/renderer/plugins/live/HwWebRTC.ts
+3
-3
PhotoRole.ts
src/renderer/plugins/live/PhotoRole.ts
+47
-47
ShowPhoto.vue
src/renderer/screens/ShowPhoto.vue
+5
-13
export.ts
src/renderer/utils/HWLLS_SDK_Web_2.3.0/export.ts
+1
-0
index.ts
src/renderer/utils/HWLLS_SDK_Web_2.3.0/index.ts
+0
-1
tsconfig.json
tsconfig.json
+1
-0
No files found.
src/renderer/index.html
View file @
b1b26209
...
...
@@ -6,5 +6,6 @@
<body>
<div
id=
"app"
></div>
</body>
<!-- <script src="./utils/HWLLS_SDK_Web_2.3.0/lib/HWLLSPlayer.js"></script> -->
<script
type=
"module"
src=
"./main.ts"
></script>
</html>
src/renderer/plugins/live/HwWebRTC.ts
View file @
b1b26209
import
HWLLSSDK
from
'@/renderer/utils/HWLLS_SDK_Web_2.3.0'
;
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 {
*/
static
async
isBrowserSupport
()
{
let
check
=
false
;
check
=
await
HWLLSSDK
.
checkSystemRequirements
();
check
=
await
(
window
as
any
).
HWLLSSDK
.
default
.
checkSystemRequirements
();
return
check
;
}
...
...
src/renderer/plugins/live/PhotoRole.ts
View file @
b1b26209
...
...
@@ -85,7 +85,7 @@ export class PhotoRole extends EventEmitter {
private
_liveStatus
:
'init'
|
'ready'
|
'wait'
|
'closing'
|
'pushing'
=
'closing'
;
private
_pollTimeout
=
-
1
;
private
_
answerArgs
:
PhotoAnswer
|
null
=
null
;
answerArgs
:
PhotoAnswer
|
null
=
null
;
readonly
url
:
string
;
readonly
sessionId
=
guid
();
...
...
@@ -100,7 +100,7 @@ export class PhotoRole extends EventEmitter {
// type: 'photo',
// callbacks: {
// chatConnect: (ans) => {
// this.
_
answerArgs = ans;
// this.answerArgs = ans;
// console.time('chat');
// },
// chatEnd: (ans) => {
...
...
@@ -148,7 +148,7 @@ export class PhotoRole extends EventEmitter {
while
(
this
.
_liveTaskQueue
.
length
)
{
const
task
=
this
.
_liveTaskQueue
.
shift
()
as
LiveOptions
;
console
.
time
(
task
.
text
);
if
(
this
.
_liveStatus
===
'closing'
)
await
this
.
_
initLive
();
if
(
this
.
_liveStatus
===
'closing'
)
await
this
.
initLive
();
await
this
.
_createLive
(
task
);
...
...
@@ -162,31 +162,31 @@ export class PhotoRole extends EventEmitter {
}
private
async
_liveStatusTrace
()
{
if
(
!
this
.
_
answerArgs
)
return
;
if
(
!
this
.
answerArgs
)
return
;
if
(
this
.
_liveStatus
===
'pushing'
)
{
this
.
_
answerArgs
.
playState
=
'playing'
;
this
.
answerArgs
.
playState
=
'playing'
;
this
.
_typingOutAnswer
();
return
;
}
if
(
this
.
_liveStatus
===
'wait'
)
{
this
.
_
answerArgs
.
playState
=
'pause'
;
this
.
emit
(
'asyncAnswer'
,
this
.
_
answerArgs
)
this
.
answerArgs
.
playState
=
'pause'
;
this
.
emit
(
'asyncAnswer'
,
this
.
answerArgs
)
}
}
private
_typingRunner
=
false
;
private
async
_typingOutAnswer
()
{
if
(
!
this
.
_
answerArgs
||
this
.
_typingRunner
)
return
;
if
(
!
this
.
answerArgs
||
this
.
_typingRunner
)
return
;
this
.
_typingRunner
=
true
;
// 加延迟是为了 playing 状态时,能跟声音保持相对同步
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
2000
));
while
(
this
.
_
answerArgs
.
_typingAnswer
.
length
)
{
this
.
_answerArgs
.
asyncAnswer
+=
this
.
_
answerArgs
.
_typingAnswer
.
shift
();
this
.
emit
(
'asyncAnswer'
,
this
.
_
answerArgs
)
while
(
this
.
answerArgs
.
_typingAnswer
.
length
)
{
this
.
answerArgs
.
asyncAnswer
+=
this
.
answerArgs
.
_typingAnswer
.
shift
();
this
.
emit
(
'asyncAnswer'
,
this
.
answerArgs
)
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
100
));
}
...
...
@@ -195,28 +195,28 @@ export class PhotoRole extends EventEmitter {
private
_play
(
url
:
string
)
{
return
new
Promise
<
void
>
((
resolve
)
=>
{
if
(
!
this
.
_rtc
)
return
;
let
isPlaying
=
false
;
let
timeout
=
-
1
;
this
.
_rtc
.
once
(
'videoStart'
,
()
=>
{
isPlaying
=
true
;
clearTimeout
(
timeout
);
resolve
();
});
//
if (!this._rtc) return;
//
let isPlaying = false;
//
let timeout = -1;
//
this._rtc.once('videoStart', () => {
//
isPlaying = true;
//
clearTimeout(timeout);
//
resolve();
//
});
const
keepCalling
=
async
()
=>
{
if
(
isPlaying
)
return
;
try
{
await
this
.
_rtc
?.
startPlay
(
url
);
if
(
!
isPlaying
)
{
timeout
=
setTimeout
(
keepCalling
,
400
)
as
unknown
as
number
;
}
}
catch
(
error
)
{
timeout
=
setTimeout
(
keepCalling
,
200
)
as
unknown
as
number
;
}
};
keepCalling
();
//
const keepCalling = async () => {
//
if (isPlaying) return;
//
try {
//
await this._rtc?.startPlay(url);
//
if (!isPlaying) {
//
timeout = setTimeout(keepCalling, 400) as unknown as number;
//
}
//
} catch (error) {
//
timeout = setTimeout(keepCalling, 200) as unknown as number;
//
}
//
};
//
keepCalling();
});
}
...
...
@@ -331,7 +331,7 @@ export class PhotoRole extends EventEmitter {
keepCalling
();
}
private
async
_
initLive
()
{
async
initLive
()
{
console
.
time
(
'init'
);
console
.
time
(
'init-_createLive'
);
...
...
@@ -365,18 +365,18 @@ export class PhotoRole extends EventEmitter {
}
private
_bindEvents
()
{
this
.
_rtc
?.
on
(
'videoStart'
,
()
=>
{
this
.
emit
(
'videoStart'
);
});
this
.
_rtc
?.
on
(
'audioStart'
,
()
=>
{
this
.
emit
(
'audioStart'
);
});
this
.
_rtc
?.
on
(
'audioBroken'
,
()
=>
{
this
.
emit
(
'audioBroken'
);
});
this
.
_rtc
?.
on
(
'videoBroken'
,
()
=>
{
this
.
emit
(
'videoBroken'
);
});
//
this._rtc?.on('videoStart', () => {
//
this.emit('videoStart');
//
});
//
this._rtc?.on('audioStart', () => {
//
this.emit('audioStart');
//
});
//
this._rtc?.on('audioBroken', () => {
//
this.emit('audioBroken');
//
});
//
this._rtc?.on('videoBroken', () => {
//
this.emit('videoBroken');
//
});
}
/**
...
...
@@ -427,7 +427,7 @@ export class PhotoRole extends EventEmitter {
this
.
_rtc
=
new
HwWebRTC
(
this
.
_webRTCContainer
.
id
);
this
.
_bindEvents
();
await
this
.
_
initLive
();
await
this
.
initLive
();
// this._pollStatus(this.sessionId);
}
...
...
src/renderer/screens/ShowPhoto.vue
View file @
b1b26209
...
...
@@ -11,6 +11,7 @@ import type {
import
{
audioAiTTS
,
localTTS
}
from
'../plugins/tts'
import
useStore
from
'@/renderer/store'
import
flvjs
from
'flv.js'
import
{
PhotoRole
}
from
'@/renderer/plugins/live/PhotoRole'
;
const
router
=
useRouter
()
const
route
=
useRoute
()
...
...
@@ -24,6 +25,7 @@ const url = route.query.url as string
const
microphoneState
=
ref
<
'waitInput'
|
'input'
|
'loading'
|
'disabled'
>
(
'waitInput'
)
const
videoElement
=
ref
<
HTMLVideoElement
|
null
>
(
null
)
const
can
=
ref
<
HTMLCanvasElement
|
null
>
(
null
)
let
photoRole
:
PhotoRole
|
null
=
null
;
let
flvPlayer
:
flvjs
.
Player
|
null
=
null
onMounted
(()
=>
{
...
...
@@ -49,6 +51,7 @@ async function init() {
draw
(
ctx
,
img
)
canvasEle
.
width
=
img
.
naturalWidth
canvasEle
.
height
=
img
.
naturalHeight
photoRole
=
new
PhotoRole
(
url
,
canvasEle
);
// initPlayer(videoEle);
...
...
@@ -71,6 +74,8 @@ async function init() {
requestAnimationFrame
(
updateFrame
)
}
requestAnimationFrame
(
updateFrame
)
await
photoRole
.
initLive
();
}
function
draw
(
...
...
@@ -448,19 +453,6 @@ async function runAudioPlay() {
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
>
<
template
>
...
...
src/renderer/utils/HWLLS_SDK_Web_2.3.0/export.ts
0 → 100644
View file @
b1b26209
export
*
from
'./lib/HWLLSPlayer'
;
\ No newline at end of file
src/renderer/utils/HWLLS_SDK_Web_2.3.0/index.ts
deleted
100644 → 0
View file @
3b84df78
export
*
as
HWLLSSDK
from
'./lib/HWLLSPlayer'
;
\ No newline at end of file
tsconfig.json
View file @
b1b26209
...
...
@@ -7,6 +7,7 @@
"moduleResolution"
:
"node"
,
"jsx"
:
"preserve"
,
"allowJs"
:
true
,
"checkJs"
:
false
,
"noImplicitAny"
:
false
,
"allowSyntheticDefaultImports"
:
true
,
"declaration"
:
true
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment