diff --git a/resources/views/user/pages/tutorial_tes/index.blade.php b/resources/views/user/pages/tutorial_tes/index.blade.php index 14eb22b..f4d7d5c 100644 --- a/resources/views/user/pages/tutorial_tes/index.blade.php +++ b/resources/views/user/pages/tutorial_tes/index.blade.php @@ -30,37 +30,10 @@
  1. Persiapan: Pastikan Tobii sudah terhubung dan berfungsi dengan baik.
  2. Penempatan: Tempatkan Tobii di posisi yang sesuai untuk mendeteksi gerakan mata dengan akurat.
  3. -
  4. Hubungkan Tobii: Hubungkan Tobii ke dalam web dengan menggunakan link API dibawah ini.
  5. +
  6. Hubungkan Tobii: Hubungkan Tobii ke dalam web dengan menggunakan aplikasi API, jika tidak terhubung, hubungi administrator.
  7. Hasil: Setelah menghubungkan ke web berhasil, akan muncul notifikasi bahwa Tobii telah terhubung.
  8. Selanjutnya: Melakukan kalibrasi mata dengan Tobii.
-
Link API Tobii:
-
-
- -
-
- -
-
-
Link ID Tobii:
-
-
- -
-
- -
-
-
Link Token Tobii:
-
-
- -
-
- -
-

Memuat...

@@ -128,10 +101,79 @@ let getDataInterval = false; let checkTobiiInterval = null; let tobiiConnectedStatus = false; - const ws = new WebSocket('{{ env("WEBSOCKET_URL") }}'); + let ws = null; + let reconnectDelay = 1000; + let maxReconnectDelay = 10000; let SESSION_ID = '{{ $data_session->id_test_sessions }}'; let TOKEN_SESSION = '{{ $data_session->token_session }}'; + function startWebsocket() { + console.log("Connecting to WebSocket..."); + ws = new WebSocket('{{ env("WEBSOCKET_URL") }}'); + ws.onopen = () => { + console.log("Connected to WebSocket"); + reconnectDelay = 1000; + ws.send(JSON.stringify({ + type: "register", + session_id: SESSION_ID, + token_session: TOKEN_SESSION, + role: "web" + })); + + searchingTobiiDevice(); + + ws.send(JSON.stringify({ + type: "update_status", + status_sessions: false, + id_session: SESSION_ID + })); + }; + + ws.onmessage = (event) => { + const data = JSON.parse(event.data); + console.log('Received data from WebSocket:', data); + + if(data.type === 'tobii_data') { + try { + moveTheEye(data.gaze_x, data.gaze_y); + } catch(error) { + console.log(error); + } + } + + if(data.type === 'status_tobii_device') { + if(data.status) { + console.log('Tobii device is connected'); + tobiiConnectedStatus = true; + } else { + console.log('Tobii device is not connected'); + tobiiConnectedStatus = false; + searchingTobiiDevice(); + } + checkTobiiConnection(); + } + + if(data.type === 'reset_start_tobii') { + startTobii(); + } + }; + + ws.onerror = function (error) { + console.log("WebSocket error"); + }; + + ws.onclose = function () { + setTimeout(() => { + reconnectDelay = Math.min( + reconnectDelay * 2, + maxReconnectDelay + ); + console.log("Disconnected from WebSocket. Retrying in " + reconnectDelay + " ms..."); + startWebsocket(); + }, reconnectDelay); + }; + } + function showTutorial(step, tutorialId) { $(`#${tutorialId}`).hide(); $(`#tutorial_${step}`).show(); @@ -297,6 +339,39 @@ function checkTobiiConnection() { } } + async function searchingTobiiDevice() { + try { + console.log('Searching for tobii...'); + const response = await fetch('{{ env('TOBII_API_URL') }}', { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify({ + session_id: SESSION_ID, + token: TOKEN_SESSION, + url: "{{ env('WEBSOCKET_URL') }}" + }) + } + ); + if (!response.ok) { + console.error('Failed to get tobii device, retrying...'); + setTimeout(5000); + searchingTobiiDevice(); + return; + } + const data = await response.json(); + if(data.session_id == SESSION_ID && data.token == TOKEN_SESSION) { + tobiiConnectedStatus = true; + console.log('Done searching...'); + } + } catch (error) { + console.error('Error getting Tobii device:', error); + setTimeout(5000); + searchingTobiiDevice(); + } + } + function startTobii() { ws.send(JSON.stringify({ type: "command", @@ -320,50 +395,8 @@ function stopTobii() { $('#calibration_point').hide(); $('#show_calibration').hide(); generateLinkApiTobii(); - - ws.onopen = () => { - console.log("Connected to WebSocket"); - ws.send(JSON.stringify({ - type: "register", - session_id: SESSION_ID, - token_session: TOKEN_SESSION, - role: "web" - })); - - ws.send(JSON.stringify({ - type: "update_status", - status_sessions: false, - id_session: SESSION_ID - })); - }; - - ws.onmessage = (event) => { - const data = JSON.parse(event.data); - console.log('Received data from WebSocket:', data); - - if(data.type === 'tobii_data') { - try { - moveTheEye(data.gaze_x, data.gaze_y); - } catch(error) { - console.log(error); - } - } - - if(data.type === 'status_tobii_device') { - if(data.status) { - console.log('Tobii device is connected'); - tobiiConnectedStatus = true; - } else { - console.log('Tobii device is not connected'); - tobiiConnectedStatus = false; - } - checkTobiiConnection(); - } - - if(data.type === 'reset_start_tobii') { - startTobii(); - } - }; + startWebsocket(); + console.log("hehehehehehehehehhehehe"); }); diff --git a/resources/views/user/pages/ujian/temp_index.blade.php b/resources/views/user/pages/ujian/temp_index.blade.php index 76112ff..6ae7197 100644 --- a/resources/views/user/pages/ujian/temp_index.blade.php +++ b/resources/views/user/pages/ujian/temp_index.blade.php @@ -70,7 +70,9 @@ @section('script') @endsection \ No newline at end of file