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