修复人员名称无法更新的问题

This commit is contained in:
zher52 2022-02-16 17:07:47 +08:00
parent 10b9c6c252
commit fb422155cc
6 changed files with 21 additions and 35 deletions

View File

@ -1,11 +1,14 @@
package com.tencent.trtc;
import android.util.Log;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONObject;
public class CordovaEventKit {
public static CordovaEventKit kit = null;
private static final String TAG = "CordovaEventKit";
private CordovaPlugin plugin;
@ -29,7 +32,9 @@ public class CordovaEventKit {
}
public void fireEvent(String event, String obj){
Log.d(TAG,"fireEvent --- event:"+event+",obj:"+obj);
if (plugin == null || event == null || obj == null) {
Log.w(TAG,"fireEvent --- plugin:"+plugin);
return;
}
event = event.replace('\'','_');
@ -38,6 +43,7 @@ public class CordovaEventKit {
plugin.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(TAG,"fireEvent --- code:"+js);
plugin.webView.loadUrl("javascript:" + js);
}
});

View File

@ -108,13 +108,12 @@ public class CustomVideoView extends RelativeLayout {
this.setVisibility(alwaysHide?INVISIBLE:VISIBLE);
});
}
Events.addListener("userinfo.update",(extra -> {
if(this.userInfo !=null && this.userInfo.getDisplayName() == null
&& this.userInfo.getDisplayName().length() == 0
&& extra.getString("userId").equals(this.userInfo.getPersonid())){
Events.addListener("userinfo.update",(extra) -> {
if(this.userInfo !=null && extra.getString("userId").equals(this.userInfo.getPersonid())){
this.userInfo.setDisplayName(extra.getString("displayName"));
this.titleView.setText(extra.getString("displayName",this.userInfo.getDisplayName()));
}
}));
});
return this;
}

View File

@ -1,6 +1,7 @@
package com.tencent.trtc.event;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.HashMap;
@ -8,24 +9,29 @@ import java.util.List;
import java.util.Map;
public class Events {
private static final String TAG = "Events";
private static final String PREFIX = "com.tencent.trtc.event";
private static final Map<String, List<Listener>> events = new HashMap();
public static void fireEvent(String event){
fireEvent(event,null);
}
public static void fireEvent(String event, Extra extra){
Log.d(TAG,"fireEvent --- event:"+event+",extra:"+ extra);
if(events.containsKey(PREFIX+event)){
for(Listener listener : events.get(PREFIX+event)){
Bundle bundle = extra == null ? Bundle.EMPTY: new Bundle();
if(extra != null){
extra.extra(bundle);
}
Log.d(TAG,"fireEvent --- event:"+event+",bundle:"+ bundle);
listener.on(extra == null ? Bundle.EMPTY : bundle);
}
}
}
public static void addListener(String eventName,Listener listener){
Log.d(TAG,"addListener --- event:"+eventName+",listener:"+listener.hashCode());
if(!events.containsKey(PREFIX+eventName)){
events.put(PREFIX+eventName,new ArrayList<>());
}
@ -36,6 +42,7 @@ public class Events {
}
public static void removeListener(String eventName,Listener listener){
Log.d(TAG,"removeListener --- event:"+eventName+",listener:"+listener.hashCode());
if(!events.containsKey(PREFIX+eventName)){
events.put(PREFIX+eventName,new ArrayList<>());
}

View File

@ -1,28 +0,0 @@
package com.tencent.trtc.message;
import com.tencent.trtc.MessageObject;
import org.json.JSONObject;
public class LayoutChangeMessage implements MessageObject {
private String room;
private String personid;
public LayoutChangeMessage(String room, String personid) {
this.room = room;
this.personid = personid;
}
@Override
public String getEvent() {
return "LayoutChangeMessage";
}
@Override
public JSONObject getJson() {
JSONObject obj = new JSONObject();
return obj;
}
}

View File

@ -179,13 +179,13 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
}
Events.fireEvent("subview.always.hide",(extra)->extra.putBoolean("alwaysHide",false));
Events.addListener("userinfo.update",(extra -> {
Events.addListener("userinfo.update",(extra) -> {
String user = extra.getString("userId");
int index = this.mUserList.indexOf(user);
if(index > -1){
this.mUserList.get(index).setDisplayName(extra.getString("displayName"));
}
}));
});
}
private void enterRoom() {

View File

@ -19,6 +19,8 @@
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textAlignment="center"
android:singleLine="true"
android:visibility="gone"
android:autoSizeTextType="uniform"
/>
</RelativeLayout>