feat: 增加分辨率修改
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { encodeControlMessage } from '../proto/controlMessage';
|
||||
import { encodeControlMessage, decodeControlMessage, Action } from '../proto/controlMessage';
|
||||
|
||||
// 对应 Android 端 WebRtcClient / Flutter webrtc_controller.dart。
|
||||
// 作为 OFFER 方:仅接收远端视频(recvonly)+ 创建控制用 DataChannel,
|
||||
@@ -6,7 +6,7 @@ import { encodeControlMessage } from '../proto/controlMessage';
|
||||
const DATA_CHANNEL_LABEL = 'control_channel';
|
||||
|
||||
export class WebRtcController {
|
||||
constructor({ iceServers, deviceId, targetDeviceId, signaling, onIceState, onDataChannelState, onStream, onStats, onError }) {
|
||||
constructor({ iceServers, deviceId, targetDeviceId, signaling, onIceState, onDataChannelState, onStream, onStats, onError, onResolutionReport }) {
|
||||
this.iceServers = iceServers;
|
||||
this.deviceId = deviceId;
|
||||
this.targetDeviceId = targetDeviceId;
|
||||
@@ -16,6 +16,7 @@ export class WebRtcController {
|
||||
this.onStream = onStream;
|
||||
this.onStats = onStats;
|
||||
this.onError = onError;
|
||||
this.onResolutionReport = onResolutionReport;
|
||||
|
||||
this.pc = null;
|
||||
this.dataChannel = null;
|
||||
@@ -96,7 +97,22 @@ export class WebRtcController {
|
||||
this.dataChannel = dc;
|
||||
dc.onopen = () => this.onDataChannelState && this.onDataChannelState(true);
|
||||
dc.onclose = () => this.onDataChannelState && this.onDataChannelState(false);
|
||||
dc.onmessage = (e) => console.debug('[DataChannel] 收到消息', e.data);
|
||||
dc.onmessage = (e) => {
|
||||
try {
|
||||
// 被控端发来的是二进制 protobuf(目前仅 REPORT_RESOLUTION 上报)。
|
||||
const bytes = e.data instanceof ArrayBuffer ? new Uint8Array(e.data) : e.data;
|
||||
const msg = decodeControlMessage(bytes);
|
||||
if (msg && msg.action === Action.REPORT_RESOLUTION) {
|
||||
this.onResolutionReport && this.onResolutionReport({
|
||||
width: msg.width | 0,
|
||||
height: msg.height | 0,
|
||||
fps: msg.fps | 0,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.debug('[DataChannel] 解码消息失败(非分辨率上报或格式异常)', err);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async handleAnswer(sdp) {
|
||||
@@ -147,6 +163,7 @@ export class WebRtcController {
|
||||
sendKey(keyCode) { return this.sendControlMessage({ action: 3, keyCode, keyAction: 0 }); } // KEY
|
||||
sendLongPress(x, y) { return this.sendControlMessage({ action: 4, x, y }); } // LONG_PRESS
|
||||
sendMotionEvent(action, x, y) { return this.sendControlMessage({ action: 5, motionAction: action, x, y }); } // MOTION_EVENT
|
||||
sendResolutionChange(width, height, fps) { return this.sendControlMessage({ action: 6, width, height, fps }); } // SET_RESOLUTION
|
||||
|
||||
_startStats() {
|
||||
this._statsTimer = setInterval(async () => {
|
||||
|
||||
Reference in New Issue
Block a user