Last active
December 20, 2019 08:33
-
-
Save gtindo/f9de3ba2b107a7220f2bd03f4eaf09de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Test socket</title> | |
</head> | |
<body> | |
<form> | |
<input type="text" id="zone" /> | |
<button id="btnZone">Valid</button> | |
</form> | |
<br /> | |
<div> | |
<button id="authBtn">Authentication</button> <br /><br /> | |
<button id="qcmBtn">QCM Challenge</button> <br /><br /> | |
<button id="qcmQuestionBtn">QCM Question</button> <br /><br /> | |
<button id="posBtn">Head Position challenge</button> <br /><br /> | |
<button id="gestureBtn">Hand gesture challenge</button> <br /><br /> | |
<button id="numberBtn">Hand gesture number</button> <br /><br /> | |
<button id="endBtn">End stream</button><br /><br /> | |
</div> | |
<script> | |
var SECRET_KEY = 'izWgIZpP9qAUF1LX8VB1iuwPu9Gu7rrC' | |
var btnAuth = document.getElementById("authBtn"); | |
var qcmBtn = document.getElementById("qcmBtn"); | |
var qcmQuestionBtn = document.getElementById("qcmQuestionBtn"); | |
var posBtn = document.getElementById("posBtn"); | |
var gestureBtn = document.getElementById("gestureBtn"); | |
var numberBtn = document.getElementById("numberBtn"); | |
var endBtn = document.getElementById("endBtn") | |
var ws = new WebSocket("ws://127.0.0.1:5678/"); | |
ws.onopen = async function (event) { | |
mobile_uuid = "970a91ce-e88c-4bad-b8e4-5afc5d611113" | |
hashBuffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(mobile_uuid+"sasdvwqe"+SECRET_KEY)); | |
hashArray = Array.from(new Uint8Array(hashBuffer)); | |
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); | |
console.log(hashHex); | |
session_id = "d161efad-d370-41d3-9810-d08e75d9f78f" | |
var message = { | |
action: "auth/", | |
data: { | |
mobile_uuid: mobile_uuid, | |
random_uuid: "sasdvwqe", | |
client_hash: hashHex | |
} | |
} | |
var qcm_message = { | |
action: "challenge/qcm/", | |
data: { | |
mobile_uuid: mobile_uuid, | |
session_id: session_id, | |
lang: "fr" | |
} | |
} | |
var qcm_question_message = { | |
action: "challenge/qcm/question/", | |
data: { | |
mobile_uuid: mobile_uuid, | |
session_id: session_id, | |
question_id: 2, | |
lang: "fr", | |
pos1: "LEFT", | |
pos2: "RIGHT" | |
} | |
} | |
var head_position_message = { | |
action: "challenge/head_movement/", | |
data: { | |
mobile_uuid: mobile_uuid, | |
session_id: session_id | |
} | |
} | |
var hand_gesture_message = { | |
action: "challenge/hand_gesture/", | |
data: { | |
mobile_uuid: mobile_uuid, | |
session_id: session_id | |
} | |
} | |
var hand_gesture_number = { | |
action: "challenge/hand_gesture/number/", | |
data: { | |
mobile_uuid: mobile_uuid, | |
session_id: session_id, | |
number: 8 | |
} | |
} | |
var stop_stream = { | |
action: "stream/end/", | |
data: { | |
mobile_uuid: mobile_uuid, | |
session_id: session_id | |
} | |
} | |
console.log("Open") | |
ws.onmessage = function (event) { | |
console.log(JSON.parse(event.data)); | |
}; | |
btnAuth.addEventListener("click", () => { | |
ws.send(JSON.stringify(message)); | |
}); | |
qcmBtn.addEventListener("click", () => { | |
ws.send(JSON.stringify(qcm_message)); | |
}); | |
qcmQuestionBtn.addEventListener("click", () => { | |
ws.send(JSON.stringify(qcm_question_message)); | |
}); | |
posBtn.addEventListener("click", () => { | |
ws.send(JSON.stringify(head_position_message)); | |
}); | |
gestureBtn.addEventListener("click", () => { | |
ws.send(JSON.stringify(hand_gesture_message)); | |
}); | |
numberBtn.addEventListener("click", () => { | |
ws.send(JSON.stringify(hand_gesture_number)); | |
}); | |
endBtn.addEventListener("click", () => { | |
ws.send(JSON.stringify(stop_stream)) | |
}); | |
ws.onclose = function(event) { | |
console.log("close") | |
} | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment