使用node js webrtc和socket io建立视频聊天

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值