@@ -20,16 +20,15 @@ import {
2020 SettingsPagePaneLayout ,
2121} from '@/components/settings/SettingsPageLayout' ;
2222import { yupResolver } from '@hookform/resolvers/yup' ;
23- import { boolean , number , object , string } from 'yup' ;
23+ import { boolean , object } from 'yup' ;
24+ import {
25+ OSCSettings ,
26+ useOscSettingsValidator ,
27+ } from '@/hooks/osc-setting-validator' ;
2428
2529interface VRCOSCSettingsForm {
2630 vrchat : {
27- oscSettings : {
28- enabled : boolean ;
29- portIn : number ;
30- portOut : number ;
31- address : string ;
32- } ;
31+ oscSettings : OSCSettings ;
3332 trackers : {
3433 head : boolean ;
3534 chest : boolean ;
@@ -67,54 +66,16 @@ const defaultValues = {
6766export function VRCOSCSettings ( ) {
6867 const { l10n } = useLocalization ( ) ;
6968 const { sendRPCPacket, useRPCPacket } = useWebsocketAPI ( ) ;
69+ const { oscValidator } = useOscSettingsValidator ( ) ;
7070
71- const bannedPorts = [ 6969 , 21110 ] ;
7271 const { reset, control, watch, handleSubmit } = useForm < VRCOSCSettingsForm > ( {
7372 defaultValues,
7473 reValidateMode : 'onChange' ,
7574 mode : 'onChange' ,
7675 resolver : yupResolver (
7776 object ( {
7877 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- } ) ,
78+ oscSettings : oscValidator ,
11879 trackers : object ( {
11980 head : boolean ( ) . required ( ) ,
12081 chest : boolean ( ) . required ( ) ,
0 commit comments