<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dominik Sasko on Medium]]></title>
        <description><![CDATA[Stories by Dominik Sasko on Medium]]></description>
        <link>https://medium.com/@saskodominik?source=rss-4ecfc08e8bb6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IPVR3VsQ4FNvhl9f7qi7Vg.jpeg</url>
            <title>Stories by Dominik Sasko on Medium</title>
            <link>https://medium.com/@saskodominik?source=rss-4ecfc08e8bb6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 04:53:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saskodominik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Create a Hybrid Chat App With React.js]]></title>
            <link>https://medium.com/the-web-tub/how-to-create-a-hybrid-chat-app-with-react-js-d3348be325da?source=rss-4ecfc08e8bb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3348be325da</guid>
            <category><![CDATA[monaca]]></category>
            <category><![CDATA[redux-toolkit]]></category>
            <category><![CDATA[hybrid-app-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[chat-app-development]]></category>
            <dc:creator><![CDATA[Dominik Sasko]]></dc:creator>
            <pubDate>Wed, 06 Jul 2022 12:32:44 GMT</pubDate>
            <atom:updated>2023-04-09T18:47:40.401Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Mobile phone with chat application and with chat bubbles above." src="https://cdn-images-1.medium.com/max/1024/1*LSCP0zlvtx-QMW8IwYm2fw.jpeg" /><figcaption>Let’s Write chat application.</figcaption></figure><p>In this tutorial we will learn how to create a live chat hybrid app, where people can join a chat group and communicate together (similar to Discord). <br>The app uses React.js to create the UI, with a help from <a href="https://framework7.io/">Framework7</a> to style components like messages. Redux Toolkit is used as state management (even though Context API would be enough, it is good to learn the fundamentals on small projects before moving on to bigger ones). As for the database, Firebase provides the authentication and the data storage. This article will explain just the main parts of code, styling and basic React code will not be covered.</p><p>After finishing the tutorial, you will have a functioning app that can be run on a desktop, as well as on iOS or Android devices (with the help of <a href="https://monaca.io/">Monaca</a> deployment).</p><p>Link for the repository: <a href="https://github.com/DomSas/Chat-App">Chat App</a></p><h4>Terminology</h4><p>First of all, let’s go through definitions of technologies which will be used.</p><p><a href="https://redux-toolkit.js.org/"><strong>Redux Toolkit</strong></a><strong><br></strong>Most of you probably have experience with React.js and passing data through props. To get around problems as “prop drilling” (passing props multiple layers from parent to child) and have the data globally available in every part of the app, we can use <a href="https://reactjs.org/docs/context.html">Context API</a> or Redux Toolkit. The later one is meant to be a successor of React Redux, with easier configuration and less boilerplate code to write to set up a Redux store. Nowadays, the Redux team officially recommends Redux Toolkit as a state management solution.</p><p><a href="https://firebase.google.com/"><strong>Firebase</strong></a><strong><br></strong>“App development platform that helps you build and grow apps and games users love.” Firebase provides multiple cloud solutions, from which we will be using authentication and Firestore database. Since these products are for free, you will not need to buy any subscription.</p><p><a href="https://monaca.io/"><strong>Monaca</strong></a><strong><br></strong>Cross-platform hybrid mobile app development platform and tools in the cloud. In this app, Monaca will serve as a simple solution for deployment on a mobile device. You also have the possibility of development in the cloud with Monaca Cloud IDE, so you do not have to download anything on your computer.</p><h4>Prerequisites:</h4><ul><li>Node v12.22.0 or higher,</li><li>free account on <a href="https://monaca.mobi/en/login">Monaca</a>,</li><li>free account on <a href="https://firebase.google.com/">Firebase</a>.</li></ul><h4>Workflow:</h4><ol><li>Implement authentication of user.</li><li>Create Redux Toolkit store.</li><li>Add database of chat groups.</li><li>Enable the users to send and receive messages.</li><li>Bonus: Building on Windows, PWA and Firebase deployment.</li></ol><h4>App Wireframe</h4><figure><img alt="Three phones with pages showing the wireframe of chat app." src="https://cdn-images-1.medium.com/max/1024/1*hhgRhti_rGYeoOpcT3uK1g.png" /><figcaption>Chat App wireframe.</figcaption></figure><h4>Setting up The Project</h4><p>To simplify the development, we can start from a template provided by Monaca CLI. After creating an account, open the console and write the following commands:</p><pre>$ npm install -g monaca         // install Monaca CLI<br>$ monaca login                  // login with your new account<br>$ monaca create Chat-App        // create new project</pre><pre>Choose: Onsen UI and React -&gt; Framework7 React Blank</pre><p>After this, you should see a new folder <em>“Chat-App”</em> created. Open it in your preferred code editor and we can start coding.</p><h4>User Authentication</h4><p>At first, we need to set up Firebase. The process is pretty straightforward, but for detailed explanation, see <em>“Configuring Firebase” </em>section in <a href="https://medium.com/@pablomatgar/ed675ee74c0a">this article</a>. <br>After the initialisation, run npm install firebase<strong> </strong>command and your project should be connected to the Firebase console. <br>Now go to <em>Authentication –&gt; Sign-in method –&gt; Add new provider</em> and enable <em>Anonymous</em> option.</p><figure><img alt="Steps to enable authentication in Firebase." src="https://cdn-images-1.medium.com/max/1024/1*eX_Ps-4QPOjoHCZbHwUWiQ.png" /><figcaption>Enabling authentication in Firebase.</figcaption></figure><p>Let’s add two functions for login and logout to <em>“db.js”</em> file. The login function is called on button click event in Loading Page. After successful login, user is redirected to Groups Page (see image of wireframe above). Open the DevTools of your preferred browser, go to <em>Application</em> menu and find <em>firebaseLocalStorage</em>. You can see the information of anonymous user (most importantly <em>uid</em>) provided by Firebase. This value will be used to identify the logged in user.<br>For now, ignore the code on line 14 with store, we will come to that later. On line 16, the Framework7 changes the page to Login page and clears history, therefore the user cannot move back once he/she is logged out.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/549fc8e5dda83d9fba1dc5ef9f38dd84/href">https://medium.com/media/549fc8e5dda83d9fba1dc5ef9f38dd84/href</a></iframe><figure><img alt="Browser screenshot showing information about logged in user." src="https://cdn-images-1.medium.com/max/826/1*EZ8R_y-qxajgZX4kYxyRYQ.png" /><figcaption>Information about logged in user.</figcaption></figure><h4>Redux Toolkit - Store Global State</h4><p>Here is a simplified version of store creation, based on <a href="https://redux-toolkit.js.org/tutorials/quick-start">this</a> tutorial. Codes of the files are provided below.</p><ol><li>Run command npm install @reduxjs/toolkit react-redux and create a directory <em>“/store”</em> which will contain all the store logic. Inside that directory, create <em>“/store/slices”</em> directory.</li><li>We will use two <em>slices</em> in this app, therefore create <em>“groupsSlice.js”</em> and <em>“userSlice.js”</em>. These slices hold reducer logic and actions for a single feature of app (in this case information about chat groups and the user).</li><li>In <em>“/store”</em>, create <em>“store.js”</em> which will include reducer object with all of our slices.</li><li>Wrap your application by React Redux <em>&lt;Provider&gt; </em>in <em>“app.jsx”</em> to make the store available in the components.</li><li>Use the state with <em>useDispatch() </em>and <em>useSelector()</em> in functional React components, and <em>store.dispatch()</em> and <em>store.getState()</em> in vanilla Javascript files.</li></ol><p>Slices always include name for identification, initial state and reducers (which are exported by object destructuring).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84950bd198de890b5d9e671a1b90c59c/href">https://medium.com/media/84950bd198de890b5d9e671a1b90c59c/href</a></iframe><p>In the state of groups (line 3) we have an array of all chat groups saved in the database, but also selected group which user clicked to join, as well as notification if new message was sent/received and the UI should show it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e990c86d8a376edf115bdff21e656e40/href">https://medium.com/media/e990c86d8a376edf115bdff21e656e40/href</a></iframe><p>Adding the slices to the store and wrapping the app with provider:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/533d5312794dc8099138b6639d48bf5c/href">https://medium.com/media/533d5312794dc8099138b6639d48bf5c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d19fe7a58a546191a332dfef7e22570f/href">https://medium.com/media/d19fe7a58a546191a332dfef7e22570f/href</a></iframe><p>For debugging the state of the app, install an extension to your browser called <a href="https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd?hl=en"><em>Redux DevTools</em></a>, where you can see in realtime how the state is being changed. After installing, click on the circle icon and the interface will open.</p><figure><img alt="React DevTools user interface." src="https://cdn-images-1.medium.com/max/673/1*8DS0D8AIaWbM6WM4xf7Bjg.png" /><figcaption>Redux DevTools user interface.</figcaption></figure><h4>Firestore Database</h4><p>To store chat groups, users and messages, we will use Firestore Database. Navigate into this database in Firestore and create three collections: <em>groups, messages </em>and <em>users</em>. In each one, create a mock document (let Firestore assign a Document ID automatically). The structure is as follows:</p><pre>Groups: {category: string, description: string, image: string, name:    string}.</pre><pre>Messages: {avatar: string, group: string, name: string, text: string, time: number, userID: string}.</pre><pre>Users: {gender: string, image: string, name: string}.</pre><p>The final result should look similar to this:</p><figure><img alt="Screenshot of Firestore Database filled with data." src="https://cdn-images-1.medium.com/max/1024/1*C_3vt-z2ZlfxXsJlq3ds-A.png" /><figcaption>Information in Firestore Database.</figcaption></figure><p>In the image above you can see a link to a Firebase storage. To store images (in our case a thumbnails of the chat groups), go to <em>Storage</em>, upload your image and copy the link to access it.</p><p><strong>Combining Redux Toolkit with Database</strong></p><p>After user fills the name and selects gender in the Login page, login function will run and the data will be sent to database. On line 2 below, random user API is used to get an image for user, and on line 7 the login action is dispatched to update state in “<em>userSlice.js”</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7830a6f0e1e0c4bc8877b2ea4e3ea898/href">https://medium.com/media/7830a6f0e1e0c4bc8877b2ea4e3ea898/href</a></iframe><p>Firebase has an <em>onAuthStateChanged</em> function shown below, which listens to changes in authentication state. When the user is logged in, the condition on line 2 is true (this <em>user</em> is created by Firebase with <em>uid</em> we saw in DevTools). We obtain the chat groups from database and upload <em>uid </em>and these groups in Redux store (lines 4 and 5).</p><p>Next, we check if the user exists in database (line 14). If yes, we fill in remaining info into “<em>userSlice.js”</em>. If the user does not exist, we add new one to the database (line 25).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3f25c6e232f8f4aa041377c33b27c75/href">https://medium.com/media/e3f25c6e232f8f4aa041377c33b27c75/href</a></iframe><p>The <em>getChatGroupsFirebase</em> function retrieves chat groups from database and returns object with arrays of groups.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f2bf94c0f779102ba5350d8cdc142d3/href">https://medium.com/media/4f2bf94c0f779102ba5350d8cdc142d3/href</a></iframe><p>Those groups are then displayed in <em>“GroupsPage.jsx”</em>. After user clicks on one of those groups, the selected group’s name is sent to the store to be later displayed in <em>“MessagesPage.jsx”</em>.</p><h4>Sending and Receiving Messages</h4><p>After the user is redirected to <em>“MessagesPage.jsx”</em>, <em>useEffect</em> hook will start listening to new messages (line 2). If a new message appears in the database, the component will render the messages (line 6).<br>The styling and logic of messages is based on <a href="https://framework7.io/react/messages">Framework7 message template</a>. Since the <em>Message</em> component needs <em>type</em> as a property to decide on which side (left or right) will the message be rendered, we use <em>getTypeOfMessage</em> function (line 11) to compare if the <em>uid</em> of sender is the same as currently logged in user’s <em>uid</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d84498db75bbbf600a6712cd016341df/href">https://medium.com/media/d84498db75bbbf600a6712cd016341df/href</a></iframe><p>As the last step, we need to implement functions that will send and receive messages from the database.<br>After getting the messages, we filter them to contain only messages from our chosen group and sort them by the time of creation (lines 7 and 8). Sending is similar as uploading user to database, with the difference of creating a timestamp (line 17). Subscribing to changed in database is done by <em>onSnapshot</em> function provided by Firebase. If a change is made, we dispatch an action so the Message component listening to changes can re-render.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f76ce03bfb2025583d64a45e7992422a/href">https://medium.com/media/f76ce03bfb2025583d64a45e7992422a/href</a></iframe><p><strong>Congratulations! </strong>If you followed all the steps above, you should now have a functioning chat app where users can send and receive messages!</p><h4>PWA, Windows Build and Firebase Deployment</h4><p>As a bonus tasks, you can:</p><ul><li>Use <a href="https://en.docs.monaca.io/products_guide/monaca_ide/build/build_winrt">Windows build</a> to have standalone desktop app.</li><li><a href="https://en.docs.monaca.io/products_guide/monaca_ide/build/build_pwa">Build a PWA</a> - this includes creating service-worker.js (registered in index.html), manifest.json and icons in multiple sizes.</li><li><a href="https://en.docs.monaca.io/products_guide/monaca_ide/monaca_ci/firebase">Deploy to Firebase</a> - after this you can publicly access the app.</li></ul><h4>Conclusion</h4><p>In this tutorial we learnt how to create anonymous authentication in Firebase, save images and data to database, and send and receive messages. Some ideas for future improvement might include authentication via email or social media, or creating private chats between two users.<br>If you want to deploy and test it on your own mobile device, check <a href="https://medium.com/the-web-tub/creating-a-stock-management-application-with-monaca-592d7895c4e4">this</a> tutorial to guide you through the Monaca deployment process.</p><p>In case of any questions or suggestions for improvements, do not hesitate to contact me.</p><p>Good luck and have fun coding! :)</p><h4>Resources</h4><p><a href="https://reactjs.org/">https://reactjs.org/</a><br><a href="https://redux-toolkit.js.org/">https://redux-toolkit.js.org/</a><a href="https://monaca.io/"><br>https://monaca.io/<br></a><a href="https://docs.monaca.io/en/">https://docs.monaca.io/en/</a><br><a href="https://framework7.io/">https://framework7.io/</a><br><a href="https://firebase.google.com/docs/database">https://firebase.google.com/docs/database</a><br><a href="https://firebase.google.com/docs/storage">https://firebase.google.com/docs/storage</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3348be325da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-web-tub/how-to-create-a-hybrid-chat-app-with-react-js-d3348be325da">How to Create a Hybrid Chat App With React.js</a> was originally published in <a href="https://medium.com/the-web-tub">The Web Tub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Piano Chords Prediction With AI (Teachable Machine)]]></title>
            <link>https://medium.com/the-web-tub/piano-chords-prediction-with-ai-teachable-machine-22d0865c2100?source=rss-4ecfc08e8bb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/22d0865c2100</guid>
            <category><![CDATA[teachable-machine]]></category>
            <category><![CDATA[ml5js]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[audio-recognition]]></category>
            <category><![CDATA[monaca]]></category>
            <dc:creator><![CDATA[Dominik Sasko]]></dc:creator>
            <pubDate>Wed, 18 May 2022 06:42:10 GMT</pubDate>
            <atom:updated>2022-05-18T14:57:56.076Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oHxm79WfGNGrsmKADOctpQ.jpeg" /></figure><p>Recognising piano chords with AI in only two lines of code sounds impossible? Check this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f1a7f0755c99c8a904e2a1800b91f5a/href">https://medium.com/media/3f1a7f0755c99c8a904e2a1800b91f5a/href</a></iframe><p>Done…easy right?</p><p>If you would like to learn how to incorporate this code into your project, stick around! We will create a hybrid app that your friends and family can use to learn piano chords! <br>Link for the whole repository can be found <a href="https://github.com/monaca-samples/piano-chords-ai-recognition">here</a>.</p><h4><strong>Terminology</strong></h4><p>Let’s look at the technologies applied in this project.</p><p><a href="https://teachablemachine.withgoogle.com/"><strong>Teachable Machine (TM)</strong></a><strong><br></strong>A web-based tool which simplifies the process of training the machine learning model with easy-to-use GUI. As of writing this article, TM provides three classifying models — for images, sounds and poses. We will use a sound classification model to recognise four different piano chords.</p><p><a href="https://ml5js.org/"><strong>ml5.js</strong></a><strong><br></strong>Open source high level interface built on top of Tensorflow.js for building ML applications. It aims to improve public understanding of machine learning by making ML approachable for a broad audience of artists, creative coders, and students.</p><p><a href="https://monaca.io/"><strong>Monaca</strong></a><strong><br></strong><em>“Cross-platform hybrid mobile app development platform and tools in the cloud.”</em> In this app, Monaca will serve as an easy solution for deployment on a mobile device. You also have the possibility of development in the cloud with Monaca Cloud IDE, so you do not have to download anything on your computer.</p><h4>Prerequisites:</h4><ul><li>Node v14.19.0 or higher,</li><li>free account on <a href="https://monaca.mobi/en/login">Monaca</a>,</li><li>piano (online version is enough).</li></ul><h4>Workflow:</h4><ol><li>Train the models with Teachable Machine — for better results, we will train two models (one for laptop and one for mobile).</li><li>Use ml5.js to load the model and start predictions.</li><li>Create a GUI to show feedback for user.</li><li>Deploy the application for phone.</li></ol><h4>App Wireframe</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6aTEaD9uaySJF82fZCY4Sg.png" /><figcaption>Piano chords recognition app wireframe.</figcaption></figure><h4>Training The Model</h4><p>As a first step, we need to train the model. Open Teachable Machine <a href="https://teachablemachine.withgoogle.com/train?action=fileOpen">website</a> and select <em>Audio Project.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OT3ywUv9YzlG3PCB9VavDQ.png" /><figcaption>Teachable Machine interface to select which model we want to use.</figcaption></figure><p>You will be presented with GUI that walks you through the process of training the model. There are two default classes: <em>Background noise</em> and <em>Class 2</em>. For the simplicity of this demo, we will use only four chords, namely C, D, E and F (feel free to add more), therefore we need four classes for chords + one class for background noise (this class is always present, so that the model knows when there is no sound happening — you can record silence in the room where your piano is located).<br>As for the number of samples, it is better to have more than the recommended minimum — around 40 samples can already make the predictions accurate. Since we want to make hybrid application, we need to train two independent models. This is due to different quality of microphone on phone and laptop, that might affect the accuracy of predictions.</p><blockquote>There is <strong>one problem</strong> which occurs if you want to upload audio recorded by phone microphone. The Teachable Machine does not work on mobile devices, nor you can upload your own audio (it must be directly recorded through TM website). To tackle this issue, download <a href="https://www.ez-mic.com/">EZ-mic</a> or similar software, which will allow you to use phone microphone as an external laptop microphone.</blockquote><p>After training the model, you should see similar view as below — when pressing individual chords, the output shows prediction in percentages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*qZO0MctKlPbBRswIpZ0zaA.gif" /><figcaption>Teachable Machine GUI live predicting the piano chords after training the model.</figcaption></figure><p>The training part is done, now we can do some coding.</p><h4>Setting up The Project</h4><p>To simplify the development, we can start from a template provided by Monaca CLI. After creating an account, open the console and write the following commands:</p><pre>$ npm install -g monaca         // install Monaca CLI<br>$ monaca login                  // login with your new account<br>$ monaca create AI-Piano-App    // create new project</pre><pre>Choose: Onsen UI and Vue.js -&gt; Framework7 Vue Blank</pre><p>After this, you should see a new folder <em>“AI-Piano-App”</em> created. Open it in your preferred code editor. <br>The UI will consist of two Vue components. Create <em>“LoadingPage.vue” </em>and <em>“PredictingPage.vue”</em> in <em>“./pages”</em> directory. The first mentioned page serves as an initial page displayed for the user while the model is being loaded. It consists only of HTML code, so you can copy it from the repository. <em>“PredictingPage.vue” </em>displays the chord to play. If the user does not know the chord, he/she can tap the card and flip it to see the chord’s picture. After successful play and recognition of it, the card turns green and a new chord is displayed. Here is the Vue code which uses Composition API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aeeec8dbf000309a76721b25ff804203/href">https://medium.com/media/aeeec8dbf000309a76721b25ff804203/href</a></iframe><p>The component starts with variable and function definitions, after that, it uses <em>onMounted</em> lifecycle hook to set up the component. On line 19 a function from a different module is called to start the prediction. Let’s implement it.<br>Create <em>”helperFunctions,js” </em>in <em>“./js”</em> directory. Define both trained models’ URLs as constants and add functions which are used to detect the type of the device:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09ace52be4fa3e8996390641dd17faaf/href">https://medium.com/media/09ace52be4fa3e8996390641dd17faaf/href</a></iframe><p>The next step is implementing the function to load model. This function is called in <em>“app.vue”</em> when the app starts. Install <a href="https://www.npmjs.com/package/cordova.plugins.diagnostic"><em>cordova.plugin.diagnostic</em></a><em> </em>with command<em> </em>npm i cordova.plugin.diagnostic, which is used to explicitly ask for microphone usage permission (line 7).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8de76e64e8a371804cd26b1eb310cccb/href">https://medium.com/media/8de76e64e8a371804cd26b1eb310cccb/href</a></iframe><p>Line 20 uses ml5.js with model URL as a first parameter and threshold of the successful prediction as a second one. It is best to play around with the threshold to see which value will give the best results.<br>The last function to code is <em>startPredition</em>. As you can see, it has a callback as a parameter. That way we can access the result in other parts of the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e8842e802a8e9b12e9bd56f739e758e/href">https://medium.com/media/9e8842e802a8e9b12e9bd56f739e758e/href</a></iframe><p>If you start the application now, it accesses the microphone and starts predicting the piano chords. The next task is to deploy it on a mobile device. Check the last part of <a href="https://medium.com/the-web-tub/creating-a-stock-management-application-with-monaca-592d7895c4e4">this tutorial</a>, which will guide you step by step on how to use build a hybrid app in a few steps. Be aware that the prediction accuracy will vary depending on your phone’s/laptop’s microphone capabilities, and that the current implementation of ml5.js soundClassifier might not be able to access the microphone of all devices.</p><p>In case of any questions or suggestions for improvements, do not hesitate to contact me.</p><p>Good luck and have fun coding! :)</p><p><strong>Resources</strong></p><p><a href="https://teachablemachine.withgoogle.com/">https://teachablemachine.withgoogle.com/</a><a href="https://ml5js.org/"><br>https://ml5js.org/</a><a href="https://ml5js.org/"><br></a><a href="https://vuejs.org/">https://vuejs.org/</a><br><a href="https://monaca.io/">https://monaca.io/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22d0865c2100" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-web-tub/piano-chords-prediction-with-ai-teachable-machine-22d0865c2100">Piano Chords Prediction With AI (Teachable Machine)</a> was originally published in <a href="https://medium.com/the-web-tub">The Web Tub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recognising Eye Blinking With Tensorflow.js]]></title>
            <link>https://medium.com/the-web-tub/recognising-eye-blinking-with-tensorflow-js-3c02b738850d?source=rss-4ecfc08e8bb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c02b738850d</guid>
            <category><![CDATA[monaca]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[blink-detection]]></category>
            <category><![CDATA[tensorflowjs]]></category>
            <category><![CDATA[pinia]]></category>
            <dc:creator><![CDATA[Dominik Sasko]]></dc:creator>
            <pubDate>Fri, 01 Apr 2022 04:54:50 GMT</pubDate>
            <atom:updated>2022-05-18T14:02:11.897Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Blink-To-Text application" src="https://cdn-images-1.medium.com/max/1024/1*nDVShrNwBUsGe_Hi2gwV_Q.png" /><figcaption>Blink-To-Text application.</figcaption></figure><p>For many years, developing Machine Learning (ML) projects have been mostly limited to Python users. Fortunately for web developers, this changes with the rise of libraries like Tensorflow.js, which allow us to train and develop ML models directly in the browser or Node.js environment.</p><p>Today, we will explore the world of “hybrid machine learning development” by converting eye blinks into text, with the usage of <a href="https://github.com/tensorflow/tfjs-models/tree/master/face-landmarks-detection"><em>Face Landmark Detection</em> model</a>. The app will be using Vue.js and Framework7 to build the frontend, but feel free to use your preferred technologies. After finishing the tutorial, you will have a functioning app that can be run on the computer, as well as on iOS or Android devices (with the help of Monaca deployment).</p><blockquote>Just a disclaimer — previous experience in ML is beneficial, but not necessary to follow along.</blockquote><p>Link for the repository: <a href="https://github.com/monaca-samples/blink-to-text">Blink-To-Text</a>.</p><h4>Terminology</h4><p>Let’s look at the technologies applied in this project.</p><p><strong>Tensorflow.js<br></strong>Tensorflow.js is a library for machine learning in JavaScript. It provides many pre-trained models that are ready to use, but also gives the user an option to train and build their own model directly in JavaScript. The whole list of pre-trained models can be found <a href="https://github.com/tensorflow/tfjs-models">here</a>.<br>If you are a complete beginner and want to try a simpler approach, I suggest you to start with <a href="https://ml5js.org/">ml5.js</a>, which is built on top of Tensorflow.js and provides a user-friendly interface for building ML applications.</p><p><strong>Vue.js &amp; Pinia<br></strong>If you are a frontend developer, you must have heard the name Vue.js. In short, it is a JavaScript framework for building user interfaces, which divides parts of code into logical segments called components. The motivation to choose Vue.js over React or Angular was the lightweight of the framework and easy learning curve.<br>As for the state management throughout our app, <a href="https://pinia.vuejs.org/">Pinia</a> will do the work. It is similar to the Vuex library, but has a simpler API and does not require as much boilerplate code.</p><p><strong>Monaca<br></strong><em>“Cross-platform hybrid mobile app development platform and tools in the cloud.”</em> In this app, Monaca will serve as an easy solution for deployment on a mobile device. You also have the possibility of development in the cloud with Monaca Cloud IDE, so you do not have to download anything on your computer.</p><h4><strong>Prerequisites:</strong></h4><ul><li>Node v14.19.0 or higher,</li><li>free account on <a href="https://monaca.mobi/en/login">Monaca</a>.</li></ul><h4>Workflow:</h4><ol><li>Implement functions to capture the camera (on both computer and mobile).</li><li>Load Tensorflow.js model and use the video from camera as an input.</li><li>Capture the prediction and convert it into text with Morse Code table.</li></ol><h4>App Wireframe</h4><figure><img alt="Blink-To-Text app wireframe" src="https://cdn-images-1.medium.com/max/1024/1*pDUPJucEMuH0GUGrj7E0jQ.png" /><figcaption>Blink-To-Text app wireframe.</figcaption></figure><h4><strong>Setting up The Project</strong></h4><p>To simplify the development, we can start from a template provided by Monaca CLI. After creating an account, open the console and write the following commands:</p><pre>$ npm install -g monaca         // install Monaca CLI<br>$ monaca login                  // login with your new account<br>$ monaca create Blink-To-Text   // create new project</pre><pre>Choose: Onsen UI and Vue.js -&gt; Framework7 Vue3 Minimal</pre><p>After this, you should see a new folder <em>“Blink-To-Text”</em> created. Open it in your preferred code editor and we can start coding.</p><h4><strong>Capturing Video</strong></h4><p>Firstly, we need to install the dependencies:</p><pre>$ npm install com.virtuoworks.cordova-plugin-canvascamera<br>$ npm install cordova-plugin-file</pre><p>Go to <em>“./js” </em>and create a file named “<em>hybridFunctions.js”.</em> Start with three helper functions to detect type of device:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcff34b409c8b54856fc573ef32c1dbb/href">https://medium.com/media/bcff34b409c8b54856fc573ef32c1dbb/href</a></iframe><p>Next comes accessing the camera. Passed <em>options</em> object can contain settings for camera (e.g. width, height, etc.).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19a6928cb33f5252c2ed66c26833edd0/href">https://medium.com/media/19a6928cb33f5252c2ed66c26833edd0/href</a></iframe><p>The mobile camera needs one more step to be loaded. <em>CanvasCamera</em> plugin saves the data on the device, therefore we access it through the <em>readImageFile</em> function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f1a570f99c219cfeaad79f23131eb76f/href">https://medium.com/media/f1a570f99c219cfeaad79f23131eb76f/href</a></iframe><p>The purpose of callback passed as an argument is to obtain the video and display it on the frontend side of the app. For this, we need to export the functions and create a Vue.js component in <em>“./pages”</em> called <em>“PredictingPage.vue”</em>. There we assign the returned values to &lt;video&gt; and &lt;img&gt; HTML elements for computer and mobile camera respectively.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d822eab413620923827016e12ce4372/href">https://medium.com/media/2d822eab413620923827016e12ce4372/href</a></iframe><p>The other two components are <em>“LoadingPage.vue”</em> (shown during loading the model) and <em>“MoreCodePage.jsx”</em> (includes instructions for the app). They do not include logic, so the code should be very straightforward.</p><p>Now that the videos are being captured, we can move on to another part.</p><h4><strong>Predicting Blinks</strong></h4><p>Let’s install all dependencies for Tensorflow.js:</p><pre>$ npm install @tensorflow-models/face-landmarks-detection<br>$ npm install @tensorflow/tfjs-backend-webgl<br>$ npm install @tensorflow/tfjs-converter<br>$ npm install @tensorflow/tfjs-core</pre><p>The code for blink prediction was inspired by <a href="https://www.npmjs.com/package/blink-detection">this package</a>. The author describes in detail the process of capturing the blink <a href="https://www.ankurkedia.com/blog/toggle-dark-mode-blink">here</a>. Simply put:</p><ol><li>The Face Landmark Detection model captures points of the eye.</li><li><em>Eye Aspect Ratio (EAR)</em> is calculated — Euclidian distance between points on top and bottom of the eye.</li><li>We get a result of either closed or opened eye.</li></ol><p>Create a file <em>“./js/blinkPrediction.js”</em> that will encapsulate all the Tensorflow.js logic. Import the libraries and load the model:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d7a7e5edc6d0d1f852ab64e6ab57e91/href">https://medium.com/media/9d7a7e5edc6d0d1f852ab64e6ab57e91/href</a></iframe><p>The EAR_THRESHOLD value of 0.27 proved to be accurate in blinking prediction. The Euclidian distance was calculated by the function below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60437fa815fae91969a8cfd3dab8ae38/href">https://medium.com/media/60437fa815fae91969a8cfd3dab8ae38/href</a></iframe><p>This function is called on line 12 and 16 of the lower code snippet, after we obtain the predicted points.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9fce1121dbd0dad68af03783e48f55ab/href">https://medium.com/media/9fce1121dbd0dad68af03783e48f55ab/href</a></iframe><p>Here on line 4, we use the video as input to our model, and we determine if the eye is closed by EAR value.<br>Since Morse Code needs two different inputs, long blinks will be assigned as a dash (“ — “) and short one as a dot (“.”). From line 22 to 34 we calculate how many consecutive frames included closed eyes, and therefore we can estimate the length of blink.</p><p>To see the predictions, load the model and create the first prediction of an empty image in <em>“./components/app.vue”</em> while the Vue.js app is loading.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5520344921a9fc5c48e916aba6971247/href">https://medium.com/media/5520344921a9fc5c48e916aba6971247/href</a></iframe><p>After the camera is loaded, send the video to the <em>startPrediciton(video) </em>function in <em>“PredictingPage.vue”</em> and get a result. We need to await the result since the prediction takes some time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd625ab759d8066a03d46f3fd088afdc/href">https://medium.com/media/bd625ab759d8066a03d46f3fd088afdc/href</a></iframe><h4><strong>Connecting Parts of the App Together with Pinia</strong></h4><p>Pinia will be our state management library to allow all parts of the app to share the data. Install it with npm install pinia and define it in <em>“./js/app.js”</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67b92b8f49049bf31cf7b86ce2f9d154/href">https://medium.com/media/67b92b8f49049bf31cf7b86ce2f9d154/href</a></iframe><p>Create a folder <em>“./store”</em> and inside it a file <em>“blinkStore.js”</em>. The content of the file is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67ad82d786ba1d533ae672ec4d6fbd0e/href">https://medium.com/media/67ad82d786ba1d533ae672ec4d6fbd0e/href</a></iframe><p>We define the state of the app on line 5, and on line 11 we have actions. In <em>startCapturingBlinks()</em> you can see the 7-second timer, after which the captured sequence of blinks will be sent to the <em>“./js/morseCodeTable.js”</em> file containing Morse Code table, which returns a letter after conversion. <br>On line 16 we call the <em>stopCapturingBlinks()</em> if the number of captured blinks is four. This is due to the fact that none of the letters are encoded with more than four characters.</p><p>To access and show the items of the store, we must import the store and define a variable as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/213fabd45c6caf7eb2bc76c040acf151/href">https://medium.com/media/213fabd45c6caf7eb2bc76c040acf151/href</a></iframe><p>Now the individual components can talk to each other through the Pinia store. If you followed all steps, <strong>great job! </strong>You should be able to recognise eye blinking and convert it into text!</p><h4>Conclusion</h4><p>In this article, we have seen how to access the video from your computer or mobile camera and predict if the eyes did short or long blink. Conversion to text is only one of many possibilities of application of this prediction. You can use it to count blinks and detect if the person is tired, or control your app with winking of left or right eye…just use your imagination!<br>If you want to deploy and test it on your own mobile device, check <a href="https://medium.com/the-web-tub/creating-a-stock-management-application-with-monaca-592d7895c4e4">this</a> tutorial to guide you through the Monaca deployment process.</p><p>In case of any questions or suggestions for improvements, do not hesitate to contact me.</p><p>Good luck and have fun coding! :)</p><blockquote>The prediction accuracy will vary depending on your phone’s capabilities.</blockquote><p><strong>Resources</strong></p><p><a href="https://www.tensorflow.org/js/">https://www.tensorflow.org/js/</a><br><a href="https://vuejs.org/">https://vuejs.org/</a><br><a href="https://monaca.io/">https://monaca.io/</a><br><a href="https://pinia.vuejs.org/">https://pinia.vuejs.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c02b738850d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-web-tub/recognising-eye-blinking-with-tensorflow-js-3c02b738850d">Recognising Eye Blinking With Tensorflow.js</a> was originally published in <a href="https://medium.com/the-web-tub">The Web Tub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Online Payments with Monaca, React, Framework7 and Express backend]]></title>
            <link>https://medium.com/the-web-tub/online-payments-with-monaca-react-framework7-and-express-backend-2e0801f55053?source=rss-4ecfc08e8bb6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e0801f55053</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[stripe]]></category>
            <category><![CDATA[monaca]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[online-payments]]></category>
            <dc:creator><![CDATA[Dominik Sasko]]></dc:creator>
            <pubDate>Wed, 23 Feb 2022 03:28:03 GMT</pubDate>
            <atom:updated>2022-05-18T13:31:20.174Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P-i2CGMUdUFh-eCqHTZO0A.png" /></figure><p>Have you ever wondered how to allow users to pay for products directly in your app? In this article, you will learn how to use Stripe Checkout API in React, which can help you simplify the process of charging your customers. We will also implement the backend code, written in Express framework, and deploy it on Heroku to be publicly accessible.</p><blockquote>This article is a second part of two-part series, where we develop a Food ordering hybrid application with Monaca, React, Framework7 and Firebase database. See the first part <a href="https://medium.com/@pablomatgar/ed675ee74c0a">here</a>.</blockquote><p>Link for repositories: <a href="https://github.com/monaca-samples/food-ordering-app">Frontend</a>, <a href="https://github.com/monaca-samples/food-ordering-app-backend">Backend</a>.</p><h3>Terminology</h3><p>First of all, let’s go through definitions of technologies which will be used.</p><h4>Stripe Checkout</h4><p>Easy to implement online payment solution: <em>“Checkout creates a secure, Stripe-hosted payment page that lets you collect payments quickly. It works across devices and can help increase your conversion.”.</em><br>Stripe Checkout offers features such as localization (different countries might use different ways of payments, e.g. Alipay in China), tax support, customization, and many more.</p><p>In this tutorial, we will use it for one-time payments — stripe will validate the credit card and process the payment in a predefined UI. Afterwards, we will receive the money on our test account. Read more about it at: <a href="https://stripe.com/en-sk/payments/checkout">Stripe checkout website</a>.</p><h4>Heroku</h4><p><em>“Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.”</em>. It features many subscription types, where it is free to use for personal projects. <br>Multiple programming languages are supported, but for our project Node.js will be used with Express framework to create and deploy the backend side of the application. Read more at <a href="https://www.heroku.com/">Heroku website</a>.</p><h3>Prerequisites:</h3><ul><li>free account on Stripe,</li><li>free account on Heroku,</li><li>Node v14.19.0 or higher,</li><li>finished first part of tutorial (optional).</li></ul><h3>Workflow</h3><p>Let’s quickly see, how simple it is to implement online payments:</p><ol><li>Create the accounts and install all necessary dependencies.</li><li>Insert the StripeCheckout component into your React frontend.</li><li>Set up backend code to approve the payments and deploy it on Heroku (or run it locally).</li><li>Connect frontend with backend and start charging your clients.</li></ol><h3>Frontend Code</h3><p>We will start building upon the foundations of the first tutorial. You can develop locally or use <a href="https://monaca.io/">Monaca Cloud IDE</a> to have live preview of your app. <br>In the beginning, create a React component called <em>“PaymentPage.jsx”</em>. Styles are not the focus of this blog, but feel free to use the <em>“PaymentPage.css”</em> in the <em>“./css”</em> folder to style your interface.<br>Next, use command below to install Stripe Checkout to your project.</p><pre>$ npm install react-stripe-checkout</pre><p>Imports in the code are as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57a1fa31e8b8ac2706bc529068c10e0d/href">https://medium.com/media/57a1fa31e8b8ac2706bc529068c10e0d/href</a></iframe><p>Noteworthy imports are: <em>StripeCheckout </em>(allows user to click a button to start the payment process), <em>AppContext </em>(provides info about order and customer), and functions from the database.</p><p>Next we use three React Hooks — <em>useContext </em>(store state of app), <em>useState </em>(toggling of payment option buttons) and <em>useEffect </em>(retrieves unique order number from database), and below them we define the first necessary part of Stripe Checkout — public key.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b69558b91e9e89474ca29199808be11/href">https://medium.com/media/9b69558b91e9e89474ca29199808be11/href</a></iframe><p><em>Side note</em><strong>:</strong> If you are wondering where to find this key, after you successfully logged into Stripe, go to <em>Developers -&gt; API Keys -&gt; Standard Keys</em> where you find two keys: public (safe to share — its purpose is to encrypt data sent to server) and private (decrypts data — must be stored at backend). <br>In the right upper corner, <em>Test mode</em> indicates that we are using just a dummy account, therefore do not worry if you accidentally share also the secret key. But as better practice, you could store these keys in environment variables.</p><figure><img alt="Stripe dashboard — public and private keys." src="https://cdn-images-1.medium.com/max/1024/1*Xc4GuIU12lQawyB0ieqbew.png" /><figcaption>Public and secret keys in Stripe dashboard.</figcaption></figure><p>Now we create a function that will be fired after clicking on the StripeCheckout component. On line 5, we call the POST method on our backend with a body containing a token and an order. The token object includes information that customer fills into the payment form, such as email and credit card information, and order includes order number and total price.<br>After successful response from backend, user will be redirected to summary page (line 23) or get alert to try again (line 26).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9141297d1f016b98cbebe9e643414c8c/href">https://medium.com/media/9141297d1f016b98cbebe9e643414c8c/href</a></iframe><p>And as a last part of the frontend, insert the <em>&lt;StripeCheckout&gt;</em> component that will render as a button on your page. Only <em>stripeKey</em> and <em>token </em>props are required.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e65adae1ddceb3d2fd557517398a0da4/href">https://medium.com/media/e65adae1ddceb3d2fd557517398a0da4/href</a></iframe><p>Great job! That is all what was needed at the frontend part of the code. After clicking the Pay button, you should see a similar window.</p><figure><img alt="Stripe UI on mobile device." src="https://cdn-images-1.medium.com/max/466/1*cYBxO6qo4ukCHvwK_6V7yQ.png" /><figcaption>Pre-defined User Interface of Stripe.</figcaption></figure><p>Stripe provides <a href="https://stripe.com/docs/testing#international-cards">test cards</a> (as the one pre-filled in picture), which ensure successful payment. But so far without a working backend, our transaction will be declined. Now we can move to another section to implement it.</p><h3>Backend code</h3><p>As mentioned before, the backend code is done with Express framework, but you can use your preferred technology and programming language, as long as it is supported by Stripe and Heroku.</p><p>First let’s install all necessary dependencies:</p><pre>$ npm install -g heroku   // globally installs Heroku CLI<br>$ npm install express stripe cors uuid // installs four dependencies</pre><p><em>Cors </em>package allows us to contact our backend from URLs that we define, and the <em>uuid </em>package creates a unique ID to ensure that the customer is not charged twice.</p><p>The next step is to provide your secret stripe key on line below:</p><pre>const stripe = require(“stripe”)(“YOUR_SECRET_KEY_GOES_HERE”);</pre><p>We have two exposed routes. First one uses GET request to check if our backend is working:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8331e3100058ce63e3a977ec0e83241b/href">https://medium.com/media/8331e3100058ce63e3a977ec0e83241b/href</a></iframe><p>Second one is a POST request with route <em>“/checkout”</em>. It parses the body to obtain information about the customer and the order, then on line 10 it creates a customer and on line 18 creates the charge. The status of the response is sent to the frontend, with either success or error message.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cf3bb6a9ca4ab1837bfcf4072d114e6/href">https://medium.com/media/6cf3bb6a9ca4ab1837bfcf4072d114e6/href</a></iframe><p>During the creation of charge, we specify the amount, customer and description. These items are later visible in <em>Payment</em> page of Stripe:</p><figure><img alt="Payment details in Stripe dashboard." src="https://cdn-images-1.medium.com/max/1024/1*NeGZnf9sUcGnJ0N92nqZ-A.png" /><figcaption>Payment details in Stripe dashboard.</figcaption></figure><p>To create such payment, you must run the Express server and contact it from frontend. You can run it locally with npm run start, or deploy it on Heroku, which will be explained in the next section.</p><h4>Heroku Deployment</h4><p>In the beginning, log in to Heroku website and create a new app (app must have a unique name for public URL). You will be presented with multiple ways to deploy the code, from which we choose the <em>Deploy using Heroku Git</em>. Follow the steps on the screen:</p><pre>$ heroku login<br>$ cd my-project/<br>$ git init<br>$ heroku git:remote -a NAME_OF_YOUR_APP<br>$ git add .<br>$ git commit -am &quot;Initial commit&quot;<br>$ git push heroku master</pre><p>After writing these commands, you should have notifications in <em>Latest activity</em> section:</p><figure><img alt="Heroku interface indicating that we pushed and deployed our code." src="https://cdn-images-1.medium.com/max/1024/1*EnDyjrz1GiMcFrZ2PYrcNA.png" /><figcaption>Heroku interface indicating that we pushed and deployed our code.</figcaption></figure><p>Click the <em>Open app</em> button that opens a new tab, where you should see a message <em>“Restaurant management backend is working!”</em>. This means that you have deployed a working backend app.</p><p>Now change the URL on frontend to your own backend, and try the payment again. If you are redirected to the Summary page, <strong>congratulations</strong>! <strong>You successfully paid for the first product!</strong> Check the <em>Payment</em> page of Stripe website to see how much you earned.</p><h3>Conclusion</h3><p>Today, we have learnt how to implement payments in our frontend React hybrid app. You should now have fundamentals of how to publicly deploy your backend service and contact it from frontend.<br>If you followed every step and received money to your test account, next step would be to build your app with Monaca for iOS or Android (check <a href="https://medium.com/the-web-tub/creating-a-stock-management-application-with-monaca-592d7895c4e4">this</a> tutorial).</p><p>In case of any questions or suggestions for improvements, do not hesitate to contact me.</p><p>Good luck and have fun coding! :)</p><h4>Resources</h4><p><a href="https://monaca.io/">https://monaca.io/</a><br><a href="https://reactjs.org/">https://reactjs.org/</a><a href="https://monaca.io/"><br></a><a href="https://docs.monaca.io/en/">https://docs.monaca.io/en/</a><br><a href="https://cordova.apache.org/">https://cordova.apache.org/</a><br><a href="https://framework7.io/">https://framework7.io/</a><br><a href="https://stripe.com/">https://stripe.com/</a><br><a href="https://heroku.com/">https://heroku.com/</a><br><a href="https://expressjs.com/">https://expressjs.com/</a><br><a href="https://firebase.google.com/docs/database">https://firebase.google.com/docs/database</a><br><a href="https://firebase.google.com/docs/storage">https://firebase.google.com/docs/storage</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e0801f55053" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-web-tub/online-payments-with-monaca-react-framework7-and-express-backend-2e0801f55053">Online Payments with Monaca, React, Framework7 and Express backend</a> was originally published in <a href="https://medium.com/the-web-tub">The Web Tub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>