[Huawei Developers] Freemind R:
Introduction

HMS Video Kit allow us to play video by using a URL or multiple URLs that contain an address of a video. The latest version of this kit allow us to playback videos but in the later version it will support both editing and hosting of videos.

This service helps us to build a superb video experience for our app users.

Use Cases

1) The service can be used in a news app that contains small videos of the reported incident.

2) The service can be used as a video editing app.

3) The service can be used as a promotion video in your application.

4) The service can be used as an educational video related application.

In this article we will be working on one of the use case and that is education video related application. For that we need two major players in any software development and that is server and client.

Demo

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20201106064058.36195668078029418770611789863975:50511118054902:2800:4E1C51ECC412441DC648F197090D37E00CC10F50D0C0730CF881DB53B8951C4E.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/647/156/2640091000001647156.20201106064058.36195668078029418770611789863975:50511118054902:2800:4E1C51ECC412441DC648F197090D37E00CC10F50D0C0730CF881DB53B8951C4E.gif[/IMG]

Server Side (Node Server)

Prerequisite

1) We must have latest version of Node installed.

2) We must have latest version of Visual Studio Code installed.

3) Laptop/desktop and Huawei mobile device must share same Wi-Fi connection.

Tool’s required

1) Express js is a Node js web application server framework, designed for building single-page, multi-page, and hybrid web applications. It is the de facto standard server framework for node.js.

We don't have to repeat same code over and over again using Express js. Node.js is a low-level I/O mechanism which has an HTTP module. If you just use an HTTP module, a lot of work like parsing the payload, cookies, storing sessions, selecting the right route pattern based on regular expressions will have to be re-implemented. With Express.js, it is just there for us to use.

Express.js basically helps us manage everything, from routes, to handling requests and views.

2) Request module is by far the most popular (non-standard) Node package for making HTTP requests. Actually, it is really just a wrapper around Node's built in http module, so we can achieve all of the same functionality on your own with http, but request just makes it a whole lot easier.

const request = require('request');

request(' https://developer.huawei.com/consumer/en/', function(err, res, body) {
console.log(body);
});

The code above submits an HTTP GET request to developer.huawei.com and then prints the returned HTML to the screen. This type of request works for any HTTP endpoint, whether it returns HTML, JSON, an image, or just about anything else.The first argument to request can either be a URL string, or an object of options. Here are some of the more common options you'll encounter in our application:

a) url: The destination URL of the HTTP request

b) method: The HTTP method to be used (GET, POST, DELETE, etc.)

c) headers: An object of HTTP headers (key-value) to be set in the request

d) form: An object containing key-value form data

Creating Project

First we need to find a space in our machine and create a folder. We can name the folder whatever we want. Open Visual Studio Code, navigate to particular folder location which we created using cd command in the terminal of VS code. Run the below command to create package.json file.

npm init

Answer the questions presented, and you will end up with a package.json that looks like this:

{
"name": "android-node-server",
"version": "1.0.0",
"description": "It is a server for HMS Push Notification Kit",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Sanghati",
"license": "ISC"
}

We need to run the above command when we start a new project. Also whatever tools we install in this project, a dependency will be added in the package.json file and we use the below command to install our dependencies in node_modules folder.

npm install

We may need to run this every time we manually add a dependency to our package.json file.

Install Express

We run the below command to install Express js in our project.

npm install express –save

--save, will ensure to add express dependency to our package.json file.

Create app.js file

To create app.js file using VS code terminal we need touch. Touch command creates an empty file if it doesn’t exist. Run the below command to create app.js file.

npm install -g touch-cli
touch app.js

More details, you can visit https://forums.developer.huawei.com/forumPortal/en/topic/0204400319008240095