好的,我要提供这个事实我知道很少的android本机代码。我将从react-native下载到android本机代码中,尝试使用点对点视频会议sdk。
我试图使用的SDK是Skylink SDK,我试图将它包装在react-native ui模块中。
我已经接近提供视图,并且SDK正在成功触发,但我目前正在遇到SDK抱怨的错误:
ResourceType: No known package when getting name for resource number 0xffffffff
09-13 09:57:14.237 25504 25781 I org.webrtc.Logging: SurfaceViewRenderer: No surface to draw on
该应用程序崩溃了。
我的代码如下,但我怀疑我缺少一大块基本逻辑。
我也无法确认react-native是否将表面渲染器渲染到应用程序中。
Skylink SDK - https://cdn.temasys.com.sg/skylink/skylinksdk/android/latest/doc/reference/packages.html
Skylink示例Android应用程序 - https://github.com/Temasys/skylink-android-sample
package com.reactlibrary;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
//import com.facebook.Fresco;
import android.util.Log;
import android.util.Base64;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.VideoView;
import android.support.annotation.Nullable;
import android.app.Activity;
import sg.com.temasys.skylink.sdk.listener.LifeCycleListener;
import sg.com.temasys.skylink.sdk.listener.MediaListener;
import sg.com.temasys.skylink.sdk.listener.RemotePeerListener;
import sg.com.temasys.skylink.sdk.rtc.SkylinkConnection;
import sg.com.temasys.skylink.sdk.rtc.SkylinkException;
import sg.com.temasys.skylink.sdk.rtc.UserInfo;
import sg.com.temasys.skylink.sdk.rtc.SkylinkConfig;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;
import org.webrtc.SurfaceViewRenderer;
import java.util.Date;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
import java.io.UnsupportedEncodingException;
public class SkylinkViewManager extends SimpleViewManager<SurfaceViewRenderer> {
public static final String REACT_CLASS = "RNSkylinkView";
@Override
public String getName() {
return REACT_CLASS;
}
private static SkylinkConnection skylinkConnection;
private Activity mActivity = null;
private ThemedReactContext mContext = null;
private String roomName = null;
private String userName = null;
private String appKey = null;
private String secret = null;
private SurfaceViewRenderer appointmentView = null;
private SkylinkConfig getSkylinkConfig() {
SkylinkConfig config = new SkylinkConfig();
config.setAudioVideoSendConfig(SkylinkConfig.AudioVideoConfig.AUDIO_AND_VIDEO);
config.setTimeout(60);
return config;
}
public void initAppointment(ThemedReactContext context) {
Log.d("APPOINTMENT", "INITIALISED APPOINTMENT");
skylinkConnection = SkylinkConnection.getInstance();
skylinkConnection.init(
"API_KEY_HERE",
getSkylinkConfig(),
context
);
Log.d("APPOINTMENT", "INITIALISED APPOINTMENT");
}
public void startAppointment() {
Log.d("APPOINTMENT", "Attempting Appointment start");
if(roomName != null && userName != null && appKey != null && secret != null){
Log.d("APPOINTMENT", "STARTING APPOINTMENT " + roomName + " " + userName + " " + appKey + " " + secret);
boolean connection_success;
connection_success = skylinkConnection.connectToRoom(secret, roomName, userName);
Log.d("APPOINTMENT", "APPOINTMENT CONNECTED " + connection_success);
if (connection_success == true) {
changeToView();
}
} else {
Log.d("APPOINTMENT", "Variables arent ready, aborted appointment start");
}
}
// private boolean setListeners(ReactApplicationContext reactContext) {
// if (skylinkConnection != null) {
// skylinkConnection.setLifeCycleListener(reactContext.);
// skylinkConnection.setMediaListener(this);
// skylinkConnection.setOsListener(this);
// skylinkConnection.setRemotePeerListener(this);
// return true;
// } else {
// return false;
// }
// }
public void changeToView() {
Log.d("APPOINTMENT", "Attempting to Switch views");
appointmentView = skylinkConnection.getVideoView(null);
}
@ReactMethod
public void getConnectionInfo(Callback callback) {
// UserInfo user_data = skylinkConnection.getUserInfo(null);
String room_id = skylinkConnection.getRoomId();
callback.invoke(room_id);
}
@Override
public SurfaceViewRenderer createViewInstance(ThemedReactContext context) {
Log.d("APPOINTMENT", "Creating View Instance");
mContext = context;
appointmentView = new SurfaceViewRenderer(context);
appointmentView.setVisibility(View.VISIBLE);
appointmentView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
appointmentView.getLayoutParams().height = 100;
appointmentView.getLayoutParams().width = 100;
appointmentView.setBackgroundColor(0x00FF00); // Just making this appear
appointmentView.bringToFront();
initAppointment(context);
return appointmentView;
}
public void updateView () {
Log.d("APPOINTMENT", "Updating the view");
}
@ReactProp(name = "roomName")
public void setRoomName(SurfaceViewRenderer view, @Nullable String room_name) {
Log.d("APPOINTMENT", "Setting Room Name "+room_name);
roomName = room_name;
startAppointment();
}
@ReactProp(name = "userName")
public void setUserName(SurfaceViewRenderer view, @Nullable String user_name) {
Log.d("APPOINTMENT", "Setting User Name "+user_name);
userName = user_name;
startAppointment();
}
@ReactProp(name = "appKey")
public void setAppKey(SurfaceViewRenderer view, @Nullable String app_key) {
Log.d("APPOINTMENT", "Setting App Key "+app_key);
appKey = app_key;
startAppointment();
}
@ReactProp(name = "secret")
public void setSecret(SurfaceViewRenderer view, @Nullable String this_secret) {
Log.d("APPOINTMENT", "Setting secret "+this_secret);
secret = this_secret;
startAppointment();
}
}
提前感谢任何指示或帮助。