搭建WebRTC服务器,有一步就是:进到源码apprtc目录下,使用npm install命令将package.json里的依赖包都给装上,这些依赖包将被安装到当前目录下的node_modules目录下,需要安装的依赖包很多,都是从http://registry.npmjs.org下载的,遗憾并不顺利,有个closurecompiler死活装不上,报错如下:
root@cat:~/apprtc# npm install
> closurecompiler@1.6.1 install /root/apprtc/node_modules/closurecompiler
> npm run-script configure
sh: 1: npm: Permission denied
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.0.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.0.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/nunjucks/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! closurecompiler@1.6.1 install: `npm run-script configure`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the closurecompiler@1.6.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-02-07T05_57_38_544Z-debug.log
看到报的这一堆错误,百度后,有的说是权限问题,加上sudo就能解决,还有的说要换npm源https://registry.npm.taobao.org,结果都不奏效。最后找到这个closurecompiler项目的github网址:https://github.com/dcodeIO/ClosureCompiler.js,其git地址为:https://github.com/dcodeIO/ClosureCompiler.js.git,于是直接git clone到node_modules目录下,里面有了一个closurecompiler目录,以为大功告成了,后来发现这个closurecompiler的子目录compiler里面少了一个jar包:closure-compiler-v20200112.jar。没有它,apprtc.debug.js这个文件就编译不出来。实际上这个jar包可以从这里下载:https://dl.google.com/closure-compiler/compiler-latest.tar.gz。本人后来发现在windows下搭建node环境,使用npm install -g closurecompiler是可以成功安装closurecompiler到全局的node_modules下的,整个过程如下:
$ npm install -g closurecompiler
E:\1234\RTC\node-v8.17.0-win-x64\ccjs -> E:\1234\RTC\node-v8.17.0-win-x64\node_modules\closurecompiler\bin\ccjs
> closurecompiler@1.6.1 install E:\1234\RTC\node-v8.17.0-win-x64\node_modules\closurecompiler
> npm run-script configure
> closurecompiler@1.6.1 configure E:\1234\RTC\node-v8.17.0-win-x64\node_modules\closurecompiler
> node scripts/configure.js
Configuring ClosureCompiler.js 1.6.1 ...
Downloading https://dl.google.com/closure-compiler/compiler-latest.tar.gz ...
| 0 / 7 mb
| 1 / 7 mb
| 2 / 7 mb
| 3 / 7 mb
| 4 / 7 mb
| 5 / 7 mb
| 6 / 7 mb
| 7 / 7 mb
✔ Download complete: E:\1234\RTC\node-v8.17.0-win-x64\node_modules\closurecompiler\compiler\compiler.tar.gz (7 mb)
Unpacking E:\1234\RTC\node-v8.17.0-win-x64\node_modules\closurecompiler\compiler\compiler.tar.gz ...
| closure-compiler-v20200112.jar
| COPYING
| README.md
✔ Unpack complete.
Configuring JRE ...
✔ Global Java is available, perfect!
✔ ClosureCompiler.js has successfully been configured!
+ closurecompiler@1.6.1
added 25 packages from 6 contributors in 40.414s
上面的E:\1234\RTC\node-v8.17.0-win-x64\是我在windows下的node安装路径。然后我就把E:\1234\RTC\node-v8.17.0-win-x64\node_modules\closurecompiler这个目录打个压缩包,弄到apprtc目录下面的node_modules下解压后,grunt build,没有出现错误,这次终于成功了。编译过程如下:
Running "shell:buildAppEnginePackage" (shell) task
Running "shell:genJsEnums" (shell) task
src >>> src/web_app/js
Running "closurecompiler:debug" (closurecompiler) task
Compiling node_modules/webrtc-adapter/out/adapter.js,src/web_app/js/analytics.js,src/web_app/js/enums.js,src/web_app/js/appcontroller.js,src/web_app/js/call.js,src/web_app/js/constants.js,src/web_app/js/infobox.js,src/web_app/js/peerconnectionclient.js,src/web_app/js/remotewebsocket.js,src/web_app/js/roomselection.js,src/web_app/js/sdputils.js,src/web_app/js/signalingchannel.js,src/web_app/js/stats.js,src/web_app/js/storage.js,src/web_app/js/util.js,src/web_app/js/windowport.js -> out/app_engine/js/apprtc.debug.js
>> Complete: 276879
Running "grunt-chrome-build:apprtc" (grunt-chrome-build) task
Chrome packaged app build.
Deleting buildDir: out/chrome_app
Creating empty buildDir: out/chrome_app
Copying resources to buildDir: out/chrome_app
object
out/chrome_app/manifest.json
src/web_app/chrome_app/manifest.json-->out/chrome_app/manifest.json
object
out/chrome_app/js/apprtc.debug.js
out/app_engine/js/apprtc.debug.js-->out/chrome_app/js/apprtc.debug.js
object
out/chrome_app/js/loopback.js
out/app_engine/js/loopback.js-->out/chrome_app/js/loopback.js
object
out/chrome_app/third_party/pako/pako.min.js
out/app_engine/third_party/pako/pako.min.js-->out/chrome_app/third_party/pako/pako.min.js
object
out/chrome_app/css/main.css
out/app_engine/css/main.css-->out/chrome_app/css/main.css
object
out/chrome_app/images/apprtc-128.png
out/app_engine/images/apprtc-128.png-->out/chrome_app/images/apprtc-128.png
object
out/chrome_app/images/apprtc-16.png
out/app_engine/images/apprtc-16.png-->out/chrome_app/images/apprtc-16.png
object
out/chrome_app/images/apprtc-22.png
out/app_engine/images/apprtc-22.png-->out/chrome_app/images/apprtc-22.png
object
out/chrome_app/images/apprtc-32.png
out/app_engine/images/apprtc-32.png-->out/chrome_app/images/apprtc-32.png
object
out/chrome_app/images/apprtc-48.png
out/app_engine/images/apprtc-48.png-->out/chrome_app/images/apprtc-48.png
object
out/chrome_app/js/background.js
src/web_app/js/background.js-->out/chrome_app/js/background.js
object
out/chrome_app/js/appwindow.js
src/web_app/js/appwindow.js-->out/chrome_app/js/appwindow.js
Running "grunt-chrome-build-transform" task
Transforming files using jinja.
Running "jinja:chrome-build" (jinja) task
Using context web_app/html/index_template
File "out/chrome_app/appwindow.html" created.
Running "grunt-chrome-build-compress" task
Creating zip file:out/chrome_app/apprtc.zip
Running "compress:chrome-build" (compress) task
>> Compressed 18 files.
Running "grunt-chrome-build-package" task
Skipping creation of Chrome package.
Done.
我把这个closurecompiler打包后放在这里:https://sifangyun.cn/download/closurecompiler.tar.gz,以方便遇到同样坑坑的小伙伴下载。