trtc-electron-sdk
Advanced tools
Comparing version 0.0.3 to 6.6.25
214
demo.js
@@ -21,2 +21,3 @@ const TrtcEngine = require('./liteav/trtc'); | ||
console.info('onExitRoom: userenter reason:' + reason); | ||
self.destroyAllVideoView(); | ||
}); | ||
@@ -32,3 +33,3 @@ rtcEngine.on('onUserEnter', (uid) => { | ||
if (available) { | ||
let view = this.findView(uid, TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeBig); | ||
let view = this.findVideoView(uid, TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeBig); | ||
this.rtcEngine.startRemoteView(uid, view); | ||
@@ -38,2 +39,3 @@ } | ||
this.rtcEngine.stopRemoteView(uid); | ||
this.destroyVideoView(uid, TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeBig); | ||
} | ||
@@ -44,3 +46,3 @@ }); | ||
if (available) { | ||
let view = this.findView(uid, TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeSub); | ||
let view = this.findVideoView(uid, TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeSub); | ||
this.rtcEngine.startRemoteSubStreamView(uid, view); | ||
@@ -50,2 +52,3 @@ } | ||
this.rtcEngine.stopRemoteSubStreamView(uid); | ||
this.destroyVideoView(uid, TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeSub); | ||
} | ||
@@ -98,17 +101,177 @@ }); | ||
onmyTest() { | ||
debugger | ||
// this.rtcEngine.muteLocalVideo(this.mytestvalue);//测试 | ||
// this.rtcEngine.muteLocalAudio(this.mytestvalue);//测试 | ||
// this.rtcEngine.muteAllRemoteAudio(this.mytestvalue);//测试 | ||
// this.rtcEngine.switchRole(TrtcEngine.TRTCRoleType.TRTCRoleAudience); | ||
//网络参数 | ||
// let netparam = { | ||
// preference: TrtcEngine.TRTCVideoQosPreference.TRTCVideoQosPreferenceClear, | ||
// controlMode: TrtcEngine.TRTCQosControlMode.TRTCQosControlModeServer | ||
// }; | ||
// this.rtcEngine.setNetworkQosParam(netparam); | ||
//联麦 | ||
// if (this.mytestvalue) { | ||
// let para = '{"roomId":123,"userId":"456"}'; | ||
// this.rtcEngine.connectOtherRoom(para); | ||
// } | ||
// else { | ||
// this.rtcEngine.disconnectOtherRoom(); | ||
// } | ||
//填充模式 | ||
// if (this.mytestvalue) | ||
// this.rtcEngine.setLocalViewFillMode(TrtcEngine.TRTCVideoFillMode.TRTCVideoFillMode_Fit); | ||
// else | ||
// this.rtcEngine.setLocalViewFillMode(TrtcEngine.TRTCVideoFillMode.TRTCVideoFillMode_Fill); | ||
//旋转 TODO: | ||
// this.rtcEngine.setLocalViewRotation(TrtcEngine.TRTCVideoRotation.TRTCVideoRotation270); // | ||
//this.rtcEngine.setRemoteViewRotation('406804', TrtcEngine.TRTCVideoRotation.TRTCVideoRotation90); //带rotation | ||
// this.rtcEngine.setVideoEncoderRotation(TrtcEngine.TRTCVideoRotation.TRTCVideoRotation270); | ||
//镜像 mirro | ||
// this.rtcEngine.setLocalViewMirror(this.mytestvalue); | ||
// this.rtcEngine.setVideoEncoderMirror(this.mytestvalue); | ||
//小流 | ||
// this.rtcEngine.enableSmallVideoStream(this.mytestvalue, null); | ||
// this.rtcEngine.setRemoteVideoStreamType('trtc_electron_05', TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeSmall); | ||
// this.rtcEngine.setPriorRemoteVideoStreamType(TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeSmall); | ||
//音频 | ||
// this.rtcEngine.muteLocalAudio(this.mytestvalue);//测试 | ||
// this.rtcEngine.muteAllRemoteAudio(this.mytestvalue);//测试 | ||
// this.rtcEngine.enableAudioVolumeEvaluation(1000); | ||
//摄像头 | ||
// var cameralist = this.rtcEngine.getCameraDevicesList(); | ||
// for (i=0;i<cameralist.length;i++) { | ||
// var camera = cameralist[i]; | ||
// console.info("camera deviceName: " + camera.deviceName + " id:" + camera.id); | ||
// } | ||
// if (cameralist.length>1) | ||
// this.rtcEngine.setCurrentCameraDevice(cameralist[1].id); | ||
// var cur = this.rtcEngine.getCurrentCameraDevice(); | ||
// console.info("camera deviceName: " + cur.deviceName + " id:" + cur.id); | ||
//mic | ||
// var miclist = this.rtcEngine.getMicDevicesList(); | ||
// for (i=0;i<miclist.length;i++) { | ||
// var mic = miclist[i]; | ||
// console.info("mic deviceName: " + mic.deviceName + " id:" + mic.id); | ||
// } | ||
// if (miclist.length>1) | ||
// this.rtcEngine.setCurrentMicDevice(miclist[1].id); | ||
// var cur = this.rtcEngine.getCurrentMicDevice(); | ||
// console.info("cur mic deviceName: " + cur.deviceName + " id:" + cur.id); | ||
// this.rtcEngine.setCurrentMicDeviceVolume(58); | ||
// var volume = this.rtcEngine.getCurrentMicDeviceVolume(); | ||
//speaker | ||
// var speakerlist = this.rtcEngine.getSpeakerDevicesList(); | ||
// for (i=0;i<speakerlist.length;i++) { | ||
// var speaker = speakerlist[i]; | ||
// console.info("mic deviceName: " + speaker.deviceName + " id:" + speaker.id); | ||
// } | ||
// this.rtcEngine.setCurrentSpeakerDevice(speakerlist[0].id); | ||
// var cur = this.rtcEngine.getCurrentSpeakerDevice(); | ||
// console.info("cur mic deviceName: " + cur.deviceName + " id:" + cur.id); | ||
// this.rtcEngine.setCurrentSpeakerVolume(59); | ||
// var sval = this.rtcEngine.getCurrentSpeakerVolume(); | ||
// this.rtcEngine.setBeautyStyle(TrtcEngine.TRTCBeautyStyle.TRTCBeautyStyleNature, 8, 8, 8); | ||
//screen capture | ||
// if (this.mytestvalue) | ||
// this.rtcEngine.pauseScreenCapture(); | ||
// else | ||
// this.rtcEngine.resumeScreenCapture(); | ||
// this.rtcEngine.setSubStreamMixVolume(78); | ||
//发消息 | ||
//this.rtcEngine.sendCustomCmdMsg(4, 'test message', true, true); | ||
//this.rtcEngine.sendSEIMsg('test message', 1); | ||
//BGM | ||
// if (this.mytestvalue) { | ||
// this.rtcEngine.playBGM('./test.mp3'); | ||
// // this.rtcEngine.pauseBGM(); | ||
// // this.rtcEngine.resumeBGM(); | ||
// // var result = this.rtcEngine.getBGMDuration('./test.mp3'); | ||
// // this.rtcEngine.setBGMPosition(2000); | ||
// // this.rtcEngine.setMicVolumeOnMixing(120); | ||
// // this.rtcEngine.setBGMVolume(121); | ||
// } | ||
// else { | ||
// this.rtcEngine.stopBGM(); | ||
// } | ||
//设备测试项 test | ||
// if (this.mytestvalue) { | ||
// this.rtcEngine.startSpeedTest(this.sdkAppId, this.userId, this.findUserSig(this.userId)); | ||
// var v = this.findVideoView("camera_test_view", 0); | ||
// this.rtcEngine.startCameraDeviceTest(v); | ||
// this.rtcEngine.startMicDeviceTest(5000); | ||
// this.rtcEngine.startSpeakerDeviceTest('./test.mp3'); | ||
// } | ||
// else { | ||
// this.rtcEngine.stopSpeedTest(); | ||
// this.rtcEngine.stopCameraDeviceTest(); | ||
// this.rtcEngine.stopMicDeviceTest(); | ||
// this.rtcEngine.stopSpeakerDeviceTest(); | ||
// } | ||
//PUBLISH CDN | ||
// if (this.mytestvalue) { | ||
// var param = { | ||
// appId: this.sdkAppId, | ||
// bizId: 123456, | ||
// url: 'rtmp://xx.mytest.com/dd' | ||
// }; | ||
// this.rtcEngine.startPublishCDNStream(param); | ||
// } | ||
// else { | ||
// this.rtcEngine.stopPublishCDNStream(); | ||
// } | ||
//实验接口 | ||
// jsonStr = '{"seven": 123}'; | ||
// this.rtcEngine.callExperimentalAPI(jsonStr); | ||
//水印 | ||
function str2ab(str) { | ||
var buf = new ArrayBuffer(str.length); // 2 bytes for each char | ||
var bufView = new Uint8Array(buf); | ||
for (var i=0, strLen=str.length; i<strLen; i++) { | ||
bufView[i] = str.charCodeAt(i); | ||
} | ||
return buf; | ||
} | ||
if (this.mytestvalue) { | ||
let para = '{"roomId":123,"userId":"456"}'; | ||
this.rtcEngine.connectOtherRoom(para); | ||
var streamType = TrtcEngine.TRTCVideoStreamType.TRTCVideoStreamTypeBig; | ||
var srcData = str2ab("./water.png"); | ||
var srcType = 0; | ||
var nWidth = 240; | ||
var nHeight = 240; | ||
var xOffset = 0; | ||
var yOffset = 0; | ||
var fWidthRatio = 0.1; | ||
this.rtcEngine.setWaterMark(streamType, srcData, srcType, nWidth, nHeight, xOffset, yOffset, fWidthRatio);// | ||
} | ||
else { | ||
this.rtcEngine.disconnectOtherRoom(); | ||
} | ||
}, | ||
onStartScreenCapture() { | ||
@@ -122,2 +285,9 @@ //屏幕分享 | ||
let encparam = { | ||
videoResolution: TrtcEngine.TRTCVideoResolution.TRTCVideoResolution_320_240, | ||
videoFps: 12, | ||
videoBitrate: 200 | ||
}; | ||
this.rtcEngine.setSubStreamEncoderParam(encparam); | ||
var type = sourcelist[0].type; | ||
@@ -128,6 +298,6 @@ var sourceId = sourcelist[0].sourceId; | ||
var mouse = true, highlight = true; | ||
this.rtcEngine.selectScreenCaptureTarget(type, sourceId,sourceName, x,y,w,h, mouse, highlight); | ||
this.rtcEngine.startScreenCapture(); | ||
} | ||
@@ -152,5 +322,6 @@ else { | ||
//3. 进房参数 | ||
var roomid = parseInt(this.roomID); | ||
let param = { | ||
sdkAppId: this.sdkAppId, | ||
roomId: this.roomID, | ||
roomId: roomid, | ||
userSig: this.findUserSig(this.userId), | ||
@@ -170,3 +341,3 @@ userId: this.userId, | ||
if (bEnable) { | ||
let view = this.findView("local_video", 0); | ||
let view = this.findVideoView("local_video", 0); | ||
this.rtcEngine.startLocalPreview(view); | ||
@@ -198,3 +369,3 @@ } | ||
//------------------------- | ||
findView(uid, streamtype) { | ||
findVideoView(uid, streamtype) { | ||
let key = uid + String(streamtype); | ||
@@ -211,2 +382,17 @@ var userVideoEl = document.getElementById(key); | ||
destroyVideoView(uid, streamtype) { | ||
let key = uid + String(streamtype); | ||
var userVideoEl = document.getElementById(key); | ||
if (userVideoEl) { | ||
document.querySelector("#video_wrap").removeChild(userVideoEl); | ||
} | ||
}, | ||
destroyAllVideoView() { | ||
var n = document.querySelector("#video_wrap").childNodes.length; | ||
for (var i = 0; i < n; i++) { | ||
var dom = document.querySelector("#video_wrap"); | ||
dom.removeChild(dom.firstChild); | ||
} | ||
}, | ||
findUserSig() { | ||
@@ -213,0 +399,0 @@ var userSig = null; |
{ | ||
"name": "trtc-electron-sdk", | ||
"version": "0.0.3", | ||
"version": "6.6.25", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./liteav/trtc.js", |
122
README.md
# TRTC on Electron | ||
## Windows | ||
### Windows工程编译 | ||
### 工程编译 | ||
1. 安装win32 node环境 | ||
1. 安装win32 node环境 | ||
2. 安装visual Studio 2015 | ||
@@ -11,2 +12,3 @@ 3. 确认安装node-gyp,如果node没有自带node-gyp,需要[手动安装](https://github.com/nodejs/node-gyp) | ||
5. npm start | ||
注意: trtc electron sdk暂只支持win32版本,安装node 请选用win32版本 | ||
@@ -20,89 +22,59 @@ ## mac 环境搭建 | ||
## TRTC_Electron 使用方法 | ||
## 技术架构 | ||
![结构图](https://main.qcloudimg.com/raw/c2de0a2ef5369a66708af35cac184298.png "结构图") | ||
- 单进程 | ||
### 通过npm下载trtc库 | ||
npm install trtc-electron-sdk (确认联网状态) | ||
### 具体方法 | ||
```java | ||
//1、引入库 | ||
const TrtcEngine = require('trtc-electron-sdk'); | ||
## 发布 | ||
//2、构建Trtc | ||
this.rtcEngine = new TrtcEngine(); | ||
//3、注册回调 | ||
subscribeEvents = (rtcEngine) => { | ||
rtcEngine.on('onerror', (errcode, errmsg) => { | ||
console.info('trtc_demo: onerror :' + errcode + " msg" + errmsg); | ||
}); | ||
#### 发布npm包 | ||
- 修改版本号(package.json中version字段) | ||
- 修改包的main字段 (package.json中"main": "./liteav/trtc.js",原因当前库指向demo) | ||
- 增加下载命令 (package.json中script项中,增加 "install": "npm run download") | ||
- npm login (user: trtc_electron_sdk 76629254@qq.com password: 6Ba_8fm2NHF-PBU) | ||
- electron sdk发布: npm publish | ||
- 使用sdk: npm install-->从npm下载脚本-->从cos按OS和version号下载版本 | ||
- 网页端查看: https://www.npmjs.com/~trtc_electron_sdk | ||
![流程图](https://main.qcloudimg.com/raw/8b75eb9b2cff63fe45a83a1bd1aa4d90.png "流程图") | ||
rtcEngine.on('enterroom', (elapsed) => { | ||
console.info('trtc_demo: enterroom elapsed:' + elapsed); | ||
}); | ||
rtcEngine.on('exitroom', (reason) => { | ||
console.info('exitroom: userenter reason:' + reason); | ||
}); | ||
//..... | ||
//..... | ||
}; | ||
subscribeEvents(this.rtcEngine); | ||
//4、进入房间 | ||
enterroom () { | ||
//1. 开本地视频 | ||
this.enableVideoCapture(this.enableCamera); | ||
## 当前进度 | ||
#### 整理接口 | ||
- 接口已补全 | ||
- Render绘制上填充模式和旋转,需要多细测试; | ||
- 自定义音视频采集和渲染,放二期 | ||
- setVideoEncoderRotation() ,trtc native接口有问题,已改 | ||
- setCurrentSpeakerVolume() ,trtc native接口有问题,暂未改 | ||
- mac上摄像头出数据慢,且开始会黑屏的情况,需要再确认下. | ||
- 在win和mac平台,对接口需要更多的测试; | ||
//2. 编码参数 | ||
let encparam = { | ||
videoResolution: TrtcEngine.TRTCVideoResolution.TRTCVideoResolution_640_360, | ||
videoFps: 15, | ||
videoBitrate: 600 | ||
}; | ||
this.rtcEngine.setVideoEncoderParam(encparam); | ||
#### 性能: | ||
##### 测试场景: | ||
- 共6个用户在同一房间(一台PC、一台mac、4台手机),6个用户上行视频,其中PC用户同时上行辅路视频,4个手机端上行分辨率640x360; | ||
- trtc Electron运行于mac端,通过活动监视器采集CPU情况, mac端 CPU 2.6 GHz Intel Core i7, 6核, 16G内存; | ||
- mac端的trtc electron demo同时显示自已和另5位用户的视频,另包括一路辅路视频,显示分辨率480x320; | ||
##### 结论: | ||
- webGL的绘制CPU占用62%, 性能还不错。 内存350M. | ||
- 在使用YUV-canvas进行绘制,CPU占用87%, 比webGL性能差20%,也还在可接受范围,内存390M. | ||
//3. 进房参数 | ||
let param = { | ||
sdkAppId: this.sdkAppId, | ||
roomId: this.roomID, | ||
userSig: this.findUserSig(this.userId), | ||
userId: this.userId, | ||
privateMapKey: '', | ||
businessInfo: '' | ||
}; | ||
this.rtcEngine.enterRoom(param, 0); | ||
}, | ||
//5、退出房间 | ||
exitroom() { | ||
this.rtcEngine.exitRoom(); | ||
}, | ||
#### 文档和demo: | ||
- 已经整理接入文档和接口文档,参照native方式; | ||
- 计划将demo和文档暂放到gitee上,方便用户更新; | ||
- demo暂时只是开发用demo, 需要更加完善; | ||
//6、开启视频 | ||
enableVideoCapture(bEnable) { | ||
if (bEnable) { | ||
let view = this.findView("local", 0); | ||
this.rtcEngine.startLocalPreview(view); | ||
} | ||
else { | ||
this.rtcEngine.stopLocalPreview(); | ||
} | ||
}, | ||
#### 开发进度 | ||
- 今天晚上发码云 | ||
- 时间节点: 26号; | ||
//7、开启音频 | ||
enableAudioCapture(bEnable) { | ||
if (bEnable) { | ||
this.rtcEngine.startLocalAudio(); | ||
} | ||
else { | ||
this.rtcEngine.stopLocalAudio(); | ||
} | ||
}, | ||
``` | ||
#### 分工 | ||
- jasonxiao win | ||
- sevenzhu mac | ||
### 参考 | ||
demo: http://git.code.oa.com/TICSDK/TRTC_Electron_Demo.git | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
28341
11
528
2
78