ptt
This commit is contained in:
parent
803fcb38d2
commit
5190f5d489
|
|
@ -204,7 +204,7 @@
|
|||
</div>
|
||||
|
||||
<div class="footer">
|
||||
Telewave SDK Connectivity v1.0
|
||||
SDK Connectivity v1.0
|
||||
</div>
|
||||
|
||||
<!-- 自定义“关于”弹窗 -->
|
||||
|
|
@ -657,12 +657,18 @@
|
|||
// 修复 PTT 按键逻辑:支持 TouchEvents 并处理异常中断
|
||||
if (pttBtn) {
|
||||
var isDown = false;
|
||||
var lastTouchTime = 0;
|
||||
|
||||
var startSpeak = function(e) {
|
||||
if (pttBtn.disabled) return;
|
||||
e.preventDefault();
|
||||
|
||||
var now = Date.now();
|
||||
if (now - lastTouchTime < 300) return; // 物理防抖:300ms 内禁止重复触发按下
|
||||
|
||||
if (!isDown) {
|
||||
isDown = true;
|
||||
lastTouchTime = now;
|
||||
pttBtn.style.background = "#b91c1c";
|
||||
pttBtn.innerText = "正在通话...";
|
||||
if (window.android && window.android.pttSpeakPlay) {
|
||||
|
|
@ -674,6 +680,9 @@
|
|||
|
||||
var stopSpeak = function(e) {
|
||||
if (isDown) {
|
||||
// 延迟 50ms 再处理释放,确保即使在极速点击下,Down 指令也先到达原生层
|
||||
setTimeout(function() {
|
||||
if (!isDown) return;
|
||||
isDown = false;
|
||||
pttBtn.style.background = "#ef4444";
|
||||
pttBtn.innerText = "长按对讲 (PTT)";
|
||||
|
|
@ -681,6 +690,7 @@
|
|||
window.android.pttSpeakRelease();
|
||||
}
|
||||
showPttResult("释放话权");
|
||||
}, 50);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -17,14 +17,8 @@ import org.json.JSONObject
|
|||
class AndroidInterface(private val activity: MainActivity) {
|
||||
|
||||
private var isSpeaking = false
|
||||
|
||||
/**
|
||||
* PTT 登录
|
||||
*/
|
||||
@JavascriptInterface
|
||||
fun pttLogin(account: String, pwd: String, ip: String) {
|
||||
SendAtUtil.toLogin(account, pwd, ip, 1, 1)
|
||||
}
|
||||
private var lastSpeakTime = 0L
|
||||
private val MIN_SPEAK_DURATION = 200L // 最小通话时长 200ms
|
||||
|
||||
/**
|
||||
* PTT 开始说话 (带状态保护)
|
||||
|
|
@ -33,6 +27,7 @@ class AndroidInterface(private val activity: MainActivity) {
|
|||
fun pttSpeakPlay() {
|
||||
if (!isSpeaking) {
|
||||
isSpeaking = true
|
||||
lastSpeakTime = System.currentTimeMillis()
|
||||
SendAtUtil.speakPlay()
|
||||
Timber.tag("PTT").d("Speak Play")
|
||||
}
|
||||
|
|
@ -43,10 +38,28 @@ class AndroidInterface(private val activity: MainActivity) {
|
|||
*/
|
||||
@JavascriptInterface
|
||||
fun pttSpeakRelease() {
|
||||
if (isSpeaking) {
|
||||
val now = System.currentTimeMillis()
|
||||
val duration = now - lastSpeakTime
|
||||
|
||||
if (duration < MIN_SPEAK_DURATION) {
|
||||
// 如果按得太快,延迟释放
|
||||
val delay = MIN_SPEAK_DURATION - duration
|
||||
Timber.tag("PTT").d("Speak duration too short ($duration ms), delaying release by $delay ms")
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
realRelease()
|
||||
}, delay)
|
||||
} else {
|
||||
realRelease()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun realRelease() {
|
||||
if (isSpeaking) {
|
||||
isSpeaking = false
|
||||
SendAtUtil.speakRelease()
|
||||
Timber.tag("PTT").d("Speak Release")
|
||||
Timber.tag("PTT").d("Real Speak Release")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue