Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用nodejs为WebRTC+freeSWITCH搭建https服务大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

Node.js使用 v6.11.0 x64 LTS 版本,下载地址:https://nodejs.org/dist/v6.11.0/node-v6.11.0-x64.msi

对应的 npm 版本 3.10.10 。

下载了 msi 安装包,一路 next 即可。

服务器我们用node-static

先用 npm init 创建一个package.json,然后添加依赖 node-static ,package.json 如下:

{
  "name": "freeswitch","version": "1.0.0","description": "test freeswitch for webrtc","main": "server.js","dependencies": {
    "node-static": "^0.7.9"
  },"devDependencies": {},"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","start": "node server.js"
  },"keywords": [
    "webrtc"
  ],"author": "foruok","license": "ISC"
}

执行:

npm install

然后创建 server.js 文件内容如下:

var fs = require("fs");
var static = require('node-static');

var file = new static.Server('./public');

const options = {
  key: fs.readFileSync('D:/projects/webconference/freeswitch/privatekey.pem'),cert: fs.readFileSync('D:/projects/webconference/freeswitch/certification.pem')
};

require('https').createServer(options,function (request,responsE) {
    request.addListener('end',function () {
        file.serve(request,responsE);
    }).resume();
}).listen(8080);

便在 public 目录下放个什么 html 文件,比如 test.html 。

用 npm start 启动服务,可以在 Chrome 浏览器内输入地址 https://192.168.40.96:8080/test.html测试一下。

如果能看到,说明服务正常。

相关阅读:

大佬总结

以上是大佬教程为你收集整理的使用nodejs为WebRTC+freeSWITCH搭建https服务全部内容,希望文章能够帮你解决使用nodejs为WebRTC+freeSWITCH搭建https服务所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。