44using Cysharp . Threading . Tasks ;
55using HelloWorld ;
66using UnityEngine ;
7+ using UnityEngine . UI ;
78using Vuplex . WebView ;
89using WebViewRPC ;
910
@@ -12,10 +13,19 @@ namespace SampleRpc
1213 public class WebViewRpcTester : MonoBehaviour
1314 {
1415 [ SerializeField ] private CanvasWebViewPrefab webViewPrefab ;
16+ [ SerializeField ] private Button image ;
17+ [ SerializeField ] private Text text ;
18+
1519 private HelloServiceClient _client ;
1620 private WebViewRpcServer _server ;
1721 private WebViewRpcClient _rpcClient ;
1822 private IWebViewBridge _bridge ;
23+
24+ // 시작 시간
25+ private float _startTime ;
26+
27+ // 지연 시간 설정 (Inspector에서 조정 가능)
28+ [ SerializeField ] private float serviceRegistrationDelay = 3.0f ;
1929
2030 private void Awake ( )
2131 {
@@ -27,7 +37,7 @@ private async void Start()
2737 // Set chunking configuration
2838 try
2939 {
30- WebViewRpcConfiguration . MaxChunkSize = 900 ; // 900 bytes for testing
40+ WebViewRpcConfiguration . MaxChunkSize = 1024 ; // 900 bytes for testing
3141 WebViewRpcConfiguration . EnableChunking = true ;
3242 WebViewRpcConfiguration . ChunkTimeoutSeconds = 10 ; // 10 seconds for testing
3343
@@ -46,27 +56,47 @@ private async void Start()
4656 }
4757
4858 await InitializeWebView ( webViewPrefab ) ;
59+
60+ Debug . Log ( $ "[EXTREME TIMING TEST] WebView loaded, but intentionally delaying service registration for { serviceRegistrationDelay } seconds...") ;
61+ Debug . Log ( $ "[{ DateTime . Now : yyyy-MM-dd HH:mm:ss.fff} ] Starting delay...") ;
62+
63+ // 의도적으로 서비스 등록을 지연시킴
64+ await UniTask . Delay ( TimeSpan . FromSeconds ( serviceRegistrationDelay ) ) ;
65+
66+ Debug . Log ( $ "[{ DateTime . Now : yyyy-MM-dd HH:mm:ss.fff} ] Delay finished, now registering services...") ;
4967
5068 // Initialize C# Server to handle JS -> C# RPC
5169 _bridge = new ViewplexWebViewBridge ( webViewPrefab ) ;
5270 _server = new WebViewRpcServer ( _bridge ) ;
5371 _server . Services . Add ( HelloService . BindService ( new HelloWorldService ( ) ) ) ;
5472 _server . Start ( ) ;
73+
74+ Debug . Log ( $ "[{ DateTime . Now : yyyy-MM-dd HH:mm:ss.fff} ] Unity RPC Server is now ready!") ;
5575
5676 // Initialize C# Client to handle C# -> JS RPC
5777 _rpcClient = new WebViewRpcClient ( _bridge ) ;
5878 _client = new HelloServiceClient ( _rpcClient ) ;
79+
80+ // On Button Click, run the bidirectional chunking test
81+ image . onClick . AddListener ( RunBidirectionalChunkingTest ) ;
82+ // Set button color to blue initially
83+ image . GetComponent < Image > ( ) . color = Color . blue ;
84+
85+ text . text = "Click to send another request" ; // Reset UI text
5986 }
6087
6188 private async void RunBidirectionalChunkingTest ( )
6289 {
63- Debug . Log ( "--- [C# Client] Sending Hello Request ---" ) ;
90+ Debug . Log ( "--- [C# Client] Starting Bidirectional Chunking Test ---" ) ;
91+ Debug . Log ( "[C# Client] Waiting for WebView server to be ready..." ) ;
92+
93+ _startTime = Time . time ; // Record start time
6494
6595 // Create a very long message for chunking test
6696 var sb = new StringBuilder ( ) ;
67- for ( int i = 0 ; i < 3 ; i ++ )
97+ for ( int i = 0 ; i < 60 ; i ++ )
6898 {
69- sb . Append ( new string ( ( char ) ( 'X' + i ) , 2000 ) ) ;
99+ sb . Append ( new string ( ( char ) ( 'X' + i ) , 1024 ) ) ;
70100 }
71101 var longMessage = sb . ToString ( ) ;
72102
0 commit comments