licode pre-v7.3開啓屏幕共享功能

由於工作需要,所以開始研究licode的共享屏幕功能,但在簡單修改代碼後,並沒有成功開啓屏幕共享功能。於是潛心Google+度娘,雖然最終結果只在firefox 69版本中開啓了屏幕共享功能(chrome 77版本沒能成功),但至少驗證licode的屏幕共享是OK的。Mac平臺上具體步驟如下:

編譯及安裝licode

  1. 下載licode pre-v7.3源碼並解碼
wget https://github.com/lynckia/licode/releases/tag/pre-v7.3
  1. 編譯licode
    licode官網
./scripts/installMacDeps.sh
./scripts/installErizo.sh
./scripts/installNuve.sh
./scripts/installBasicExample.sh

在執行./scripts/installNuve.sh的時候,過程中會報錯,大致的意思是找不到google-closure-compiler-js命令
原因:在licode/nuve/installNuve.sh腳本中有條語句出錯,把

npm install --loglevel error -g google-closure-compiler-js

改成

npm install --loglevel error -g google-closure-compiler-js@20180204
  1. 運行demo
./licode/scripts/initLicode.sh
./scripts/initBasicExample.sh
  1. 備註
    有時候需要重啓licode中相關node服務,之後basicExample無法正常運行,我的操作是重啓mongodb及rabbitMQ,重啓mongodb把緩存一併清除,同時執行./script/installNuve.sh(不執行它則無法獲取到superKey,因爲mongodb的數據已經清空了),再重啓所有的node服務

https自簽證書安裝及配置

自簽證書的目的主要是爲了建立https安全連接

  1. 創建openssl.cnf文件,文件內容如下:
[req]
prompt = no
default_bits = 4096
default_md = sha256
distinguished_name = dn
x509_extensions = v3_req

[dn]
C=CN
ST=HangZhou
L=HangZhou
O=TEST
OU=Testing Domain
CN=localhost
emailAddress=admin@localhost

[v3_req]
keyUsage=keyEncipherment, dataEncipherment
extendedKeyUsage=serverAuth
subjectAltName=@alt_names

[alt_names]
DNS.1=localhost
  1. 生成key
openssl genrsa -out ssl.key 4096
  1. 生成csr
openssl req -new -config openssl.cnf -key ssl.key -out ssl.csr
  1. 生成crt證書
openssl req -new -newkey rsa:2048 -sha1 -days 365 -nodes -x509 -keyout ssl.key -out ssl.crt -config openssl.cnf
  1. 信任自簽證書
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ./ssl.crt
  1. 驗證自簽證書
    https服務端server.js代碼爲:
const https = require('https');
const fs = require('fs');

const ssl_option = {
	key: fs.readFileSync('./ssl.key'),
	cert: fs.readFileSync('./ssl.crt')
};

const server = https.Server(ssl_option, (req, res) => {
	res.writeHead(200, {"Content-Type":"text/plain"})
	res.end("hello world\n");
});
server.listen(443, () => console.log("https listening on port: 443"));

運行server.js

sudo node server.js

打開chrome瀏覽器並輸入https://localhost地址,最終運行結果畫面如下:
在這裏插入圖片描述

licode的basicExample代碼修改

  1. 修改licode_config.js
......
config.erizoController.hostname = 'localhost'; //一定要改成localhost,否則socket.io連接會報證書錯話,因爲證書的域名是localhost,不可用ip來直接連接socket
......
config.erizoController.ssl = true;
config.erizoController.listen_ssl = true;
......
//使用全路徑
config.erizoController.ssl_key = '/Users/topsluo/workspace/Github/licode/cert/ssl.key';
config.erizoController.ssl_cert = '/Users/topsluo/workspace/Github/licode/cert/ssl.crt';
  1. 修改basicServer.js
打開basicServer.js
vim extras/basic_example/basicServer.js
修改與證書相關的代碼爲:
const options = {
   key: fs.readFileSync('../../cert/ssl.key').toString(),
   cert: fs.readFileSync('../../cert/ssl.crt').toString(),                                                                                                                   
 };
  1. 修改licode web client端代碼
打開web client端代碼:
vim extras/basic_example/public/script.js
把創建localStream代碼改成:
const config_screen = {screen: true, video: {mandatory: {maxWidth: 1280, maxHeight: 720}, attributes: {name: 'MyScreen'}}};
 config_screen.extensionId = 'okeephmleflklcdebijnponpabbmmgeo';//licode共享屏幕插件ID,爲靜態值
localStream = Erizo.Stream(config_screen);

在這裏插入圖片描述

運行結果

備註:運行chrome前,需要先安裝licode源碼目錄中自帶的插件,具體方法爲:

//打開manifest.json
vim erizo_controller.erizoClient/extras/chrome-extension/manifest.json
//修改matches字段,如果訪問域名爲localhost,則改爲
"matches":["*/localhost/*"]
//如果訪問的是IP,不是域名,則改爲
"matches":["*//192.168.10.203/*"]

OK,打開chrome瀏覽器,安裝剛纔修改過的屏幕共享插件,獲取插件ID(如圖):
在這裏插入圖片描述
用此ID替換extras/basic_example/public/script.js(前面有講過)文件中的config_screen.extensionId

OK,到最終驗證階段了

  1. Chrome運行結果(因爲之前的ssl域名爲localhost,所以此時顯示爲不安全連接)
    ![在這裏插入圖片描述](https://img-blog.csdnimg.cn/20191025191809571.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1RvcHNMdW8=,s
  2. firefox運行結果:
    注意,打開licode客戶端前,在火狐首頁輸入欄輸入about:config
    然後 【點擊我瞭解風險】輸入 security.enterprise_roots.enabled,把這個key改成true
    在這裏插入圖片描述
    在這裏插入圖片描述
    參考文檔
  3. https://www.cnblogs.com/cther/p/4634189.html
  4. https://moxo.io/blog/2017/08/01/problem-missing-subjectaltname-while-makeing-self-signed-cert/
  5. https://chotis2.dit.upm.es/room?id=5d936e52a0497e214118f724
  6. https://blog.csdn.net/qq_40155820/article/details/82383165
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章