@@ -12,10 +12,17 @@ const curStream = ref<MediaStream>()
1212// 当前音视频设备
1313const curVideoDevInfo = ref ({ id: undefined , label: undefined })
1414const curAudioDevInfo = ref ({ id: undefined , label: undefined })
15+ const curResolution = ref (' 4K_priority' )
1516
1617// 可选音视频设备
1718const videoDevList = ref <Array <any >>([])
1819const audioDevList = ref <Array <any >>([])
20+ const resolutionList = ref <Array <any >>([
21+ ' 4K_priority' ,
22+ ' 2K_priority' ,
23+ ' 1080P_priority' ,
24+ ' 720P_priority'
25+ ])
1926
2027const isOpenAudio = ref (true )
2128
@@ -261,8 +268,31 @@ function closeStream() {
261268async function refreshStream() {
262269 closeStream ()
263270 try {
271+ // 解析分辨率
272+ let idealWidth = 3840
273+ let idealHeight = 2160
274+ if (curResolution .value === ' 2K_priority' ) {
275+ idealWidth = 2560
276+ idealHeight = 1440
277+ } else if (curResolution .value === ' 1080P_priority' ) {
278+ idealWidth = 1920
279+ idealHeight = 1080
280+ } else if (curResolution .value === ' 720P_priority' ) {
281+ idealWidth = 1280
282+ idealHeight = 720
283+ }
284+ // 如果是移动端,则翻转宽高
285+ // if (window.innerHeight > window.innerWidth) {
286+ // const tmp = idealWidth
287+ // idealWidth = idealHeight
288+ // idealHeight = tmp
289+ // }
264290 curStream .value = await navigator ?.mediaDevices ?.getUserMedia ({
265- video: { deviceId: curVideoDevInfo .value .id },
291+ video: {
292+ deviceId: curVideoDevInfo .value .id ,
293+ width: { ideal: idealWidth },
294+ height: { ideal: idealHeight }
295+ },
266296 audio: isOpenAudio .value ? { deviceId: curAudioDevInfo .value .id } : false
267297 })
268298 if (! curStream .value ) {
@@ -290,6 +320,7 @@ async function refreshStream() {
290320 })
291321 localStorage .setItem (' audioDev' , JSON .stringify (curAudioDevInfo .value ))
292322 }
323+ localStorage .setItem (' videoResolution' , curResolution .value )
293324 videoElm .value .srcObject = curStream .value
294325 } catch (e ) {
295326 logInfo .value .logs .push ({
@@ -328,6 +359,10 @@ onMounted(async () => {
328359 if (tmpDev ) {
329360 curAudioDevInfo .value = JSON .parse (tmpDev )
330361 }
362+ let tmpResolution = localStorage .getItem (' videoResolution' )
363+ if (tmpResolution ) {
364+ curResolution .value = tmpResolution
365+ }
331366
332367 // 更新媒体流
333368 if (! (await refreshStream ())) {
@@ -364,6 +399,7 @@ onMounted(async () => {
364399
365400 watch (curAudioDevInfo , refreshStream )
366401 watch (curVideoDevInfo , refreshStream )
402+ watch (curResolution , refreshStream )
367403 watch (isOpenAudio , refreshStream )
368404
369405 // 获取上次使用的连接ID
@@ -399,15 +435,27 @@ onUnmounted(() => {
399435 <div class =" bg-neutral-50 dark:bg-black" :style =" { 'padding-top': navHeight + 'px' }" >
400436 <div class =" overflow-y-auto md:flex md:flex-row p-4" >
401437 <div class =" md:flex-1 md:p-4 space-y-4" >
438+ <!-- 选择视频设备 -->
402439 <UFormGroup :label =" $t('label.videoDev')" >
403440 <USelectMenu :options =" videoDevList" v-model =" curVideoDevInfo" :disabled =" isConnecting" />
404441 </UFormGroup >
442+
443+ <UFormGroup :label =" $t('label.resolution')" >
444+ <USelectMenu :options =" resolutionList" v-model =" curResolution" :disabled =" isConnecting" >
445+ <template #label >{{ $t('label.' + curResolution) }}</template >
446+ <template #option =" opt " >{{ $t('label.' + opt.option) }}</template >
447+ </USelectMenu >
448+ </UFormGroup >
449+
450+ <!-- 选择音频设备 -->
405451 <UFormGroup :label =" $t('label.audioDev')" >
406452 <USelectMenu
407453 :options =" audioDevList"
408454 v-model =" curAudioDevInfo"
409455 :disabled =" !isOpenAudio || isConnecting"
410456 />
457+
458+ <!-- 是否启用音频 -->
411459 </UFormGroup >
412460 <div class =" flex flex-row items-center justify-end gap-4 text-sm" >
413461 <label class =" contents" >
@@ -416,6 +464,7 @@ onUnmounted(() => {
416464 </label >
417465 </div >
418466
467+ <!-- 连接ID -->
419468 <UFormGroup :label =" $t('label.connectionID')" >
420469 <UInput
421470 :type =" isShowConnectId ? 'text' : 'password'"
0 commit comments