refactor: use moonraker webcam api instead of direct DB access (#1445)

This commit is contained in:
Stefan Dej authored and GitHub committed 2023-07-16 21:51:45 +02:00
1 parent 039a446944
commit 7c81690c1e
29 files changed
+597 -582

No files matched your search

+29 -20
View File
@@ -2,10 +2,8 @@
<panel
:icon="mdiPrinter3d"
:title="printer_name"
:card-class="
'farmprinter-panel ' +
(!printer.socket.isConnected && !printer.socket.isConnecting ? 'disabledPrinter' : '')
"
card-class="farmprinter-panel"
:class="panelClass"
:loading="printer.socket.isConnecting"
:toolbar-color="isCurrentPrinter ? 'primary' : ''">
<template #buttons>
@@ -17,7 +15,7 @@
</v-btn>
</template>
<v-list dense class="py-0">
<v-list-item link @click="currentCamId = 'off'">
<v-list-item link @click="currentCamName = 'off'">
<v-list-item-icon class="mr-2">
<v-icon small class="mt-1">{{ mdiWebcamOff }}</v-icon>
</v-list-item-icon>
@@ -27,9 +25,9 @@
</v-list-item>
<v-list-item
v-for="webcam of printer_webcams"
:key="webcam.index"
:key="webcam.name"
link
@click="currentCamId = webcam.id">
@click="currentCamName = webcam.name">
<v-list-item-icon class="mr-2">
<v-icon small class="mt-1">{{ convertWebcamIcon(webcam.icon) }}</v-icon>
</v-list-item-icon>
@@ -47,7 +45,7 @@
<div
v-if="
printer.socket.isConnected &&
currentCamId !== 'off' &&
currentCamName !== 'off' &&
currentWebcam &&
'service' in currentWebcam
"
@@ -122,6 +120,7 @@ import { mdiPrinter3d, mdiWebcam, mdiMenuDown, mdiWebcamOff, mdiFileOutline } fr
import { Debounce } from 'vue-debounce-decorator'
import WebcamMixin from '@/components/mixins/webcam'
import WebcamWrapper from '@/components/webcams/WebcamWrapper.vue'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component({
components: {
@@ -156,12 +155,12 @@ export default class FarmPrinterPanel extends Mixins(BaseMixin, WebcamMixin) {
return this.$store.getters['farm/' + this.printer._namespace + '/isCurrentPrinter']
}
get currentCamId() {
return this.$store.getters['farm/' + this.printer._namespace + '/getSetting']('currentCamId', 'off')
get currentCamName() {
return this.$store.getters['farm/' + this.printer._namespace + '/getSetting']('currentCamName', 'off')
}
set currentCamId(newVal) {
this.$store.dispatch('farm/' + this.printer._namespace + '/setSettings', { currentCamId: newVal })
set currentCamName(newVal) {
this.$store.dispatch('farm/' + this.printer._namespace + '/setSettings', { currentCamName: newVal })
}
get printer_name() {
@@ -199,18 +198,30 @@ export default class FarmPrinterPanel extends Mixins(BaseMixin, WebcamMixin) {
}
get showWebcamSwitch() {
return this.printer.socket.isConnected && this.printer_webcams.length > 0
if (this.printer_webcams.length == 0) return false
return this.printer.socket.isConnected
}
get printer_webcams() {
get printer_webcams(): GuiWebcamStateWebcam[] {
return this.$store.getters['farm/' + this.printer._namespace + '/getPrinterWebcams']
}
get currentWebcam() {
const currentCam = this.printer_webcams.find((webcam: any) => webcam.id === this.currentCamId)
get currentWebcam(): GuiWebcamStateWebcam | null {
const currentCam = this.printer_webcams?.find(
(webcam: GuiWebcamStateWebcam) => webcam.name === this.currentCamName
)
if (currentCam) return currentCam
return false
return null
}
get panelClass(): string[] {
let output = []
if (!this.printer.socket.isConnected && !this.printer.socket.isConnecting) output.push('disabledPrinter')
return output
}
clickPrinter() {
@@ -268,10 +279,8 @@ export default class FarmPrinterPanel extends Mixins(BaseMixin, WebcamMixin) {
.v-overlay {
top: 48px;
}
</style>
<style>
.farmprinter-panel {
::v-deep .farmprinter-panel {
position: relative;
}
</style>
+6 -5
View File
@@ -28,7 +28,7 @@
<v-list-item-title>{{ $t('Panels.WebcamPanel.All') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-for="webcam of webcams" :key="webcam.id" link @click="currentCamId = webcam.id">
<v-list-item v-for="webcam of webcams" :key="webcam.name" link @click="currentCamId = webcam.name">
<v-list-item-icon class="mr-2">
<v-icon small class="mt-1">{{ convertWebcamIcon(webcam.icon) }}</v-icon>
</v-list-item-icon>
@@ -77,13 +77,14 @@ export default class WebcamPanel extends Mixins(BaseMixin, WebcamMixin) {
return this.$store.getters['gui/webcams/getWebcams']
}
// id changed to name with the refactoring of using moonraker webcam API
get currentCamId(): string {
if (this.webcams.length === 1) return this.webcams[0].id ?? 'all'
if (this.webcams.length === 1) return this.webcams[0].name ?? 'all'
let currentCamId = this.$store.state.gui.view.webcam.currentCam[this.currentPage ?? ''] ?? 'all'
if (this.webcams.findIndex((webcam: GuiWebcamStateWebcam) => webcam.id === currentCamId) !== -1)
if (this.webcams.findIndex((webcam: GuiWebcamStateWebcam) => webcam.name === currentCamId) !== -1)
return currentCamId
else if (currentCamId !== undefined && this.webcams.length === 1) return this.webcams[0].id ?? ''
else if (currentCamId !== undefined && this.webcams.length === 1) return this.webcams[0].name ?? ''
else return 'all'
}
@@ -92,7 +93,7 @@ export default class WebcamPanel extends Mixins(BaseMixin, WebcamMixin) {
}
get currentCam(): any {
const cam = this.webcams.find((cam: GuiWebcamStateWebcam) => cam.id === this.currentCamId)
const cam = this.webcams.find((cam: GuiWebcamStateWebcam) => cam.name === this.currentCamId)
return (
cam ?? {
@@ -129,12 +129,6 @@
hide-details
class="mt-0"
@change="changeNamespace('timelapse')"></v-checkbox>
<v-checkbox
v-if="availableNamespaces.includes('webcams')"
:label="$t('Settings.GeneralTab.DbWebcams')"
hide-details
class="mt-0"
@change="changeNamespace('webcams')"></v-checkbox>
</v-col>
</v-row>
<v-row>
@@ -180,12 +174,6 @@
hide-details
class="mt-0"
@change="changeNamespace('timelapse')"></v-checkbox>
<v-checkbox
v-if="availableNamespaces.includes('webcams')"
:label="$t('Settings.GeneralTab.DbWebcams')"
hide-details
class="mt-0"
@change="changeNamespace('webcams')"></v-checkbox>
<v-checkbox
v-if="moonrakerComponents.includes('history')"
:label="$t('Settings.GeneralTab.DbHistoryJobs')"
@@ -345,10 +333,6 @@ export default class SettingsGeneralTab extends Mixins(BaseMixin) {
name: 'view',
label: this.$t('Settings.GeneralTab.DbView').toString(),
},
{
name: 'webcams',
label: this.$t('Settings.WebcamsTab.Webcams').toString(),
},
]
}
+48 -366
View File
@@ -1,28 +1,14 @@
<template>
<div>
<v-card v-if="!form.bool" flat>
<v-card v-if="!boolForm" flat>
<v-card-text>
<h3 class="text-h5 mb-3">{{ $t('Settings.WebcamsTab.Webcams') }}</h3>
<div v-for="webcam in webcams" :key="webcam.id">
<v-divider class="my-2" />
<settings-row
:title="webcam.name"
:icon="convertWebcamIcon(webcam.icon)"
:sub-title="getSubtitle(webcam)">
<v-btn small outlined @click="editWebcam(webcam)">
<v-icon small left>{{ mdiPencil }}</v-icon>
{{ $t('Settings.Edit') }}
</v-btn>
<v-btn
small
outlined
class="ml-3 minwidth-0 px-2"
color="error"
@click="deleteWebcam(webcam.id ?? '')">
<v-icon small>{{ mdiDelete }}</v-icon>
</v-btn>
</settings-row>
</div>
<webcam-list-entry
v-for="(webcam, index) in webcams"
:key="webcam.name"
:webcam="webcam"
:bool-border-top="index > 0"
@edit-webcam="editWebcam" />
</v-card-text>
<v-card-actions>
<v-btn v-if="existCrowsnestConf" text color="primary" @click="openCrowsnestConf">
@@ -33,161 +19,7 @@
</v-card-actions>
</v-card>
<v-card v-else flat>
<v-form ref="webcamForm" v-model="form.valid" @submit.prevent="saveWebcam">
<v-card-title>
{{
form.id === null ? $t('Settings.WebcamsTab.CreateWebcam') : $t('Settings.WebcamsTab.EditWebcam')
}}
</v-card-title>
<v-card-text>
<v-row>
<v-col class="col-12 col-sm-6">
<v-row>
<v-col class="d-flex">
<v-item-group>
<v-menu :offset-y="true" title="Icon">
<template #activator="{ on, attrs }">
<v-btn
class="px-2 mr-2 _transition _menu-button"
color="transparent"
v-bind="attrs"
elevation="0"
:ripple="false"
v-on="on"
@blur="selectIcon = !selectIcon"
@focus="selectIcon = !selectIcon">
<v-icon>{{ convertWebcamIcon(form.icon) }}</v-icon>
<v-icon
:class="!selectIcon ? '' : '_rotate-180'"
:color="!selectIcon ? '' : 'primary'"
class="pl-1 mr-n2">
{{ mdiMenuDown }}
</v-icon>
</v-btn>
</template>
<v-list dense class="py-0">
<v-list-item
v-for="icon of iconItems"
:key="icon.value"
link
@click="setFormIcon(icon.value)">
<v-list-item-icon class="mr-2">
<v-icon small class="mt-1">
{{ convertWebcamIcon(icon.value) }}
</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="icon.text" />
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
</v-item-group>
<v-text-field
v-model="form.name"
:label="$t('Settings.WebcamsTab.Name')"
hide-details="auto"
outlined
:rules="[rules.required, rules.unique]"
class="_webcam-settings-name-field"
dense />
</v-col>
</v-row>
<v-row>
<v-col class="py-2">
<v-text-field
v-model="form.urlStream"
:label="$t('Settings.WebcamsTab.UrlStream')"
hide-details="auto"
outlined
dense
:rules="form.service !== 'mjpegstreamer-adaptive' ? [rules.required] : []" />
</v-col>
</v-row>
<v-row>
<v-col class="py-2">
<v-text-field
v-model="form.urlSnapshot"
:label="$t('Settings.WebcamsTab.UrlSnapshot')"
hide-details="auto"
outlined
dense
:rules="form.service === 'mjpegstreamer-adaptive' ? [rules.required] : []" />
</v-col>
</v-row>
<v-row>
<v-col class="py-2">
<v-select
v-model="form.service"
:items="serviceItems"
hide-details
outlined
dense
:label="$t('Settings.WebcamsTab.Service')"
attach />
</v-col>
</v-row>
<v-row v-if="form.service === 'mjpegstreamer-adaptive' || form.service === 'jmuxer-stream'">
<v-col class="py-2 col-6">
<v-text-field
v-model="form.targetFps"
outlined
dense
hide-details
:label="$t('Settings.WebcamsTab.TargetFPS')" />
</v-col>
<v-col class="py-2 col-6">
<v-select
v-model="form.rotate"
:items="rotateItems"
outlined
dense
hide-details
:label="$t('Settings.WebcamsTab.Rotate')" />
</v-col>
</v-row>
<v-row>
<v-col class="pt-1 pb-3">
<div class="v-label v-label--active theme--dark text-subtitle-1">
{{ $t('Settings.WebcamsTab.FlipWebcam') }}
</div>
</v-col>
</v-row>
<v-row class="mt-0">
<v-col class="py-0">
<v-checkbox
v-model="form.flipX"
class="mt-1"
hide-details
:label="$t('Settings.WebcamsTab.Horizontally')" />
</v-col>
<v-col class="py-0">
<v-checkbox
v-model="form.flipY"
class="mt-1"
hide-details
:label="$t('Settings.WebcamsTab.Vertically')" />
</v-col>
</v-row>
</v-col>
<v-col class="col-12 col-sm-6 text-center" align-self="center">
<webcam-wrapper :webcam="form" />
</v-col>
</v-row>
</v-card-text>
<v-card-actions class="d-flex justify-end">
<v-btn text @click="form.bool = false">
{{ $t('Settings.Cancel') }}
</v-btn>
<v-btn color="primary" text type="submit" :disabled="!form.name">
{{
form.id === null
? $t('Settings.WebcamsTab.SaveWebcam')
: $t('Settings.WebcamsTab.UpdateWebcam')
}}
</v-btn>
</v-card-actions>
</v-form>
<webcam-form :webcam="formWebcam" :type="typeForm" @close="closeForm" />
</v-card>
</div>
</template>
@@ -196,98 +28,30 @@
import { Component, Mixins } from 'vue-property-decorator'
import BaseMixin from '../mixins/base'
import SettingsRow from '@/components/settings/SettingsRow.vue'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
import { mdiMenuDown, mdiDelete, mdiPencil, mdiWebcam } from '@mdi/js'
import { mdiDelete, mdiPencil } from '@mdi/js'
import WebcamMixin from '@/components/mixins/webcam'
import { FileStateFile } from '@/store/files/types'
interface webcamForm {
bool: boolean
id: string | null
valid: boolean
name: string
icon: string
service: string
targetFps: number
urlStream: string
urlSnapshot: string
rotate: number
flipX: boolean
flipY: boolean
}
import WebcamForm from '@/components/settings/Webcams/WebcamForm.vue'
import WebcamListEntry from '@/components/settings/Webcams/WebcamListEntry.vue'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component({
components: {
SettingsRow,
WebcamForm,
WebcamListEntry,
},
})
export default class SettingsWebcamsTab extends Mixins(BaseMixin, WebcamMixin) {
mdiPencil = mdiPencil
mdiDelete = mdiDelete
mdiMenuDown = mdiMenuDown
private selectIcon: boolean = false
private form: webcamForm = {
bool: false,
id: null,
valid: false,
name: '',
icon: '',
service: '',
targetFps: 15,
urlStream: '',
urlSnapshot: '',
rotate: 0,
flipX: false,
flipY: false,
}
private rules = {
required: (value: string) => value !== '' || this.$t('Settings.WebcamsTab.Required'),
unique: (value: string) => !this.existsWebcamName(value) || this.$t('Settings.WebcamsTab.NameAlreadyExists'),
}
private rotateItems = [
{ value: 0, text: '0°' },
{ value: 90, text: '90°' },
{ value: 180, text: '180°' },
{ value: 270, text: '270°' },
]
declare $refs: {
webcamForm: any
}
private boolForm = false
private typeForm: 'create' | 'edit' = 'create'
private formWebcam: GuiWebcamStateWebcam = {} as GuiWebcamStateWebcam
get webcams() {
return this.$store.getters['gui/webcams/getWebcams'] ?? []
}
get iconItems() {
return [
{ value: 'mdiPrinter3d', text: this.$t('Settings.WebcamsTab.IconPrinter') },
{ value: 'mdiPrinter3dNozzle', text: this.$t('Settings.WebcamsTab.IconNozzle') },
{ value: 'mdiRadiatorDisabled', text: this.$t('Settings.WebcamsTab.IconBed') },
{ value: 'mdiWebcam', text: this.$t('Settings.WebcamsTab.IconCam') },
{ value: 'mdiAlbum', text: this.$t('Settings.WebcamsTab.IconFilament') },
{ value: 'mdiDoor', text: this.$t('Settings.WebcamsTab.IconDoor') },
{ value: 'mdiRaspberryPi', text: this.$t('Settings.WebcamsTab.IconMcu') },
{ value: 'mdiCampfire', text: this.$t('Settings.WebcamsTab.IconHot') },
]
}
get serviceItems() {
return [
{ value: 'mjpegstreamer', text: this.$t('Settings.WebcamsTab.Mjpegstreamer') },
{ value: 'mjpegstreamer-adaptive', text: this.$t('Settings.WebcamsTab.MjpegstreamerAdaptive') },
{ value: 'uv4l-mjpeg', text: this.$t('Settings.WebcamsTab.Uv4lMjpeg') },
{ value: 'ipstream', text: this.$t('Settings.WebcamsTab.Ipstream') },
{ value: 'webrtc-camerastreamer', text: this.$t('Settings.WebcamsTab.WebrtcCameraStreamer') },
{ value: 'webrtc-mediamtx', text: this.$t('Settings.WebcamsTab.WebrtcMediaMTX') },
{ value: 'hlsstream', text: this.$t('Settings.WebcamsTab.Hlsstream') },
{ value: 'jmuxer-stream', text: this.$t('Settings.WebcamsTab.JMuxerStream') },
{ value: 'webrtc-janus', text: this.$t('Settings.WebcamsTab.WebrtcJanus') },
]
return this.$store.state.gui.webcams.webcams ?? []
}
get configfiles() {
@@ -302,87 +66,6 @@ export default class SettingsWebcamsTab extends Mixins(BaseMixin, WebcamMixin) {
return this.configfiles.findIndex((file: FileStateFile) => file.filename === 'crowsnest.conf') !== -1
}
getSubtitle(webcam: GuiWebcamStateWebcam) {
return 'URL: ' + (webcam.service === 'mjpegstreamer-adaptive' ? webcam.urlSnapshot : webcam.urlStream)
}
existsWebcamName(name: string) {
return (
this.webcams.findIndex(
(webcam: GuiWebcamStateWebcam) => webcam.name === name && webcam.id !== this.form.id
) !== -1
)
}
createWebcam() {
this.clearDialog()
this.form.bool = true
}
editWebcam(webcam: GuiWebcamStateWebcam) {
this.form.id = webcam.id ?? null
this.form.name = webcam.name
this.form.icon = webcam.icon
this.form.service = webcam.service
this.form.targetFps = webcam.targetFps
this.form.urlStream = webcam.urlStream
this.form.urlSnapshot = webcam.urlSnapshot
this.form.rotate = webcam.rotate ?? 0
this.form.flipX = webcam.flipX
this.form.flipY = webcam.flipY
this.form.bool = true
this.form.valid = false
this.$nextTick(() => {
this.$refs.webcamForm?.validate()
})
}
saveWebcam() {
if (this.form.valid) {
const values = {
name: this.form.name,
icon: this.form.icon,
service: this.form.service,
targetFps: this.form.targetFps,
urlStream: this.form.urlStream,
urlSnapshot: this.form.urlSnapshot,
rotate: this.form.rotate,
flipX: this.form.flipX,
flipY: this.form.flipY,
}
if (this.form.id !== null) this.$store.dispatch('gui/webcams/update', { id: this.form.id, values: values })
else this.$store.dispatch('gui/webcams/store', { values })
this.clearDialog()
}
}
deleteWebcam(id: string) {
this.$store.dispatch('gui/webcams/delete', id)
}
clearDialog() {
this.form.bool = false
this.form.id = null
this.form.name = ''
this.form.icon = mdiWebcam
this.form.service = 'mjpegstreamer-adaptive'
this.form.targetFps = 15
this.form.urlStream = '/webcam/?action=stream'
this.form.urlSnapshot = '/webcam/?action=snapshot'
this.form.rotate = 0
this.form.flipX = false
this.form.flipY = false
}
setFormIcon(icon: string) {
this.form.icon = icon
}
openCrowsnestConf() {
this.$store.dispatch('editor/openFile', {
root: 'config',
@@ -392,36 +75,35 @@ export default class SettingsWebcamsTab extends Mixins(BaseMixin, WebcamMixin) {
permissions: this.crowsnestConf?.permissions,
})
}
createWebcam() {
this.formWebcam = {
name: '',
enabled: true,
icon: 'mdiWebcam',
service: 'mjpegstreamer-adaptive',
target_fps: 15,
target_fps_idle: 15,
stream_url: '/webcam/?action=stream',
snapshot_url: '/webcam/?action=snapshot',
rotation: 0,
flip_horizontal: false,
flip_vertical: false,
extra_data: {},
}
this.typeForm = 'create'
this.boolForm = true
}
closeForm() {
this.boolForm = false
}
editWebcam(webcam: GuiWebcamStateWebcam) {
this.formWebcam = { ...webcam }
this.typeForm = 'edit'
this.boolForm = true
}
}
</script>
<style lang="scss" scoped>
._transition i::before {
transition: transform 500ms;
}
._rotate-180:before {
transform: rotate(180deg);
}
.v-item-group {
button:hover::before,
button:focus::before {
opacity: 0 !important;
}
._menu-button {
height: 40px;
width: 62px;
border: 1px solid rgba(255, 255, 255, 0.25) !important;
}
._menu-button:hover {
border-color: rgba(255, 255, 255, 1) !important;
}
._menu-button:focus {
border: 2px solid var(--color-primary) !important;
}
}
._webcam-settings-name-field ::v-deep .v-text-field__details {
margin-bottom: -12px !important;
}
</style>
@@ -0,0 +1,324 @@
<template>
<v-form ref="webcamForm" v-model="valid" @submit.prevent="submit">
<v-card-title>{{ title }}</v-card-title>
<v-card-text>
<v-row>
<v-col class="col-12 col-sm-6">
<v-row>
<v-col class="d-flex">
<v-item-group>
<v-menu v-model="selectIcon" :offset-y="true" title="Icon">
<template #activator="{ on, attrs }">
<v-btn
class="px-2 mr-2 _transition _menu-button"
color="transparent"
v-bind="attrs"
elevation="0"
:ripple="false"
v-on="on">
<v-icon>{{ convertWebcamIcon(webcam.icon) }}</v-icon>
<v-icon :class="classIconButtonArrow" class="pl-1 mr-n2">
{{ mdiMenuDown }}
</v-icon>
</v-btn>
</template>
<v-list dense class="py-0">
<v-list-item
v-for="icon of iconItems"
:key="icon.value"
link
@click="webcam.icon = icon.value">
<v-list-item-icon class="mr-2">
<v-icon small class="mt-1">
{{ convertWebcamIcon(icon.value) }}
</v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="icon.text" />
</v-list-item-content>
</v-list-item>
</v-list>
</v-menu>
</v-item-group>
<v-text-field
v-model="webcam.name"
:label="$t('Settings.WebcamsTab.Name')"
hide-details="auto"
outlined
:rules="[rules.required, rules.unique]"
class="_webcam-settings-name-field"
dense />
</v-col>
</v-row>
<v-row>
<v-col class="py-2">
<v-text-field
v-model="webcam.stream_url"
:label="$t('Settings.WebcamsTab.UrlStream')"
hide-details="auto"
outlined
dense
:rules="rulesStreamUrl" />
</v-col>
</v-row>
<v-row>
<v-col class="py-2">
<v-text-field
v-model="webcam.snapshot_url"
:label="$t('Settings.WebcamsTab.UrlSnapshot')"
hide-details="auto"
outlined
dense
:rules="rulesSnapshotUrl" />
</v-col>
</v-row>
<v-row>
<v-col class="py-2">
<v-select
v-model="webcam.service"
:items="serviceItems"
hide-details
outlined
dense
:label="$t('Settings.WebcamsTab.Service')" />
</v-col>
</v-row>
<v-row v-if="['mjpegstreamer-adaptive', 'jmuxer-stream'].includes(webcam.service)">
<v-col class="py-2 col-6">
<v-text-field
v-model="webcam.target_fps"
outlined
dense
hide-details
:label="$t('Settings.WebcamsTab.TargetFPS')" />
</v-col>
<v-col class="py-2 col-6">
<v-select
v-model="webcam.rotation"
:items="rotationItems"
outlined
dense
hide-details
:label="$t('Settings.WebcamsTab.Rotate')" />
</v-col>
</v-row>
<v-row>
<v-col class="pt-1 pb-3">
<div class="v-label v-label--active theme--dark text-subtitle-1">
{{ $t('Settings.WebcamsTab.FlipWebcam') }}
</div>
</v-col>
</v-row>
<v-row class="mt-0">
<v-col class="py-0">
<v-checkbox
v-model="webcam.flip_horizontal"
class="mt-1"
hide-details
:label="$t('Settings.WebcamsTab.Horizontally')" />
</v-col>
<v-col class="py-0">
<v-checkbox
v-model="webcam.flip_vertical"
class="mt-1"
hide-details
:label="$t('Settings.WebcamsTab.Vertically')" />
</v-col>
</v-row>
</v-col>
<v-col class="col-12 col-sm-6 text-center" align-self="center">
<webcam-wrapper :webcam="webcam" />
</v-col>
</v-row>
</v-card-text>
<v-card-actions class="d-flex justify-end">
<v-btn text @click="closeForm">{{ $t('Settings.Cancel') }}</v-btn>
<v-btn color="primary" text type="submit" :disabled="!valid">{{ actionButtonText }}</v-btn>
</v-card-actions>
</v-form>
</template>
<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import SettingsRow from '@/components/settings/SettingsRow.vue'
import { mdiDelete, mdiPencil, mdiMenuDown } from '@mdi/js'
import WebcamMixin from '@/components/mixins/webcam'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component({
components: {
SettingsRow,
},
})
export default class WebcamForm extends Mixins(BaseMixin, WebcamMixin) {
mdiPencil = mdiPencil
mdiDelete = mdiDelete
mdiMenuDown = mdiMenuDown
@Prop({ type: Object, required: true }) private webcam!: GuiWebcamStateWebcam
@Prop({ type: String, default: 'create' }) readonly type!: 'create' | 'edit'
private selectIcon = false
private valid = false
private oldWebcamName = ''
private rules = {
required: (value: string) => value !== '' || this.$t('Settings.WebcamsTab.Required'),
unique: (value: string) => !this.existsWebcamName(value) || this.$t('Settings.WebcamsTab.NameAlreadyExists'),
}
get webcams() {
return this.$store.state.gui.webcams?.webcams ?? []
}
get title() {
if (this.type === 'create') return this.$t('Settings.WebcamsTab.CreateWebcam')
return this.$t('Settings.WebcamsTab.EditWebcam')
}
get actionButtonText() {
if (this.type === 'create') return this.$t('Settings.WebcamsTab.SaveWebcam')
return this.$t('Settings.WebcamsTab.UpdateWebcam')
}
get rotationItems() {
const options = [0, 90, 180, 270]
const output: { value: number; text: string }[] = []
options.forEach((value: number) => {
output.push({ value, text: `${value}°` })
})
return output
}
get rulesStreamUrl() {
let rules = []
if (this.webcam.service !== 'mjpegstreamer-adaptive') {
rules.push(this.rules.required)
}
return rules
}
get rulesSnapshotUrl() {
let rules = []
if (this.webcam.service === 'mjpegstreamer-adaptive') {
rules.push(this.rules.required)
}
return rules
}
get serviceItems() {
return [
{ value: 'mjpegstreamer', text: this.$t('Settings.WebcamsTab.Mjpegstreamer') },
{ value: 'mjpegstreamer-adaptive', text: this.$t('Settings.WebcamsTab.MjpegstreamerAdaptive') },
{ value: 'uv4l-mjpeg', text: this.$t('Settings.WebcamsTab.Uv4lMjpeg') },
{ value: 'ipstream', text: this.$t('Settings.WebcamsTab.Ipstream') },
{ value: 'webrtc-camerastreamer', text: this.$t('Settings.WebcamsTab.WebrtcCameraStreamer') },
{ value: 'webrtc-mediamtx', text: this.$t('Settings.WebcamsTab.WebrtcMediaMTX') },
{ value: 'hlsstream', text: this.$t('Settings.WebcamsTab.Hlsstream') },
{ value: 'jmuxer-stream', text: this.$t('Settings.WebcamsTab.JMuxerStream') },
{ value: 'webrtc-janus', text: this.$t('Settings.WebcamsTab.WebrtcJanus') },
]
}
get iconItems() {
return [
{ value: 'mdiPrinter3d', text: this.$t('Settings.WebcamsTab.IconPrinter') },
{ value: 'mdiPrinter3dNozzle', text: this.$t('Settings.WebcamsTab.IconNozzle') },
{ value: 'mdiRadiatorDisabled', text: this.$t('Settings.WebcamsTab.IconBed') },
{ value: 'mdiWebcam', text: this.$t('Settings.WebcamsTab.IconCam') },
{ value: 'mdiAlbum', text: this.$t('Settings.WebcamsTab.IconFilament') },
{ value: 'mdiDoor', text: this.$t('Settings.WebcamsTab.IconDoor') },
{ value: 'mdiRaspberryPi', text: this.$t('Settings.WebcamsTab.IconMcu') },
{ value: 'mdiCampfire', text: this.$t('Settings.WebcamsTab.IconHot') },
]
}
get classIconButtonArrow() {
let classes = ['_transition']
if (this.selectIcon) classes.push('_rotate-180')
return classes
}
mounted() {
this.oldWebcamName = this.webcam.name
}
existsWebcamName(name: string) {
name = name.toLowerCase().trim()
const count =
this.webcams.find((webcam: GuiWebcamStateWebcam) => webcam.name.toLowerCase().trim() === name)?.length ?? 0
// If we are creating a new webcam, we only want to check if the name already exists
if (this.type === 'create') return count !== 0
// If we are editing a webcam, we want to check if the name only exists once (the one we are editing)
return count >= 1
}
submit() {
if (this.type === 'create') {
this.save()
return
}
this.update()
}
async save() {
await this.$store.dispatch('gui/webcams/store', this.webcam)
this.$emit('close')
}
async update() {
await this.$store.dispatch('gui/webcams/update', { webcam: this.webcam, oldWebcamName: this.oldWebcamName })
this.$emit('close')
}
closeForm() {
this.$emit('close')
}
}
</script>
<style lang="scss" scoped>
::v-deep ._transition svg {
transition: transform 500ms;
}
::v-deep ._rotate-180 svg {
transform: rotate(180deg);
}
.v-item-group {
button:hover::before,
button:focus::before {
opacity: 0 !important;
}
._menu-button {
height: 40px;
width: 62px;
border: 1px solid rgba(255, 255, 255, 0.25) !important;
}
._menu-button:hover {
border-color: rgba(255, 255, 255, 1) !important;
}
._menu-button:focus {
border: 2px solid var(--color-primary) !important;
}
}
._webcam-settings-name-field ::v-deep .v-text-field__details {
margin-bottom: -12px !important;
}
</style>
@@ -0,0 +1,73 @@
<template>
<div>
<v-divider v-if="boolBorderTop" class="my-2" />
<settings-row :title="webcam.name" :icon="icon" :sub-title="subtitle">
<template v-if="webcam.source === 'database'">
<v-btn
class="minwidth-0 px-2"
small
outlined
:color="webcam.enabled ? '' : 'secondary'"
@click="toogleStatus">
<v-icon small>{{ mdiLightbulbOutline }}</v-icon>
</v-btn>
<v-btn class="ml-3" small outlined @click="edit">
<v-icon small left>{{ mdiPencil }}</v-icon>
{{ $t('Settings.Edit') }}
</v-btn>
<v-btn small outlined class="ml-3 minwidth-0 px-2" color="error" @click="deleteWebcam">
<v-icon small>{{ mdiDelete }}</v-icon>
</v-btn>
</template>
</settings-row>
</div>
</template>
<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import SettingsRow from '@/components/settings/SettingsRow.vue'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
import { mdiDelete, mdiPencil, mdiLightbulbOutline } from '@mdi/js'
import WebcamMixin from '@/components/mixins/webcam'
@Component({
components: {
SettingsRow,
},
})
export default class WebcamListEntry extends Mixins(BaseMixin, WebcamMixin) {
mdiPencil = mdiPencil
mdiDelete = mdiDelete
mdiLightbulbOutline = mdiLightbulbOutline
@Prop({ type: Object, default: () => {} }) private webcam!: GuiWebcamStateWebcam
@Prop({ type: Boolean, default: false }) private boolBorderTop!: boolean
get icon() {
return this.convertWebcamIcon(this.webcam.icon)
}
get subtitle() {
if (this.webcam.service === 'mjpegstreamer-adaptive') return `URL: ${this.webcam.snapshot_url}`
return `URL: ${this.webcam.stream_url}`
}
toogleStatus() {
let webcam = { ...this.webcam }
webcam.enabled = !webcam.enabled
this.$store.dispatch('gui/webcams/update', { webcam: webcam, oldWebcamName: webcam.name })
}
edit() {
this.$emit('edit-webcam', this.webcam)
}
deleteWebcam() {
this.$store.dispatch('gui/webcams/delete', this.webcam.name)
}
}
</script>
<style lang="scss" scoped></style>
+6 -8
View File
@@ -14,6 +14,7 @@
import { Component, Mixins, Prop } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import Hls from 'hls.js'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component
export default class Hlsstreamer extends Mixins(BaseMixin) {
@@ -21,11 +22,8 @@ export default class Hlsstreamer extends Mixins(BaseMixin) {
private isVisible = true
private hls: Hls | null = null
@Prop({ required: true })
camSettings: any
@Prop()
printerUrl: string | undefined
@Prop({ required: true }) readonly camSettings!: GuiWebcamStateWebcam
@Prop() printerUrl: string | undefined
declare $refs: {
video: HTMLVideoElement
@@ -34,7 +32,7 @@ export default class Hlsstreamer extends Mixins(BaseMixin) {
get url() {
if (!this.isVisible) return ''
return this.camSettings.urlStream || ''
return this.camSettings.stream_url || ''
}
get webcamStyle() {
@@ -46,8 +44,8 @@ export default class Hlsstreamer extends Mixins(BaseMixin) {
}
let transforms = ''
if ('flipX' in this.camSettings && this.camSettings.flipX) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flipY) transforms += ' scaleY(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_horizontal) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_vertical) transforms += ' scaleY(-1)'
if (transforms.trimStart().length) return { transform: transforms.trimStart() }
if (this.aspectRatio) {
+13 -15
View File
@@ -1,9 +1,3 @@
<style scoped>
.webcamImage {
width: 100%;
}
</style>
<template>
<video v-observe-visibility="visibilityChanged" :src="url" autoplay :style="webcamStyle" class="webcamImage" />
</template>
@@ -11,28 +5,26 @@
<script lang="ts">
import { Component, Mixins, Prop } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component
export default class Ipstreamer extends Mixins(BaseMixin) {
private isVisible = true
@Prop({ required: true })
camSettings: any
@Prop()
printerUrl: string | undefined
@Prop({ required: true }) readonly camSettings!: GuiWebcamStateWebcam
@Prop() printerUrl: string | undefined
get url() {
if (!this.isVisible) return ''
return this.camSettings.urlStream || ''
return this.camSettings.stream_url || ''
}
get webcamStyle() {
let transforms = ''
if ('flipX' in this.camSettings && this.camSettings.flipX) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flipY) transforms += ' scaleY(-1)'
if (transforms.trimLeft().length) return { transform: transforms.trimLeft() }
if ('flipX' in this.camSettings && this.camSettings.flip_horizontal) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_vertical) transforms += ' scaleY(-1)'
if (transforms.trimStart().length) return { transform: transforms.trimStart() }
return ''
}
@@ -42,3 +34,9 @@ export default class Ipstreamer extends Mixins(BaseMixin) {
}
}
</script>
<style scoped>
.webcamImage {
width: 100%;
}
</style>
+7 -9
View File
@@ -14,30 +14,28 @@
import JMuxer from 'jmuxer'
import { Component, Mixins, Prop, Watch } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component
export default class JMuxerStreamer extends Mixins(BaseMixin) {
private jmuxer: JMuxer | null = null
private status: string = 'connecting'
@Prop({ required: true })
camSettings: any
@Prop()
printerUrl: string | undefined
@Prop({ required: true }) readonly camSettings!: GuiWebcamStateWebcam
@Prop() printerUrl: string | undefined
declare $refs: {
video: HTMLVideoElement
}
get url() {
return this.camSettings.urlStream || ''
return this.camSettings.stream_url || ''
}
get webcamStyle() {
let transforms = ''
if ('flipX' in this.camSettings && this.camSettings.flipX) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flipY) transforms += ' scaleY(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_horizontal) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_vertical) transforms += ' scaleY(-1)'
if (transforms.trimStart().length) return { transform: transforms.trimStart() }
return ''
@@ -59,7 +57,7 @@ export default class JMuxerStreamer extends Mixins(BaseMixin) {
}
const video = this.$refs.video
const targetFps = this.camSettings.targetFps || 10
const targetFps = this.camSettings.target_fps || 10
this.jmuxer = new JMuxer({
node: video,
+7 -9
View File
@@ -23,6 +23,7 @@ import { Component, Mixins, Prop, Ref, Watch } from 'vue-property-decorator'
import { JanusJs, JanusSession, JanusStreamingPlugin } from 'typed_janus_js'
import BaseMixin from '@/components/mixins/base'
import { ConstructorOptions } from 'typed_janus_js/src/interfaces/janus'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component
export default class JanusStreamer extends Mixins(BaseMixin) {
@@ -33,15 +34,12 @@ export default class JanusStreamer extends Mixins(BaseMixin) {
private aspectRatio: null | number = null
private status: string = 'connecting'
@Prop({ required: true })
camSettings: any
@Prop({ required: true }) readonly camSettings!: GuiWebcamStateWebcam
@Prop({ default: null }) declare readonly printerUrl: string | null
@Ref() declare stream: HTMLVideoElement
get url() {
const baseUrl = this.camSettings.urlStream
const baseUrl = this.camSettings.stream_url
let url = new URL(baseUrl, this.printerUrl === null ? this.hostUrl.toString() : this.printerUrl)
url.port = '8188'
url.protocol = this.printerUrl?.startsWith('https') ? 'wss' : 'ws'
@@ -56,7 +54,7 @@ export default class JanusStreamer extends Mixins(BaseMixin) {
}
get streamId() {
const pathnameParts = new URL(this.camSettings.urlStream).pathname.split('/')
const pathnameParts = new URL(this.camSettings.stream_url).pathname.split('/')
return pathnameParts[pathnameParts.length - 1]
}
@@ -67,8 +65,8 @@ export default class JanusStreamer extends Mixins(BaseMixin) {
}
let transforms = ''
if ('flipX' in this.camSettings && this.camSettings.flipX) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flipY) transforms += ' scaleY(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_horizontal) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_vertical) transforms += ' scaleY(-1)'
if (transforms.trimStart().length) output.transform = transforms.trimStart()
if (this.aspectRatio) output.aspectRatio = this.aspectRatio
@@ -132,7 +130,7 @@ export default class JanusStreamer extends Mixins(BaseMixin) {
@Watch('url')
async changedUrl() {
await this.session?.destroy({})
this.startStream()
await this.startStream()
}
}
</script>
+6 -8
View File
@@ -14,6 +14,7 @@
import Component from 'vue-class-component'
import { Mixins, Prop, Watch } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
const CONTENT_LENGTH = 'content-length'
const TYPE_JPEG = 'image/jpeg'
@@ -32,11 +33,8 @@ export default class Mjpegstreamer extends Mixins(BaseMixin) {
private isVisibleViewport = false
private isVisibleDocument = true
@Prop({ required: true })
camSettings: any
@Prop()
printerUrl: string | undefined
@Prop({ required: true }) readonly camSettings!: GuiWebcamStateWebcam
@Prop() printerUrl: string | undefined
@Prop({ default: true }) declare showFps: boolean
@@ -46,7 +44,7 @@ export default class Mjpegstreamer extends Mixins(BaseMixin) {
}
get url() {
const baseUrl = this.camSettings.urlStream
const baseUrl = this.camSettings.stream_url
let url = new URL(baseUrl, this.printerUrl === undefined ? this.hostUrl.toString() : this.printerUrl)
if (baseUrl.startsWith('http') || baseUrl.startsWith('://')) url = new URL(baseUrl)
@@ -62,8 +60,8 @@ export default class Mjpegstreamer extends Mixins(BaseMixin) {
}
let transforms = ''
if ('flipX' in this.camSettings && this.camSettings.flipX) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flipY) transforms += ' scaleY(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_horizontal) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_vertical) transforms += ' scaleY(-1)'
if (transforms.trimStart().length) output.transform = transforms.trimStart()
if (this.aspectRatio) {
@@ -20,6 +20,7 @@
import Component from 'vue-class-component'
import { Mixins, Prop, Watch } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component
export default class MjpegstreamerAdaptive extends Mixins(BaseMixin) {
@@ -44,7 +45,7 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin) {
mjpegstreamerAdaptive: any
}
@Prop({ required: true }) declare camSettings: any
@Prop({ required: true }) declare camSettings: GuiWebcamStateWebcam
@Prop() declare printerUrl: string | undefined
@Prop({ default: true }) declare showFps: boolean
@@ -57,9 +58,9 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin) {
}
let transforms = ''
if (this.camSettings.flipX ?? false) transforms += ' scaleX(-1)'
if (this.camSettings.flipY ?? false) transforms += ' scaleY(-1)'
if ((this.camSettings.rotate ?? 0) === 180) transforms += ' rotate(180deg)'
if (this.camSettings.flip_horizontal ?? false) transforms += ' scaleX(-1)'
if (this.camSettings.flip_vertical ?? false) transforms += ' scaleY(-1)'
if ((this.camSettings.rotation ?? 0) === 180) transforms += ' rotate(180deg)'
if (transforms.trimStart().length) output.transform = transforms.trimStart()
if (this.aspectRatio) {
@@ -75,7 +76,7 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin) {
}
get rotate() {
return [90, 270].includes(this.camSettings.rotate ?? 0)
return [90, 270].includes(this.camSettings.rotation ?? 0)
}
refreshFrame() {
@@ -86,7 +87,7 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin) {
}
async setFrame() {
const baseUrl = this.camSettings.urlSnapshot
const baseUrl = this.camSettings.snapshot_url
let url = new URL(baseUrl, this.printerUrl === undefined ? this.hostUrl.toString() : this.printerUrl)
if (baseUrl.startsWith('http') || baseUrl.startsWith('://')) url = new URL(baseUrl)
@@ -115,7 +116,7 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin) {
const x = canvas.width / 2
const y = canvas.height / 2
ctx.translate(x, y)
ctx.rotate((this.camSettings.rotate * Math.PI) / 180)
ctx.rotate((this.camSettings.rotation * Math.PI) / 180)
await ctx?.drawImage(
frame,
(-frame.width / 2) * scale,
@@ -123,7 +124,7 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin) {
frame.width * scale,
frame.height * scale
)
ctx.rotate(-((this.camSettings.rotate * Math.PI) / 180))
ctx.rotate(-((this.camSettings.rotation * Math.PI) / 180))
ctx.translate(-x, -y)
} else await ctx?.drawImage(frame, 0, 0, frame.width, frame.height, 0, 0, canvas.width, canvas.height)
@@ -138,7 +139,7 @@ export default class MjpegstreamerAdaptive extends Mixins(BaseMixin) {
onLoad() {
this.isLoaded = true
const targetFps = this.camSettings.targetFps || 10
const targetFps = this.camSettings.target_fps || 10
const end_time = performance.now()
const current_time = end_time - this.start_time
this.time = this.time * this.time_smoothing + current_time * (1.0 - this.time_smoothing)
+3 -3
View File
@@ -29,7 +29,7 @@ export default class Uv4lMjpeg extends Mixins(BaseMixin) {
}
get url() {
const baseUrl = this.camSettings.urlStream
const baseUrl = this.camSettings.stream_url
let url = new URL(baseUrl, this.printerUrl === undefined ? this.hostUrl.toString() : this.printerUrl)
if (baseUrl.startsWith('http') || baseUrl.startsWith('://')) url = new URL(baseUrl)
@@ -45,8 +45,8 @@ export default class Uv4lMjpeg extends Mixins(BaseMixin) {
}
let transforms = ''
if ('flipX' in this.camSettings && this.camSettings.flipX) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flipY) transforms += ' scaleY(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_horizontal) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_vertical) transforms += ' scaleY(-1)'
if (transforms.trimStart().length) output.transform = transforms.trimStart()
if (this.aspectRatio) {
+1 -1
View File
@@ -3,7 +3,7 @@
<template v-if="webcam.service === 'grid'">
<v-container v-if="webcams" fluid class="pb-4">
<v-row dense>
<v-col v-for="gridWebcam in webcams" :key="gridWebcam.id" cols="6">
<v-col v-for="gridWebcam in webcams" :key="gridWebcam.name" cols="6">
<webcam-wrapper-item :webcam="gridWebcam" :show-fps="showFps" />
</v-col>
</v-row>
@@ -20,6 +20,7 @@
<script lang="ts">
import { Component, Mixins, Prop, Ref, Watch } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component
export default class WebrtcCameraStreamer extends Mixins(BaseMixin) {
@@ -29,15 +30,12 @@ export default class WebrtcCameraStreamer extends Mixins(BaseMixin) {
private aspectRatio: null | number = null
private status: string = 'connecting'
@Prop({ required: true })
camSettings: any
@Prop({ required: true }) readonly camSettings!: GuiWebcamStateWebcam
@Prop({ default: null }) declare readonly printerUrl: string | null
@Ref() declare stream: HTMLVideoElement
get url() {
const baseUrl = this.camSettings.urlStream
const baseUrl = this.camSettings.stream_url
let url = new URL(baseUrl, this.printerUrl === null ? this.hostUrl.toString() : this.printerUrl)
url.port = this.hostPort.toString()
@@ -53,8 +51,8 @@ export default class WebrtcCameraStreamer extends Mixins(BaseMixin) {
}
let transforms = ''
if ('flipX' in this.camSettings && this.camSettings.flipX) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flipY) transforms += ' scaleY(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_horizontal) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_vertical) transforms += ' scaleY(-1)'
if (transforms.trimStart().length) output.transform = transforms.trimStart()
if (this.aspectRatio) output.aspectRatio = this.aspectRatio
+8 -9
View File
@@ -20,13 +20,12 @@
<script lang="ts">
import { Component, Mixins, Prop, Ref, Watch } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
@Component
export default class WebrtcRTSPSimpleServer extends Mixins(BaseMixin) {
@Prop({ required: true }) camSettings: any
@Ref()
declare video: HTMLVideoElement
@Prop({ required: true }) readonly camSettings!: GuiWebcamStateWebcam
@Ref() declare video: HTMLVideoElement
// webrtc player vars
private terminated: boolean = false
@@ -47,19 +46,19 @@ export default class WebrtcRTSPSimpleServer extends Mixins(BaseMixin) {
get webcamStyle() {
let transforms = ''
if ('flipX' in this.camSettings && this.camSettings.flipX) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flipY) transforms += ' scaleY(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_horizontal) transforms += ' scaleX(-1)'
if ('flipX' in this.camSettings && this.camSettings.flip_vertical) transforms += ' scaleY(-1)'
if (transforms.trimStart().length) return { transform: transforms.trimStart() }
return ''
}
get url() {
if (this.camSettings.urlStream.startsWith('http')) {
return this.camSettings.urlStream.replace('http', 'ws') + 'ws'
if (this.camSettings.stream_url.startsWith('http')) {
return this.camSettings.stream_url.replace('http', 'ws') + 'ws'
}
return this.camSettings.urlStream
return this.camSettings.stream_url
}
// stop and restart the video if the url changes
-1
View File
@@ -851,7 +851,6 @@
"DbHistoryTotals": "Historie Gesamtzähler",
"DbTimelapseSettings": "Zeitraffer Einstellungen",
"DbView": "Ansichtseinstellungen",
"DbWebcams": "Webcams",
"EstimateValues": {
"Filament": "Filament",
"File": "Datei",
-1
View File
@@ -851,7 +851,6 @@
"DbHistoryTotals": "History Totals",
"DbTimelapseSettings": "Timelapse Settings",
"DbView": "View Settings",
"DbWebcams": "Webcams",
"EstimateValues": {
"Filament": "Filament",
"File": "File",
+5 -8
View File
@@ -230,13 +230,10 @@ export const actions: ActionTree<FarmPrinterState, RootState> = {
})
}
if (payload.namespaces.includes('webcams')) {
dispatch('sendObj', {
method: 'server.database.get_item',
params: { namespace: 'webcams' },
action: 'getWebcamsData',
})
}
dispatch('sendObj', {
method: 'server.webcams.list',
action: 'getWebcamsData',
})
},
getMainsailData({ commit }, payload) {
@@ -244,6 +241,6 @@ export const actions: ActionTree<FarmPrinterState, RootState> = {
},
getWebcamsData({ commit }, payload) {
commit('setWebcamsData', payload.value)
commit('setWebcamsData', payload.webcams)
},
}
+1 -9
View File
@@ -308,14 +308,6 @@ export const getters: GetterTree<FarmPrinterState, any> = {
},
getPrinterWebcams: (state) => {
const webcams: GuiWebcamStateWebcam[] = []
if (state.data.webcams) {
Object.keys(state.data.webcams).forEach((id: string) => {
webcams.push({ ...state.data?.webcams[id], id })
})
}
return webcams
return state.data.webcams.filter((webcam: GuiWebcamStateWebcam) => webcam.enabled)
},
}
+1 -1
View File
@@ -26,7 +26,7 @@ export const getDefaultState = (): FarmPrinterState => {
},
data: {
gui: getGuiDefaultState(),
webcams: {},
webcams: [],
},
settings: {},
databases: [],
+1 -3
View File
@@ -8,9 +8,7 @@ export interface FarmPrinterState {
server: FarmPrinterStateServer
data: {
gui: GuiState
webcams: {
[key: string]: GuiWebcamStateWebcam
}
webcams: GuiWebcamStateWebcam[]
// eslint-disable-next-line
[key: string]: any
}
+10 -32
View File
@@ -1,7 +1,6 @@
import { ActionTree } from 'vuex'
import { RootState } from '@/store/types'
import { GuiWebcamState } from '@/store/gui/webcams/types'
import { v4 as uuidv4 } from 'uuid'
import { GuiWebcamState, GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
import Vue from 'vue'
export const actions: ActionTree<GuiWebcamState, RootState> = {
@@ -11,46 +10,25 @@ export const actions: ActionTree<GuiWebcamState, RootState> = {
init() {
window.console.debug('init gui/webcams')
Vue.$socket.emit('server.database.get_item', { namespace: 'webcams' }, { action: 'gui/webcams/initStore' })
Vue.$socket.emit('server.webcams.list', {}, { action: 'gui/webcams/initStore' })
},
async initStore({ commit, dispatch }, payload) {
await commit('reset')
await commit('initStore', payload)
await commit('initStore', payload.webcams)
await dispatch('socket/removeInitModule', 'gui/webcam/init', { root: true })
},
upload(_, payload) {
Vue.$socket.emit('server.database.post_item', { namespace: 'webcams', key: payload.id, value: payload.value })
store(_, payload) {
Vue.$socket.emit('server.webcams.post_item', payload)
},
store({ commit, dispatch, state }, payload) {
const id = uuidv4()
commit('store', { id, values: payload.values })
dispatch('upload', {
id,
value: state.webcams[id],
})
update({ dispatch }, payload: { webcam: GuiWebcamStateWebcam; oldWebcamName: string }) {
Vue.$socket.emit('server.webcams.post_item', payload.webcam)
if (payload.webcam.name !== payload.oldWebcamName) dispatch('delete', payload.oldWebcamName)
},
update({ commit, dispatch, state, rootState }, payload) {
commit('update', payload)
dispatch('upload', {
id: payload.id,
value: state.webcams[payload.id],
})
if (
rootState.server?.components.includes('timelapse') &&
rootState.server?.timelapse?.settings.camera === payload.id
) {
dispatch('server/timelapse/saveSetting', { camera: payload.id }, { root: true })
}
},
delete({ commit }, payload) {
commit('delete', payload)
Vue.$socket.emit('server.database.delete_item', { namespace: 'webcams', key: payload })
delete(_, payload: string) {
Vue.$socket.emit('server.webcams.delete_item', { name: payload })
},
}
+3 -9
View File
@@ -4,18 +4,12 @@ import { GuiWebcamState, GuiWebcamStateWebcam } from '@/store/gui/webcams/types'
// eslint-disable-next-line
export const getters: GetterTree<GuiWebcamState, any> = {
getWebcams: (state) => {
const webcams: GuiWebcamStateWebcam[] = []
Object.keys(state.webcams).forEach((id: string) => {
webcams.push({ ...state.webcams[id], id })
})
return webcams
return state.webcams.filter((webcam: GuiWebcamStateWebcam) => webcam.enabled)
},
getWebcam: (state, getters) => (camId: string) => {
getWebcam: (_, getters) => (name: string) => {
const webcams = getters['getWebcams'] ?? []
return webcams.find((webcam: GuiWebcamStateWebcam) => webcam.id === camId)
return webcams.find((webcam: GuiWebcamStateWebcam) => webcam.name === name)
},
}
+1 -1
View File
@@ -6,7 +6,7 @@ import { GuiWebcamState } from '@/store/gui/webcams/types'
export const getDefaultState = (): GuiWebcamState => {
return {
webcams: {},
webcams: [],
}
}
+1 -20
View File
@@ -9,25 +9,6 @@ export const mutations: MutationTree<GuiWebcamState> = {
},
initStore(state, payload) {
Vue.set(state, 'webcams', payload.value)
},
store(state, payload) {
Vue.set(state.webcams, payload.id, payload.values)
},
update(state, payload) {
if (payload.id in state.webcams) {
const webcam = { ...state.webcams[payload.id] }
Object.assign(webcam, payload.values)
Vue.set(state.webcams, payload.id, webcam)
}
},
delete(state, payload) {
if (payload in state.webcams) {
Vue.delete(state.webcams, payload)
}
Vue.set(state, 'webcams', payload)
},
}
+23 -11
View File
@@ -1,18 +1,30 @@
export interface GuiWebcamState {
webcams: {
[key: string]: GuiWebcamStateWebcam
}
webcams: GuiWebcamStateWebcam[]
}
export interface GuiWebcamStateWebcam {
id?: string
name: string
location?: string
service:
| 'hlsstream'
| 'ipstream'
| 'jmuxer-stream'
| 'mjpegstreamer'
| 'mjpegstreamer-adaptive'
| 'uv4l-mjpeg'
| 'webrtc-camerastreamer'
| 'webrtc-janus'
| 'webrtc-mediamtx'
enabled: boolean
icon: string
service: 'mjpegstreamer' | 'mjpegstreamer-adaptive' | 'uv4l-mjpeg' | 'ipstream'
targetFps: number
urlStream: string
urlSnapshot: string
rotate?: number
flipX: boolean
flipY: boolean
target_fps: number
target_fps_idle?: number
stream_url: string
snapshot_url: string
flip_horizontal: boolean
flip_vertical: boolean
rotation: number
aspect_ratio?: string
extra_data?: {}
source?: 'config' | 'database'
}
+4
View File
@@ -124,6 +124,10 @@ export const actions: ActionTree<SocketState, RootState> = {
dispatch('server/announcements/getWaked', payload.params[0], { root: true })
break
case 'notify_webcams_changed':
dispatch('gui/webcams/initStore', payload.params[0], { root: true })
break
default:
window.console.debug(payload)
}
+1 -1
View File
@@ -2,7 +2,7 @@ export const defaultLogoColor = '#D41216'
export const defaultPrimaryColor = '#2196f3'
export const minKlipperVersion = 'v0.11.0-97'
export const minMoonrakerVersion = 'v0.7.1-797'
export const minMoonrakerVersion = 'v0.8.0-38'
export const colorArray = ['#F44336', '#8e379d', '#03DAC5', '#3F51B5', '#ffde03', '#009688', '#E91E63']