In this lesson we will be creating the part where the back end receives the sheikh event from your phone.
First I want you to go to get a website where you will find Sheikh J.F..
The link is get hub dot com slash Alex Gibson slash shake dot J.S. about the licensing click on the
license M.D. link.
It says that it is free of charge and we can modify it although we need to include the copyright in
the software.
So make sure you read the conditions and include the information you need as you scroll down the site
you will see the sample codes.
I'll be explaining how the codes are structured later on in this lesson.
Scroll down to the bottom of the page where you will find the support of web browser information you
will need to set one of the supportive web browser to be able to use the shake function.
Basically the recent funds will be supporting these web browsers so you wouldn't have any problems if
you do encounter any problems.
You can use the get request and make some changes in your code.
Now scroll to the top of the page and click on the shake J S link.
Once the page opens click on Raw.
You need to download this onto your computer.
I'll save this to my desktop as well.
Next we'll place the shake J S in PI term.
Here you can see the shake J S file on my desktop.
Now let's go onto the project tab.
Find the JSF folder and click to open.
Then we can drag the shape J S file to the JSF folder and hit.
OK.
Next we want to read the changes so let's go to the layout H Jamil to read the sheik file.
Copy this last script and paste rewrite the Jake where he mobile.
Part 2 Jake to shake J.S.
now we will move to the Games folder under templates.
Go to the sheik HDMI all file so we can add some codes.
Now let's start by creating a button.
We can set H ref and set sharp data roll we'll be set to button click.
We'll be a new function name send start shake which we will be creating later on.
Return will be false.
Let's name this button start next we'll create the sense start shake function go to the top of the block
content and start a script.
Here we will be creating the function send start shake.
Set left I.D. here we want to get the course name it but name will be set course pick and to the course
that has check on it and set this to the value then we set a post to send this to the back end side.
There you are.
L will be slash API slash Sheik slash start the parameter will be set to I.D. so we can get the course
I.D. once the post is successfully sent.
We will be receiving data from the back end.
The data will be Jason so you can set any name for this data as a result.
We want to set the information.
If the function has been started or not so we set the result with HDMI l data result.
This will be sent as a Jason type.
Once you've completed these codes I want you to go to the get hab Web site where we have the sheik J.S.
code samples.
We've just created the script here.
We will be using the new Sheik without the options in the sample so we can just copy the first line.
Let's rewrite the name to Sheikh event.
Next we go onto start.
The name will be Sheikh event.
Start method.
Once you've created these to Sheikh events I want you to copy and paste this window.
Add event listener here we will be setting the content for this function.
Once the phone has been shaken this sheikh event did occur.
Function will be invoked.
Let's go on and complete this function in the sense start function.
We created a code to get the course I.D. we will be using that again in this function so you can copy
the code and paste.
Also once the phone is shaken we need to send this to the back end side so let's copy the next line
and paste in this code.
We need to rewrite the URL from start to run.
This will also be an adjacent type.
So let's add that to the end.
In this function the result will be the elapsed time the elapsed time can be a long number such as 4.5
6 6 7 7 seconds which is a bit too long.
In this case we can use to fixed and set the number 2 to make the numbers shorter then set the time
as a string.
The result will be based on seconds.
So let's add the alphabet s to the result.
If the data is not running that means the game is over so we will set the result to a text message done
in a new line.
Once the results are in we want to show the results in the Jake worry I.D. as we are using post.
We need to change a couple of codes in the server P why we were using get but as we change the codes
to post we can now change the codes to receive with form.
Now we are ready to run the code.
But before running this code we will need to connect a USB cable and prepare so I'll leave this lesson
here and we'll see you in our next lesson.