From b6a5c2cc95b6d7a3c8aa7e911839531c26570bd5 Mon Sep 17 00:00:00 2001 From: Craig Date: Tue, 11 Feb 2020 18:43:31 +0000 Subject: [PATCH] live resolution complete --- client/src/components/resolution.vue | 17 ++++++++--------- client/src/components/video.vue | 2 +- client/src/neko/messages.ts | 7 ++----- client/src/neko/types.ts | 14 ++++++++++---- client/src/store/video.ts | 28 +++++++++++++++++++++++----- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/client/src/components/resolution.vue b/client/src/components/resolution.vue index ad58e456..e5b60f14 100644 --- a/client/src/components/resolution.vue +++ b/client/src/components/resolution.vue @@ -2,14 +2,13 @@ @@ -60,7 +59,7 @@ align-content: center; display: flex; flex-direction: row; - padding: 8px 5px; + padding: 8px; cursor: pointer; border-radius: 3px; @@ -99,7 +98,7 @@ diff --git a/client/src/components/video.vue b/client/src/components/video.vue index c1f70c99..93a80feb 100644 --- a/client/src/components/video.vue +++ b/client/src/components/video.vue @@ -30,7 +30,7 @@ diff --git a/client/src/neko/messages.ts b/client/src/neko/messages.ts index f08e61f6..5c9b419b 100644 --- a/client/src/neko/messages.ts +++ b/client/src/neko/messages.ts @@ -10,7 +10,7 @@ import { ScreenEvents, AdminEvents, } from './events' -import { Member, ScreenConfigurations } from './types' +import { Member, ScreenConfigurations, ScreenResolution } from './types' export type WebSocketMessages = | WebSocketMessage @@ -157,11 +157,8 @@ export interface ScreenResolutionMessage extends WebSocketMessage, ScreenResolut event: ScreenEvents } -export interface ScreenResolutionPayload { +export interface ScreenResolutionPayload extends ScreenResolution { id?: string - width: number - height: number - rate: number } export interface ScreenConfigurationsMessage extends WebSocketMessage, ScreenConfigurationsPayload { diff --git a/client/src/neko/types.ts b/client/src/neko/types.ts index ec3e4559..af1d4b3b 100644 --- a/client/src/neko/types.ts +++ b/client/src/neko/types.ts @@ -8,11 +8,17 @@ export interface Member { } export interface ScreenConfigurations { - [index: number]: ScreenConfiguration + [index: string]: ScreenConfiguration } export interface ScreenConfiguration { - width: string - height: string - rates: { [index: number]: number } + width: number + height: number + rates: { [index: string]: number } +} + +export interface ScreenResolution { + width: number + height: number + rate: number } diff --git a/client/src/store/video.ts b/client/src/store/video.ts index 2c1adac3..b8b83857 100644 --- a/client/src/store/video.ts +++ b/client/src/store/video.ts @@ -1,7 +1,7 @@ import { getterTree, mutationTree, actionTree } from 'typed-vuex' import { get, set } from '~/utils/localstorage' import { EVENT } from '~/neko/events' -import { ScreenConfigurations } from '~/neko/types' +import { ScreenConfigurations, ScreenResolution } from '~/neko/types' import { accessor } from '~/store' export const namespaced = true @@ -10,7 +10,7 @@ export const state = () => ({ index: -1, tracks: [] as MediaStreamTrack[], streams: [] as MediaStream[], - configurations: {} as ScreenConfigurations, + configurations: [] as ScreenResolution[], width: 1280, height: 720, rate: 30, @@ -99,7 +99,25 @@ export const mutations = mutationTree(state, { }, setConfigurations(state, configurations: ScreenConfigurations) { - state.configurations = configurations + const data: ScreenResolution[] = [] + + for (const i of Object.keys(configurations)) { + const { width, height, rates } = configurations[i] + if (width >= 600 && height >= 300) { + for (const j of Object.keys(rates)) { + const rate = rates[j] + if (rate >= 15 && rate <= 60) { + data.push({ + width, + height, + rate, + }) + } + } + } + } + + state.configurations = data.sort((a, b) => (b.width === a.width ? b.rate - a.rate : b.width - a.width)) }, setVolume(state, volume: number) { @@ -155,12 +173,12 @@ export const actions = actionTree( $client.sendMessage(EVENT.SCREEN.RESOLUTION) }, - screenSet({ state }, { width, height, rate }: { width: number; height: number; rate: number }) { + screenSet({ state }, resolution: ScreenResolution) { if (!accessor.connected || !accessor.user.admin) { return } - $client.sendMessage(EVENT.SCREEN.SET, { width, height, rate }) + $client.sendMessage(EVENT.SCREEN.SET, resolution) }, }, )