I have written an component using Vidyo sdk (Vidyo.io). Component was meant to be used in React-Native application and it was written 100% in java. The problem is that when I try to use this component in React it is not showing any video or camera preview. In 100% android application everything works correctly, as it is shown in demo application. To be sure I have checked several times if permission for camera is given - and it it. I have also checked if whole project have internet connection (and permission) - and it have
here is the code of xml file:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"><FrameLayout android:id="@+id/video_container" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.0" /><ImageView android:id="@+id/endCallButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/red_round_border" android:src="@drawable/ic_end_call" android:padding="5dp" android:layout_marginBottom="10dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="@+id/changeCameraStateButton" /><ProgressBar android:id="@+id/connectProgress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="visible" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent" /><TextView android:id="@+id/errorText" android:layout_width="0dp" android:layout_height="wrap_content" android:visibility="visible" android:textColor="@android:color/black" android:gravity="center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /><ImageView android:id="@+id/changeCameraStateButton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:background="@drawable/grey_round_border" android:src="@drawable/ic_deactivate_camera" android:padding="5dp" android:layout_marginBottom="10dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="@+id/endCallButton" /></android.support.constraint.ConstraintLayout>
and here is implementation on android side:
public class VidyoView extends ConstraintLayout implements VidyoConnector.IConnect, VidyoConnector.IRegisterLogEventListener, VidyoConnector.IRegisterNetworkInterfaceEventListener { private static final String TAG = "VidyoView"; enum VIDYO_CONNECTOR_STATE { VC_CONNECTED, VC_DISCONNECTED, VC_DISCONNECTED_UNEXPECTED, VC_CONNECTION_FAILURE } private FrameLayout imageContainer; private ImageView endCallButton; private ProgressBar progress; private TextView errorText; private boolean vidyoClientInitialized = false; private VIDYO_CONNECTOR_STATE vidyoConnectorState = VIDYO_CONNECTOR_STATE.VC_DISCONNECTED; private VidyoConnector vidyoConnector = null; private boolean vidyoConnectorConstructed = false; private WeakReference<ThemedReactContext> reactContext; private String host; private String token; private String userName; private String resourceId; public VidyoView(@NonNull Context context) { super(context); setUp(); } public VidyoView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); setUp(); } public VidyoView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { super(context, attrs, defStyleAttr); setUp(); } private void setUp() { Log.d(TAG, "SET UP"); inflate(getContext(), R.layout.component_vidyo_view, this); reactContext = new WeakReference<>((ThemedReactContext) getContext()); setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); imageContainer = (FrameLayout) findViewById(R.id.video_container); endCallButton = (ImageView) findViewById(R.id.endCallButton); progress = (ProgressBar) findViewById(R.id.connectProgress); errorText = (TextView) findViewById(R.id.errorText); if(reactContext.get() != null) { Connector.SetApplicationUIContext(reactContext.get().getCurrentActivity()); } vidyoClientInitialized = Connector.Initialize(); endCallButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { stopConnection(); } }); start(); } public void start() { ViewTreeObserver viewTreeObserver = imageContainer.getViewTreeObserver(); if (viewTreeObserver.isAlive()) { viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { imageContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this); // If the vidyo connector was not previously successfully constructed then construct it checkVidyoConnectionAndReconnect(); connect(); } }); } } @Override public void OnSuccess() { Log.d(TAG, "Success, connected"); onConnectorStateUpdeted(VIDYO_CONNECTOR_STATE.VC_CONNECTED, "Connected"); EventEmitter.emmitVidyoConnected(reactContext.get(), getId()); } @Override public void OnFailure(VidyoConnector.VidyoConnectorFailReason vidyoConnectorFailReason) { onConnectorStateUpdeted(VIDYO_CONNECTOR_STATE.VC_CONNECTION_FAILURE, "Connected"); EventEmitter.emmitVidyoConnectionFailure(reactContext.get(), getId(), vidyoConnectorFailReason.toString()); Log.d(TAG, "On failure = "+ vidyoConnectorFailReason.toString()); } @Override public void OnDisconnected(VidyoConnector.VidyoConnectorDisconnectReason vidyoConnectorDisconnectReason) { if (vidyoConnectorDisconnectReason == VidyoConnector.VidyoConnectorDisconnectReason.VIDYO_CONNECTORDISCONNECTREASON_Disconnected) { Log.d(TAG, "OnDisconnected: successfully disconnected, reason = "+ vidyoConnectorDisconnectReason.toString()); onConnectorStateUpdeted(VIDYO_CONNECTOR_STATE.VC_DISCONNECTED, "Disconnected"); } else { Log.d(TAG, "OnDisconnected: successfully disconnected, reason = "+ vidyoConnectorDisconnectReason.toString()); onConnectorStateUpdeted(VIDYO_CONNECTOR_STATE.VC_DISCONNECTED_UNEXPECTED, "Unexpected disconnection"); } } @Override public void OnLog(VidyoLogRecord vidyoLogRecord) { } @Override public void OnNetworkInterfaceAdded(VidyoNetworkInterface vidyoNetworkInterface) { } @Override public void OnNetworkInterfaceRemoved(VidyoNetworkInterface vidyoNetworkInterface) { } @Override public void OnNetworkInterfaceSelected(VidyoNetworkInterface vidyoNetworkInterface, VidyoNetworkInterface.VidyoNetworkInterfaceTransportType vidyoNetworkInterfaceTransportType) { } @Override public void OnNetworkInterfaceStateUpdated(VidyoNetworkInterface vidyoNetworkInterface, VidyoNetworkInterface.VidyoNetworkInterfaceState vidyoNetworkInterfaceState) { } private void onConnectorStateUpdeted(VIDYO_CONNECTOR_STATE state, final String statusText) { Log.d(TAG, "onConnectorStateUpdeted, state = "+ state.toString()); vidyoConnectorState = state; ThemedReactContext context = reactContext.get(); if (context != null && context.getCurrentActivity() != null) { context.getCurrentActivity().runOnUiThread(new Runnable() { @Override public void run() { if (vidyoConnectorState == VIDYO_CONNECTOR_STATE.VC_CONNECTED) { hideProgress(); } else if(vidyoConnectorState == VIDYO_CONNECTOR_STATE.VC_CONNECTION_FAILURE){ hideProgress(); errorText.setVisibility(VISIBLE); errorText.setText("Cannot load"); EventEmitter.emmitVidyoConnectionFailure(reactContext.get(), getId(), "cannot connect"); } } }); } } public void setHost(String host) { Log.d(TAG, "SET HOST"); this.host = host; } public void setToken(String token) { Log.d(TAG, "SET TOKEN"); this.token = token; } public void setResourceId(String resourceId) { Log.d(TAG, "SET RESOURCE ID"); this.resourceId = resourceId; } public void setUserName(String userName) { Log.d(TAG, "SET USER NAME"); this.userName = userName; } public void connect() { if (vidyoConnectorState != VIDYO_CONNECTOR_STATE.VC_CONNECTED && vidyoConnector != null) { progress.setVisibility(VISIBLE); if (!vidyoConnector.Connect( host, token, userName, resourceId, this)) { onConnectorStateUpdeted(VIDYO_CONNECTOR_STATE.VC_CONNECTION_FAILURE, "Connection failed"); Log.d(TAG, "Status: "+ false); } else Log.d(TAG, "Status: "+ true); } } private void checkVidyoConnectionAndReconnect() { if (!vidyoConnectorConstructed) { if (vidyoClientInitialized) { connectVidyo(); } else { Log.d(TAG, "ERROR: VidyoClientInitialize failed - not constructing VidyoConnector ..."); } Log.d(TAG, "onResume: vidyoConnectorConstructed => "+ (vidyoConnectorConstructed ? "success" : "failed")); } } private void connectVidyo() { vidyoConnector = new VidyoConnector(imageContainer, VidyoConnector.VidyoConnectorViewStyle.VIDYO_CONNECTORVIEWSTYLE_Default, 15,"info@VidyoClient info@VidyoConnector warning","", 0); vidyoConnectorConstructed = true; refreshView(); if (!vidyoConnector.RegisterNetworkInterfaceEventListener(VidyoView.this)) { Log.d(TAG, "VidyoConnector RegisterNetworkInterfaceEventListener failed"); } if (!vidyoConnector.RegisterLogEventListener(VidyoView.this, "info@VidyoClient info@VidyoConnector warning")) { Log.d(TAG, "VidyoConnector RegisterLogEventListener failed"); } } private void hideProgress(){ progress.setVisibility(GONE); } private void refreshView() { progress.setVisibility(GONE); vidyoConnector.ShowViewAt(imageContainer, 0, 0, imageContainer.getWidth(), imageContainer.getHeight()); }}
Does anyone knows what can cause this problem?