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 @@
...
@@ -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>
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
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
;
}
}
...
...
src/renderer/plugins/live/PhotoRole.ts
View file @
b1b26209
...
@@ -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);
}
}
...
...
src/renderer/screens/ShowPhoto.vue
View file @
b1b26209
...
@@ -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
>
...
...
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 @@
...
@@ -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
,
...
...
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