@@ -19,6 +19,8 @@ import {
1919 SettingsPageLayout ,
2020 SettingsPagePaneLayout ,
2121} from '@/components/settings/SettingsPageLayout' ;
22+ import { yupResolver } from '@hookform/resolvers/yup' ;
23+ import { boolean , number , object , string } from 'yup' ;
2224
2325interface VRCOSCSettingsForm {
2426 vrchat : {
@@ -66,13 +68,68 @@ export function VRCOSCSettings() {
6668 const { l10n } = useLocalization ( ) ;
6769 const { sendRPCPacket, useRPCPacket } = useWebsocketAPI ( ) ;
6870
71+ const bannedPorts = [ 6969 , 21110 ] ;
6972 const { reset, control, watch, handleSubmit } = useForm < VRCOSCSettingsForm > ( {
7073 defaultValues,
74+ reValidateMode : 'onChange' ,
75+ mode : 'onChange' ,
76+ resolver : yupResolver (
77+ object ( {
78+ vrchat : object ( {
79+ oscSettings : object ( {
80+ enabled : boolean ( ) . required ( ) ,
81+ portIn : number ( )
82+ . typeError ( ' ' )
83+ . required ( )
84+ . test (
85+ 'ports-dont-match' ,
86+ l10n . getString ( 'settings-osc-vrchat-network-ports_match_error' ) ,
87+ ( port , context ) => port != context . parent . portOut
88+ )
89+ . notOneOf ( bannedPorts , ( context ) =>
90+ l10n . getString (
91+ 'settings-osc-vrchat-network-port_banned_error' ,
92+ { port : context . originalValue }
93+ )
94+ ) ,
95+ portOut : number ( )
96+ . typeError ( ' ' )
97+ . required ( )
98+ . test (
99+ 'ports-dont-match' ,
100+ l10n . getString ( 'settings-osc-vrchat-network-ports_match_error' ) ,
101+ ( port , context ) => port != context . parent . portIn
102+ )
103+ . notOneOf ( bannedPorts , ( context ) =>
104+ l10n . getString (
105+ 'settings-osc-vrchat-network-port_banned_error' ,
106+ { port : context . originalValue }
107+ )
108+ ) ,
109+ address : string ( )
110+ . required ( ' ' )
111+ . matches (
112+ / ^ (? ! 0 ) (? ! .* \. $ ) ( ( 1 ? \d ? \d | 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] \d ) ( \. | $ ) ) { 4 } $ / i,
113+ {
114+ message : ' ' ,
115+ }
116+ ) ,
117+ } ) ,
118+ trackers : object ( {
119+ head : boolean ( ) . required ( ) ,
120+ chest : boolean ( ) . required ( ) ,
121+ elbows : boolean ( ) . required ( ) ,
122+ feet : boolean ( ) . required ( ) ,
123+ knees : boolean ( ) . required ( ) ,
124+ hands : boolean ( ) . required ( ) ,
125+ waist : boolean ( ) . required ( ) ,
126+ } ) ,
127+ oscqueryEnabled : boolean ( ) . required ( ) ,
128+ } ) ,
129+ } )
130+ ) ,
71131 } ) ;
72132
73- const formValues = watch ( ) ;
74- const bannedPorts = [ 6969 , 21110 ] ;
75-
76133 const onSubmit = ( values : VRCOSCSettingsForm ) => {
77134 const settings = new ChangeSettingsRequestT ( ) ;
78135
@@ -207,25 +264,6 @@ export function VRCOSCSettings() {
207264 type = "number"
208265 control = { control }
209266 name = "vrchat.oscSettings.portIn"
210- rules = { {
211- required : true ,
212- validate : ( portIn ) => {
213- if (
214- Number ( portIn ) ===
215- Number ( formValues . vrchat . oscSettings . portOut )
216- ) {
217- return l10n . getString (
218- 'settings-osc-vrchat-network-ports_match_error'
219- ) ;
220- }
221- if ( bannedPorts . includes ( Number ( portIn ) ) ) {
222- return l10n . getString (
223- 'settings-osc-vrchat-network-port_banned_error' ,
224- { port : portIn }
225- ) ;
226- }
227- } ,
228- } }
229267 placeholder = "9001"
230268 label = ""
231269 > </ Input >
@@ -238,25 +276,6 @@ export function VRCOSCSettings() {
238276 type = "number"
239277 control = { control }
240278 name = "vrchat.oscSettings.portOut"
241- rules = { {
242- required : true ,
243- validate : ( portOut ) => {
244- if (
245- Number ( portOut ) ===
246- Number ( formValues . vrchat . oscSettings . portIn )
247- ) {
248- return l10n . getString (
249- 'settings-osc-vrchat-network-ports_match_error'
250- ) ;
251- }
252- if ( bannedPorts . includes ( Number ( portOut ) ) ) {
253- return l10n . getString (
254- 'settings-osc-vrchat-network-port_banned_error' ,
255- { port : portOut }
256- ) ;
257- }
258- } ,
259- } }
260279 placeholder = "9000"
261280 label = ""
262281 > </ Input >
@@ -277,11 +296,6 @@ export function VRCOSCSettings() {
277296 type = "text"
278297 control = { control }
279298 name = "vrchat.oscSettings.address"
280- rules = { {
281- required : true ,
282- pattern :
283- / ^ (? ! 0 ) (? ! .* \. $ ) ( ( 1 ? \d ? \d | 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] \d ) ( \. | $ ) ) { 4 } $ / i,
284- } }
285299 placeholder = { l10n . getString (
286300 'settings-osc-vrchat-network-address-placeholder'
287301 ) }
0 commit comments