Search in sources :

Example 16 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-fbads by callstack.

the class NativeAdManager method init.

/**
 * Initialises native ad manager for a given placement id and ads to request.
 * This method is run on the UI thread
 *
 * @param placementId
 * @param adsToRequest
 */
@ReactMethod
public void init(final String placementId, final int adsToRequest) {
    final ReactApplicationContext reactContext = this.getReactApplicationContext();
    UiThreadUtil.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            final NativeAdsManager adsManager = new NativeAdsManager(reactContext, placementId, adsToRequest);
            adsManager.setListener(NativeAdManager.this);
            mAdsManagers.put(placementId, adsManager);
            adsManager.loadAds();
        }
    });
}
Also used : ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) NativeAdsManager(com.facebook.ads.NativeAdsManager) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 17 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-twilio-programmable-voice by hoxfon.

the class TwilioVoiceModule method ignore.

@ReactMethod
public void ignore() {
    callAccepted = false;
    SoundPoolManager.getInstance(getReactApplicationContext()).stopRinging();
    WritableMap params = Arguments.createMap();
    if (activeCallInvite != null) {
        params.putString("call_sid", activeCallInvite.getCallSid());
        params.putString("call_from", activeCallInvite.getFrom());
        params.putString("call_to", activeCallInvite.getTo());
        params.putString("call_state", activeCallInvite.getState().name());
        clearIncomingNotification(activeCallInvite);
    }
    eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, params);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 18 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-twilio-programmable-voice by hoxfon.

the class TwilioVoiceModule method accept.

@ReactMethod
public void accept() {
    callAccepted = true;
    SoundPoolManager.getInstance(getReactApplicationContext()).stopRinging();
    if (activeCallInvite != null) {
        if (activeCallInvite.getState() == CallInvite.State.PENDING) {
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "accept() activeCallInvite.getState() PENDING");
            }
            activeCallInvite.accept(getReactApplicationContext(), callListener);
            clearIncomingNotification(activeCallInvite);
        } else {
            // when the user answers a call from a notification before the react-native App
            // is completely initialised, and the first event has been skipped
            // re-send connectionDidConnect message to JS
            WritableMap params = Arguments.createMap();
            params.putString("call_sid", activeCallInvite.getCallSid());
            params.putString("call_from", activeCallInvite.getFrom());
            params.putString("call_to", activeCallInvite.getTo());
            params.putString("call_state", activeCallInvite.getState().name());
            callNotificationManager.createHangupLocalNotification(getReactApplicationContext(), activeCallInvite.getCallSid(), activeCallInvite.getFrom());
            eventManager.sendEvent(EVENT_CONNECTION_DID_CONNECT, params);
        }
    } else {
        eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, null);
    }
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 19 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-twilio-programmable-voice by hoxfon.

the class TwilioVoiceModule method getActiveCall.

@ReactMethod
public void getActiveCall(Promise promise) {
    if (activeCall != null) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "Active call found state = " + activeCall.getState());
        }
        WritableMap params = Arguments.createMap();
        params.putString("call_sid", activeCall.getSid());
        params.putString("call_from", activeCall.getFrom());
        params.putString("call_to", activeCall.getTo());
        params.putString("call_state", activeCall.getState().name());
        promise.resolve(params);
        return;
    }
    if (activeCallInvite != null) {
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "Active call invite found state = " + activeCallInvite.getState());
        }
        WritableMap params = Arguments.createMap();
        params.putString("call_sid", activeCallInvite.getCallSid());
        params.putString("call_from", activeCallInvite.getFrom());
        params.putString("call_to", activeCallInvite.getTo());
        params.putString("call_state", activeCallInvite.getState().name());
        promise.resolve(params);
        return;
    }
    promise.resolve(null);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 20 with ReactMethod

use of com.facebook.react.bridge.ReactMethod in project react-native-twilio-programmable-voice by hoxfon.

the class TwilioVoiceModule method connect.

@ReactMethod
public void connect(ReadableMap params) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "connect params: " + params);
    }
    WritableMap errParams = Arguments.createMap();
    if (accessToken == null) {
        errParams.putString("err", "Invalid access token");
        eventManager.sendEvent(EVENT_DEVICE_NOT_READY, errParams);
        return;
    }
    if (params == null) {
        errParams.putString("err", "Invalid parameters");
        eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams);
        return;
    } else if (!params.hasKey("To")) {
        errParams.putString("err", "Invalid To parameter");
        eventManager.sendEvent(EVENT_CONNECTION_DID_DISCONNECT, errParams);
        return;
    }
    toNumber = params.getString("To");
    if (params.hasKey("ToName")) {
        toName = params.getString("ToName");
    }
    // optional parameter that will be delivered to the server
    if (params.hasKey("CallerId")) {
        twiMLParams.put("CallerId", params.getString("CallerId"));
    }
    twiMLParams.put("To", params.getString("To"));
    activeCall = Voice.call(getReactApplicationContext(), accessToken, twiMLParams, callListener);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

ReactMethod (com.facebook.react.bridge.ReactMethod)82 Activity (android.app.Activity)21 Intent (android.content.Intent)11 WritableMap (com.facebook.react.bridge.WritableMap)11 Bundle (android.os.Bundle)9 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)6 WritableArray (com.facebook.react.bridge.WritableArray)6 ArrayList (java.util.ArrayList)5 Camera (android.hardware.Camera)4 NativeViewHierarchyManager (com.facebook.react.uimanager.NativeViewHierarchyManager)4 UIBlock (com.facebook.react.uimanager.UIBlock)4 UIManagerModule (com.facebook.react.uimanager.UIManagerModule)4 ShareContent (com.facebook.share.model.ShareContent)4 LayoutNode (com.reactnativenavigation.options.LayoutNode)4 LoginManager (com.facebook.login.LoginManager)3 ReactActivity (com.facebook.react.ReactActivity)3 LatLng (com.google.android.gms.maps.model.LatLng)3 ActivityNotFoundException (android.content.ActivityNotFoundException)2 RemoteException (android.os.RemoteException)2 JSApplicationIllegalArgumentException (com.facebook.react.bridge.JSApplicationIllegalArgumentException)2