Hello everyone, today we are going to learn how to build a simple one-to-one Video/Audio chat using NodeJS and Web sockets as Backend and HTML5 APIs and JavaScript as Frontend. Most modern browsers like Mozilla Firefox, Google Chrome, Opera support WebRTC (Web Real Time Communication). The mission is to enable rich, high-quality RTC apps for the browsers. Let’s start.
大家好,今天我们将学习如何使用NodeJS和Web套接字作为后端以及HTML5 API和JavaScript作为前端来建立简单的一对一视频/音频聊天。 Mozilla Firefox,Google Chrome,Opera等大多数现代浏览器都支持WebRTC(Web实时通信)。 任务是为浏览器启用丰富,高质量的RTC应用程序。 开始吧。
它是如何工作的? (How Does it work?)
Generally, a WebRTC application needs following things:
通常,WebRTC应用程序需要满足以下条件:
- Audio or Video streams 音频或视频流
- Network information 网络信息
- A communication medium to report errors (if any), start, halt or end sessions 一种报告错误(如果有),开始,停止或结束会话的通讯介质
- Player for the Audio/Video streams 音频/视频流播放器
Let’s start with creating a web server which serves the HTML and JavaScript.
让我们从创建一个提供HTML和JavaScript的Web服务器开始。
const express = require('express'),
http = require('http'),
app = express();// use express static to deliver resources HTML, CSS, JS, etc)
// from the public folderapp.use(express.static('public'));
http.createServer(options, app).listen(3355);
console.log("The HTTP server is up and running");
Here you can see we have set up a basic http server, now we need this server to handle socket sessions as well, thus we will use ws module to handle them. Let’s add some more code and combine both of them, the resu
使用Node.js和WebRTC构建视频聊天应用

本文介绍了如何使用NodeJS、WebRTC和Socket.IO创建一个简单的实时一对一视频/音频聊天应用。通过WebRTC,可以在现代浏览器中实现高质量的RTC功能。文章详细讲解了从设置Web服务器,处理套接字会话,到构建UI和JavaScript以处理视频流的过程。
最低0.47元/天 解锁文章
813

被折叠的 条评论
为什么被折叠?



