完善说明文档
This commit is contained in:
parent
b9be9b2451
commit
86d4956705
60
README.md
60
README.md
@ -1,12 +1,62 @@
|
|||||||
# cordova-plugin-trtc
|
# cordova-plugin-trtc
|
||||||
|
|
||||||
腾讯实时音视频(TRTC)封装cordova插件 (示例)
|
腾讯实时音视频(TRTC)封装cordova插件
|
||||||
|
|
||||||
具体原生项目参考tencent的demo, 源码大部分从这里搬运:
|
## 使用方法
|
||||||
|
|
||||||
[https://github.com/zhaoyang21cn/Android_TRTC](https://github.com/zhaoyang21cn/Android_TRTC)
|
```bash
|
||||||
|
cordova plugin add git+http://m.shuto.cn:8680/public/cordova-plugin-trtc.git
|
||||||
|
```
|
||||||
|
|
||||||
|
## 内置方法
|
||||||
|
|
||||||
[https://github.com/zhaoyang21cn/iOS_TRTC](https://github.com/zhaoyang21cn/iOS_TRTC)
|
### 加入视频会议
|
||||||
|
|
||||||
iOS的sdk需要自己添加到src/ios/libs下, 可以从官网获取
|
```javascript
|
||||||
|
cordova.plugin.trtc.joinChannel(
|
||||||
|
{
|
||||||
|
ROOM_ID: 123123, // 房间号
|
||||||
|
USER_ID: '', // 用户id
|
||||||
|
SDK_APP_ID: '', // TRTC app id
|
||||||
|
USER_SIG: '' // 用户签名
|
||||||
|
},
|
||||||
|
res => { console.log(res); },
|
||||||
|
err => { console.log(err); },
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 用户信息变更
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
cordova.plugin.trtc.joinChannel(
|
||||||
|
{
|
||||||
|
room: 123123, // 房间号
|
||||||
|
userId: '', // 用户id
|
||||||
|
displayName: '', // 用户名
|
||||||
|
},
|
||||||
|
res => { console.log(res); },
|
||||||
|
err => { console.log(err); },
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 主播窗口变更事件
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
document.addEventListener(
|
||||||
|
cordova.plugin.trtc.Constant.EVENT_ON_LAYOUT_CHANGE,
|
||||||
|
(event: {room:string,userId:string}) => {
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 用户加入房间事件
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
ocument.addEventListener(
|
||||||
|
cordova.plugin.trtc.Constant.EVENT_ON_USER_VIDEO_AVAILABLE,
|
||||||
|
(event: {room:string,userId:string,available:boolean}) => {
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
```
|
||||||
|
@ -61,14 +61,6 @@ public class CustomVideoView extends RelativeLayout {
|
|||||||
}else {
|
}else {
|
||||||
setVisibility(alwaysHide?INVISIBLE:VISIBLE);
|
setVisibility(alwaysHide?INVISIBLE:VISIBLE);
|
||||||
}
|
}
|
||||||
// if(this.userInfo != null){
|
|
||||||
// if(this.userInfo.isLocal()){
|
|
||||||
// mTRTCCloud.stopLocalPreview();
|
|
||||||
// mTRTCCloud.stopLocalAudio();
|
|
||||||
//// }else{
|
|
||||||
//// mTRTCCloud.stopRemoteView(this.userInfo.getPersonid());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if(isChanged(userInfo)){
|
if(isChanged(userInfo)){
|
||||||
this.userInfo = userInfo;
|
this.userInfo = userInfo;
|
||||||
if(this.userInfo != null){
|
if(this.userInfo != null){
|
||||||
@ -119,7 +111,7 @@ public class CustomVideoView extends RelativeLayout {
|
|||||||
Events.addListener("userinfo.update",(extra -> {
|
Events.addListener("userinfo.update",(extra -> {
|
||||||
if(this.userInfo !=null && this.userInfo.getDisplayName() == null
|
if(this.userInfo !=null && this.userInfo.getDisplayName() == null
|
||||||
&& this.userInfo.getDisplayName().length() == 0
|
&& this.userInfo.getDisplayName().length() == 0
|
||||||
&& extra.getString("personid").equals(this.userInfo.getPersonid())){
|
&& extra.getString("userId").equals(this.userInfo.getPersonid())){
|
||||||
this.titleView.setText(extra.getString("displayName",this.userInfo.getDisplayName()));
|
this.titleView.setText(extra.getString("displayName",this.userInfo.getDisplayName()));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -50,7 +50,7 @@ public class TrtcPlugin extends CordovaPlugin {
|
|||||||
if(object != null){
|
if(object != null){
|
||||||
Events.fireEvent("userinfo.update",extra -> {
|
Events.fireEvent("userinfo.update",extra -> {
|
||||||
try {
|
try {
|
||||||
extra.putString("personid",object.getString("personid"));
|
extra.putString("userId",object.getString("userId"));
|
||||||
extra.putString("displayName",object.getString("displayName"));
|
extra.putString("displayName",object.getString("displayName"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -2,8 +2,6 @@ package com.tencent.trtc.event;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,7 +9,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class Events {
|
public class Events {
|
||||||
private static final String PREFIX = "com.tencent.trtc.event";
|
private static final String PREFIX = "com.tencent.trtc.event";
|
||||||
private static Map<String, List<Listener>> events = new HashMap();
|
private static final Map<String, List<Listener>> events = new HashMap();
|
||||||
public static void fireEvent(String event){
|
public static void fireEvent(String event){
|
||||||
fireEvent(event,null);
|
fireEvent(event,null);
|
||||||
}
|
}
|
||||||
|
@ -167,8 +167,8 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|||||||
try {
|
try {
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put("room",mRoomId);
|
object.put("room",mRoomId);
|
||||||
object.put("personid",viewUser.getPersonid());
|
object.put("userId",viewUser.getPersonid());
|
||||||
CordovaEventKit.kit.fireEvent("LayoutChangeMessage",object);
|
CordovaEventKit.kit.fireEvent("onLayoutChangeMessage",object);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|||||||
Events.fireEvent("subview.always.hide",(extra)->extra.putBoolean("alwaysHide",false));
|
Events.fireEvent("subview.always.hide",(extra)->extra.putBoolean("alwaysHide",false));
|
||||||
|
|
||||||
Events.addListener("userinfo.update",(extra -> {
|
Events.addListener("userinfo.update",(extra -> {
|
||||||
String user = extra.getString("personid");
|
String user = extra.getString("userId");
|
||||||
int index = this.mUserList.indexOf(user);
|
int index = this.mUserList.indexOf(user);
|
||||||
if(index > -1){
|
if(index > -1){
|
||||||
this.mUserList.get(index).setDisplayName(extra.getString("displayName"));
|
this.mUserList.get(index).setDisplayName(extra.getString("displayName"));
|
||||||
@ -204,8 +204,8 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
try {
|
try {
|
||||||
object.put("room",mRoomId);
|
object.put("room",mRoomId);
|
||||||
object.put("personid",mUserList.get(0).getPersonid());
|
object.put("userId",mUserId);
|
||||||
CordovaEventKit.kit.fireEvent("LayoutChangeMessage",object);
|
CordovaEventKit.kit.fireEvent("onLayoutChangeMessage",object);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -302,16 +302,6 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshRemoteVideoViews() {
|
|
||||||
for (int i = 0; i < mRemoteViewList.size(); i++) {
|
|
||||||
if (i < mUserList.size()) {
|
|
||||||
UserInfo user = mUserList.get(i);
|
|
||||||
mRemoteViewList.get(i).changeUser(mTRTCCloud,user);
|
|
||||||
} else {
|
|
||||||
mRemoteViewList.get(i).changeUser(mTRTCCloud,null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TRTCCloudImplListener extends TRTCCloudListener {
|
private class TRTCCloudImplListener extends TRTCCloudListener {
|
||||||
|
|
||||||
@ -342,6 +332,16 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|||||||
refreshRemoteVideoViews();
|
refreshRemoteVideoViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JSONObject object = new JSONObject();
|
||||||
|
try {
|
||||||
|
object.put("room",mRoomId);
|
||||||
|
object.put("userId",userId);
|
||||||
|
object.put("available",available);
|
||||||
|
CordovaEventKit.kit.fireEvent("onUserVideoAvailable",object);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshRemoteVideoViews() {
|
private void refreshRemoteVideoViews() {
|
||||||
|
10
www/trtc.js
10
www/trtc.js
@ -8,10 +8,16 @@ Trtc.prototype.joinChannel = function(arg, success, error) {
|
|||||||
|
|
||||||
Trtc.prototype.userInfoChange = function(userInfo,success, error) {
|
Trtc.prototype.userInfoChange = function(userInfo,success, error) {
|
||||||
exec(success, error, 'Trtc', 'userInfoChange', [userInfo]);
|
exec(success, error, 'Trtc', 'userInfoChange', [userInfo]);
|
||||||
}
|
};
|
||||||
|
|
||||||
Trtc.prototype.fireEvent = function(event,extra) {
|
Trtc.prototype.fireEvent = function(event,extra) {
|
||||||
cordova.fireDocumentEvent("trtc."+event, extra);
|
cordova.fireDocumentEvent("trtc."+event, extra);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
Trtc.prototype.Constant = {
|
||||||
|
EVENT_ON_LAYOUT_CHANGE :'trtc.onLayoutChangeMessage',
|
||||||
|
EVENT_ON_USER_VIDEO_AVAILABLE :'trtc.onUserVideoAvailable',
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = new Trtc();
|
module.exports = new Trtc();
|
||||||
|
Loading…
Reference in New Issue
Block a user