@tencentcloud/trtc-component-wx 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +11 -0
- package/.eslintrc.js +101 -0
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/gulpfile.js +26 -0
- package/miniprogram_dist/index.js +183 -0
- package/miniprogram_dist/index.js.map +1 -0
- package/miniprogram_dist/trtc-player.js +245 -0
- package/miniprogram_dist/trtc-player.js.map +1 -0
- package/miniprogram_dist/trtc-player.json +4 -0
- package/miniprogram_dist/trtc-player.wxml +12 -0
- package/miniprogram_dist/trtc-player.wxss +16 -0
- package/miniprogram_dist/trtc-pusher.js +232 -0
- package/miniprogram_dist/trtc-pusher.js.map +1 -0
- package/miniprogram_dist/trtc-pusher.json +4 -0
- package/miniprogram_dist/trtc-pusher.wxml +19 -0
- package/miniprogram_dist/trtc-pusher.wxss +15 -0
- package/package.json +73 -0
- package/src/index.js +4 -0
- package/src/package.json +14 -0
- package/src/trtc-cloud-wx.js +46 -0
- package/src/trtc-player.js +72 -0
- package/src/trtc-player.json +4 -0
- package/src/trtc-player.wxml +12 -0
- package/src/trtc-player.wxss +16 -0
- package/src/trtc-pusher.js +64 -0
- package/src/trtc-pusher.json +4 -0
- package/src/trtc-pusher.wxml +19 -0
- package/src/trtc-pusher.wxss +15 -0
- package/tsconfig.json +25 -0
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tencentcloud/trtc-component-wx",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "miniprogram_dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "gulp dev --develop",
|
|
8
|
+
"watch": "gulp watch --develop --watch",
|
|
9
|
+
"build": "gulp",
|
|
10
|
+
"dist": "npm run build",
|
|
11
|
+
"clean-dev": "gulp clean --develop",
|
|
12
|
+
"clean": "gulp clean",
|
|
13
|
+
"test": "jest --bail",
|
|
14
|
+
"test-debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --bail",
|
|
15
|
+
"coverage": "jest ./test/* --coverage --bail",
|
|
16
|
+
"lint": "eslint \"src/**/*.js\" --fix",
|
|
17
|
+
"lint-tools": "eslint \"tools/**/*.js\" --rule \"import/no-extraneous-dependencies: false\" --fix"
|
|
18
|
+
},
|
|
19
|
+
"miniprogram": "miniprogram_dist",
|
|
20
|
+
"jest": {
|
|
21
|
+
"testEnvironment": "jsdom",
|
|
22
|
+
"testURL": "https://jest.test",
|
|
23
|
+
"collectCoverageFrom": [
|
|
24
|
+
"miniprogram_dist/**/*.js"
|
|
25
|
+
],
|
|
26
|
+
"moduleDirectories": [
|
|
27
|
+
"node_modules",
|
|
28
|
+
"miniprogram_dist"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": ""
|
|
34
|
+
},
|
|
35
|
+
"author": "",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^2.28.0",
|
|
39
|
+
"@typescript-eslint/parser": "^2.28.0",
|
|
40
|
+
"babel-core": "^6.26.3",
|
|
41
|
+
"babel-loader": "^7.1.5",
|
|
42
|
+
"babel-plugin-module-resolver": "^3.2.0",
|
|
43
|
+
"babel-preset-env": "^1.7.0",
|
|
44
|
+
"colors": "^1.3.1",
|
|
45
|
+
"eslint": "^5.14.1",
|
|
46
|
+
"eslint-config-airbnb-base": "13.1.0",
|
|
47
|
+
"eslint-loader": "^2.1.2",
|
|
48
|
+
"eslint-plugin-import": "^2.16.0",
|
|
49
|
+
"eslint-plugin-node": "^7.0.1",
|
|
50
|
+
"eslint-plugin-promise": "^3.8.0",
|
|
51
|
+
"gulp": "^4.0.0",
|
|
52
|
+
"gulp-clean": "^0.4.0",
|
|
53
|
+
"gulp-if": "^2.0.2",
|
|
54
|
+
"gulp-install": "^1.1.0",
|
|
55
|
+
"gulp-less": "^4.0.1",
|
|
56
|
+
"gulp-rename": "^1.4.0",
|
|
57
|
+
"gulp-sourcemaps": "^2.6.5",
|
|
58
|
+
"jest": "^23.5.0",
|
|
59
|
+
"miniprogram-api-typings": "^2.10.3-1",
|
|
60
|
+
"miniprogram-simulate": "^1.2.5",
|
|
61
|
+
"thread-loader": "^2.1.3",
|
|
62
|
+
"through2": "^2.0.3",
|
|
63
|
+
"ts-loader": "^7.0.0",
|
|
64
|
+
"typescript": "^3.8.3",
|
|
65
|
+
"vinyl": "^2.2.0",
|
|
66
|
+
"webpack": "^4.29.5",
|
|
67
|
+
"webpack-node-externals": "^1.7.2"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@tencentcloud/trtc-cloud-wx": "^0.0.2",
|
|
71
|
+
"trtc-wx-sdk": "^1.1.5"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/index.js
ADDED
package/src/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "trtc-cloud-wx",
|
|
3
|
+
"version": "1.0.4-beta.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./trtc-cloud-wx.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"mitt": "^3.0.0",
|
|
12
|
+
"trtc-wx-sdk": "^1.1.4"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var mitt = require('mitt');
|
|
4
|
+
var TRTC = require('trtc-wx-sdk');
|
|
5
|
+
|
|
6
|
+
var TrtcCloud = /** @class */function () {
|
|
7
|
+
function TrtcCloud() {
|
|
8
|
+
this.emitter = mitt();
|
|
9
|
+
this.init();
|
|
10
|
+
}
|
|
11
|
+
TrtcCloud.getTRTCShareInstance = function () {
|
|
12
|
+
console.log('@@TrtcCloud.instance1', TrtcCloud.instance);
|
|
13
|
+
if (!TrtcCloud.instance) {
|
|
14
|
+
TrtcCloud.instance = new TrtcCloud();
|
|
15
|
+
console.log('@@TrtcCloud.instance2', TrtcCloud.instance);
|
|
16
|
+
}
|
|
17
|
+
return TrtcCloud.instance;
|
|
18
|
+
};
|
|
19
|
+
TrtcCloud.prototype.init = function () {
|
|
20
|
+
this.TRTC = new TRTC(this);
|
|
21
|
+
this.EVENT = this.TRTC.EVENT;
|
|
22
|
+
};
|
|
23
|
+
TrtcCloud.prototype.on = function (eventName, handler) {
|
|
24
|
+
this.emitter.on(eventName, handler);
|
|
25
|
+
};
|
|
26
|
+
TrtcCloud.prototype.enterRoom = function (params, scene) {
|
|
27
|
+
var sdkAppId = params.sdkAppId,
|
|
28
|
+
userId = params.userId,
|
|
29
|
+
userSig = params.userSig,
|
|
30
|
+
roomId = params.roomId;
|
|
31
|
+
this.TRTC.createPusher({});
|
|
32
|
+
var pusher = this.TRTC.enterRoom({
|
|
33
|
+
sdkAppID: sdkAppId,
|
|
34
|
+
userID: userId,
|
|
35
|
+
userSig: userSig,
|
|
36
|
+
roomID: roomId,
|
|
37
|
+
enableMic: true,
|
|
38
|
+
enableCamera: true // 进房默认开启视频上行
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
this.emitter.emit('enterRoom', pusher);
|
|
42
|
+
};
|
|
43
|
+
return TrtcCloud;
|
|
44
|
+
}();
|
|
45
|
+
|
|
46
|
+
module.exports = TrtcCloud;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import TRTCCloud, {translateTRTCStreamId} from 'trtc-cloud-wx'
|
|
2
|
+
|
|
3
|
+
const trtcCloud = TRTCCloud.getTRTCShareInstance()
|
|
4
|
+
const trtc = trtcCloud.trtc
|
|
5
|
+
const InterfaceEventEmitter = trtcCloud.InterfaceEventEmitter
|
|
6
|
+
|
|
7
|
+
Component({
|
|
8
|
+
properties: {
|
|
9
|
+
streamId: String
|
|
10
|
+
},
|
|
11
|
+
data: {
|
|
12
|
+
player: {},
|
|
13
|
+
TRTCStreamId: ''
|
|
14
|
+
},
|
|
15
|
+
lifetimes: {
|
|
16
|
+
attached() {
|
|
17
|
+
this.data.TRTCStreamId = this.getTRTCStreamId(this.data.streamId)
|
|
18
|
+
this.bindTRTCCloudEvent()
|
|
19
|
+
},
|
|
20
|
+
detached() {
|
|
21
|
+
this.unbindTRTCCloudEvent()
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
methods: {
|
|
26
|
+
// todo room uniapp 特供,因为 uniapp 打包导致组件传惨变量名更替 trtc-player 组建内部无法识别
|
|
27
|
+
setTRTCStreamId(id) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
try {
|
|
30
|
+
this.data.streamId = id
|
|
31
|
+
this.data.TRTCStreamId = this.getTRTCStreamId(id)
|
|
32
|
+
this.setData({streamId: this.data.streamId}, () => {
|
|
33
|
+
resolve()
|
|
34
|
+
})
|
|
35
|
+
} catch (err) {
|
|
36
|
+
reject(err)
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
playerAttributesChange(event) {
|
|
41
|
+
const {view, playerAttributes, callback} = event
|
|
42
|
+
if (view === this.data.streamId) {
|
|
43
|
+
this.setData({player: playerAttributes}, callback)
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
getTRTCStreamId(streamId) {
|
|
47
|
+
const tempArray = streamId.split('_')
|
|
48
|
+
const userId = tempArray.slice(0, -1).join('_')
|
|
49
|
+
const streamType = Number(tempArray[tempArray.length - 1])
|
|
50
|
+
return translateTRTCStreamId(userId, streamType)
|
|
51
|
+
},
|
|
52
|
+
bindTRTCCloudEvent() {
|
|
53
|
+
InterfaceEventEmitter.on('playerAttributesChange', this.playerAttributesChange, this)
|
|
54
|
+
},
|
|
55
|
+
unbindTRTCCloudEvent() {
|
|
56
|
+
InterfaceEventEmitter.off('playerAttributesChange', this.playerAttributesChange)
|
|
57
|
+
},
|
|
58
|
+
// 请保持跟 wxml 中绑定的事件名称一致
|
|
59
|
+
_playerStateChange(event) {
|
|
60
|
+
trtc.playerEventHandler(event)
|
|
61
|
+
},
|
|
62
|
+
_playerFullscreenChange(event) {
|
|
63
|
+
trtc.playerFullscreenChange(event)
|
|
64
|
+
},
|
|
65
|
+
_playerNetStatus(event) {
|
|
66
|
+
trtc.playerNetStatus(event)
|
|
67
|
+
},
|
|
68
|
+
_playerAudioVolumeNotify(event) {
|
|
69
|
+
trtc.playerAudioVolumeNotify(event)
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<view class="trtc-player-container">
|
|
2
|
+
<live-player wx:if="{{player.streamID}}" class="trtc-player" id="{{player.streamID}}" data-userid="{{player.userID}}"
|
|
3
|
+
data-streamid="{{player.streamID}}" data-streamtype="{{player.streamType}}" src="{{player.src}}" mode="RTC"
|
|
4
|
+
autoplay="{{player.autoplay}}" mute-audio="{{player.muteAudio}}" mute-video="{{player.muteVideo}}"
|
|
5
|
+
orientation="{{player.orientation}}" object-fit="{{player.objectFit}}"
|
|
6
|
+
background-mute="{{player.enableBackgroundMute}}" min-cache="{{player.minCache}}" max-cache="{{player.maxCache}}"
|
|
7
|
+
sound-mode="{{player.soundMode}}" enable-recv-message="{{player.enableRecvMessage}}"
|
|
8
|
+
auto-pause-if-navigate="{{player.autoPauseIfNavigate}}" auto-pause-if-open-native="{{player.autoPauseIfOpenNative}}"
|
|
9
|
+
debug="{{player.debug}}" bindstatechange="_playerStateChange" bindfullscreenchange="_playerFullscreenChange"
|
|
10
|
+
bindnetstatus="_playerNetStatus" bindaudiovolumenotify="_playerAudioVolumeNotify" />
|
|
11
|
+
<view wx:if="{{player.stopVideo}}" class="trtc-dark-mask"></view>
|
|
12
|
+
</view>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.trtc-player-container {
|
|
2
|
+
height: 100%;
|
|
3
|
+
width: 100%;
|
|
4
|
+
position: relative;
|
|
5
|
+
}
|
|
6
|
+
.trtc-player {
|
|
7
|
+
height: 100%;
|
|
8
|
+
width: 100%;
|
|
9
|
+
}
|
|
10
|
+
.trtc-dark-mask {
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
background-color: black;
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 0;
|
|
16
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import TRTCCloud from 'trtc-cloud-wx'
|
|
2
|
+
|
|
3
|
+
const trtcCloud = TRTCCloud.getTRTCShareInstance()
|
|
4
|
+
const trtc = trtcCloud.trtc
|
|
5
|
+
const InterfaceEventEmitter = trtcCloud.InterfaceEventEmitter
|
|
6
|
+
|
|
7
|
+
Component({
|
|
8
|
+
properties: {
|
|
9
|
+
// trtcCloud: {
|
|
10
|
+
// type: Object,
|
|
11
|
+
// }
|
|
12
|
+
},
|
|
13
|
+
data: {
|
|
14
|
+
pusher: {},
|
|
15
|
+
},
|
|
16
|
+
lifetimes: {
|
|
17
|
+
attached() {
|
|
18
|
+
this.bindTRTCCloudEvent()
|
|
19
|
+
},
|
|
20
|
+
detached() {
|
|
21
|
+
this.unbindTRTCCloudEvent()
|
|
22
|
+
trtcCloud.exitRoom()
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
methods: {
|
|
28
|
+
pusherAttributesChange(event) {
|
|
29
|
+
const {pusher, callback} = event
|
|
30
|
+
this.setData({pusher}, callback)
|
|
31
|
+
},
|
|
32
|
+
bindTRTCCloudEvent() {
|
|
33
|
+
InterfaceEventEmitter.on('pusherAttributesChange', this.pusherAttributesChange, this)
|
|
34
|
+
},
|
|
35
|
+
unbindTRTCCloudEvent() {
|
|
36
|
+
InterfaceEventEmitter.off('playerAttributesChange', this.pusherAttributesChange)
|
|
37
|
+
},
|
|
38
|
+
// 请保持跟 wxml 中绑定的事件名称一致
|
|
39
|
+
_pusherStateChangeHandler(event) {
|
|
40
|
+
trtc.pusherEventHandler(event)
|
|
41
|
+
},
|
|
42
|
+
_pusherNetStatusHandler(event) {
|
|
43
|
+
trtc.pusherNetStatusHandler(event)
|
|
44
|
+
},
|
|
45
|
+
_pusherErrorHandler(event) {
|
|
46
|
+
trtc.pusherErrorHandler(event)
|
|
47
|
+
},
|
|
48
|
+
_pusherBGMStartHandler(event) {
|
|
49
|
+
trtc.pusherBGMStartHandler(event)
|
|
50
|
+
},
|
|
51
|
+
_pusherBGMProgressHandler(event) {
|
|
52
|
+
trtc.pusherBGMProgressHandler(event)
|
|
53
|
+
},
|
|
54
|
+
_pusherBGMCompleteHandler(event) {
|
|
55
|
+
trtc.pusherBGMCompleteHandler(event)
|
|
56
|
+
},
|
|
57
|
+
_pusherAudioVolumeNotify(event) {
|
|
58
|
+
if (!trtcCloud.isEnterRoom) {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
trtc.pusherAudioVolumeNotify(event)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<view class="trtc-pusher-container">
|
|
2
|
+
<live-pusher class="trtc-pusher" url="{{pusher.url}}" mode="{{pusher.mode}}" autopush="{{pusher.autopush}}"
|
|
3
|
+
enable-camera="{{pusher.enableCamera}}" enable-mic="{{pusher.enableMic}}" muted="{{!pusher.enableMic}}"
|
|
4
|
+
enable-agc="{{pusher.enableAgc}}" enable-ans="{{pusher.enableAns}}"
|
|
5
|
+
enable-ear-monitor="{{pusher.enableEarMonitor}}" auto-focus="{{pusher.enableAutoFocus}}"
|
|
6
|
+
zoom="{{pusher.enableZoom}}" min-bitrate="{{pusher.minBitrate}}" max-bitrate="{{pusher.maxBitrate}}"
|
|
7
|
+
video-width="{{pusher.videoWidth}}" video-height="{{pusher.videoHeight}}" beauty="{{pusher.beautyLevel}}"
|
|
8
|
+
whiteness="{{pusher.whitenessLevel}}" orientation="{{pusher.videoOrientation}}" aspect="{{pusher.videoAspect}}"
|
|
9
|
+
device-position="{{pusher.frontCamera}}" remote-mirror="{{pusher.enableRemoteMirror}}"
|
|
10
|
+
local-mirror="{{pusher.localMirror}}" background-mute="{{pusher.enableBackgroundMute}}"
|
|
11
|
+
audio-quality="{{pusher.audioQuality}}" audio-volume-type="{{pusher.audioVolumeType}}"
|
|
12
|
+
audio-reverb-type="{{pusher.audioReverbType}}" waiting-image="{{pusher.waitingImage}}"
|
|
13
|
+
beauty-style="{{pusher.beautyStyle}}" fps="{{pusher.fps}}" filter="{{pusher.filter}}"
|
|
14
|
+
bindstatechange="_pusherStateChangeHandler" bindnetstatus="_pusherNetStatusHandler"
|
|
15
|
+
binderror="_pusherErrorHandler" bindbgmstart="_pusherBGMStartHandler"
|
|
16
|
+
bindbgmprogress="_pusherBGMProgressHandler" bindbgmcomplete="_pusherBGMCompleteHandler"
|
|
17
|
+
bindaudiovolumenotify="_pusherAudioVolumeNotify" />
|
|
18
|
+
<camera wx:if="{{pusher.videoPreview}}" class="trtc-camera" device-position="{{pusher.frontCamera}}"></camera>
|
|
19
|
+
</view>
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "esnext",
|
|
4
|
+
"target": "es2015",
|
|
5
|
+
"lib": ["es2015", "es2017", "dom"],
|
|
6
|
+
"noImplicitAny": false,
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"baseUrl": ".",
|
|
10
|
+
"allowSyntheticDefaultImports": true,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"emitDecoratorMetadata":true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"resolveJsonModule": true
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"node_modules/miniprogram-api-typings/index.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"include": [
|
|
20
|
+
"src/**/*.ts"
|
|
21
|
+
],
|
|
22
|
+
"exclude": [
|
|
23
|
+
"node_modules"
|
|
24
|
+
]
|
|
25
|
+
}
|