Example usage for com.facebook.react.bridge ReadableMap getString

List of usage examples for com.facebook.react.bridge ReadableMap getString

Introduction

In this page you can find the example usage for com.facebook.react.bridge ReadableMap getString.

Prototype

@Nullable
    String getString(@NonNull String name);

Source Link

Usage

From source file:com.reactirislibrary.RNIrisSdkModule.java

License:Open Source License

/**
 * To create a session//ww w .  j av  a2  s .co  m
 * @param roomId Room Id
 * @param sessionConfig Session Config
 */
@ReactMethod
public void createSession(String roomId, ReadableMap sessionConfig) {
    Log.i(TAG_RNIRISSDK, " createSession called with " + roomId);

    // Check the room id
    if (sessionArray.containsKey(roomId)) {
        Log.e(TAG_RNIRISSDK, "A  session with RoomId " + roomId + " is already created");
        return;
    }

    // Get the notification data
    String notificationData = sessionConfig.getString("notificationData");
    IrisRtcSession mSession = new IrisRtcSession(reactContext);
    mSession.isVideoBridge = true;

    // Create the session
    try {
        mSession.create(roomId, notificationData, this);
        sessionArray.put(roomId, mSession);
    } catch (IrisRtcSDKException e) {
        Log.e(TAG_RNIRISSDK, e.getStackTrace().toString());
    }
}

From source file:com.reactirislibrary.RNIrisSdkModule.java

License:Open Source License

/**
 * To join a session//from   www .  ja  va2  s .c om
 * @param roomId
 * @param sessionConfig
 */
@ReactMethod
public void joinSession(String roomId, ReadableMap sessionConfig) {
    Log.i(TAG_RNIRISSDK, " joinSession called with " + roomId);

    // Check the room id
    if (sessionArray.containsKey(roomId)) {
        Log.e(TAG_RNIRISSDK, "A  session with RoomId " + roomId + " is already created");
        return;
    }

    // Check the parameters
    if (sessionConfig.getString("roomToken") == null || sessionConfig.getString("roomTokenExpiry") == null
            || sessionConfig.getString("rtcServer") == null) {
        WritableMap event = Arguments.createMap();
        event.putString("description",
                "React::IrisRtcSdk Missing mandatory parameters, check whether you have passed roomToken, roomTokenExpiry and rtcServer !!!");
        event.putInt("code ", -1); // To match with ios : TBD

        this.sendEvent(IrisEventOnSessionError, event);
        return;
    }

    // Get the notification data
    String notificationData = sessionConfig.getString("notificationData");
    IrisRtcSession mSession = new IrisRtcSession(reactContext);
    mSession.isVideoBridge = true;

    // Join the session
    try {
        mSession.join(roomId, sessionConfig.getString("roomToken"), sessionConfig.getString("roomTokenExpiry"),
                videoStream, sessionConfig.getString("rtcServer"), this);
        sessionArray.put(roomId, mSession);
    } catch (IrisRtcSDKException e) {
        Log.e(TAG_RNIRISSDK, e.getStackTrace().toString());
    }

}

From source file:com.reactirislibrary.RNIrisSdkModule.java

License:Open Source License

/**
 * This method is called to upgrade to video session from chat.
 * @param sessionId : Session Id/*w  ww . j  a va2 s. c o m*/
 * @param sessionConfig : Config
 */
@ReactMethod
public void upgradeToVideo(String sessionId, ReadableMap sessionConfig) {
    Log.i(TAG_RNIRISSDK, " upgradeToVideo called with " + sessionId);

    // Check the room id
    if (!sessionArray.containsKey(sessionId)) {
        Log.e(TAG_RNIRISSDK, "A  session with RoomId " + sessionId + " is not created yet");
        return;
    }
    IrisRtcSession mSession = sessionArray.get(sessionId);
    mSession.upgradeToVideo(sessionConfig.getString("notificationData"), videoStream);
}

From source file:com.reactirislibrary.RNIrisSdkModule.java

License:Open Source License

/**
 * To create a session/*from  w  ww . j a v a  2s .co  m*/
 * @param roomId Room Id
 * @param sessionConfig Session Config
 */
@ReactMethod
public void createVideoSession(String roomId, ReadableMap sessionConfig) {
    Log.i(TAG_RNIRISSDK, " createVideoSession called with " + roomId);

    // Check the room id
    if (videoSessionArray.containsKey(roomId)) {
        Log.e(TAG_RNIRISSDK, "A  session with RoomId " + roomId + " is already created");
        return;
    }

    // Init the session
    IrisRtcVideoSession mSession = new IrisRtcVideoSession(reactContext);
    mSession.isVideoBridge = true;

    // Create the session
    try {
        mSession.create(roomId, sessionConfig.getString("notificationData"), videoStream, this);
        videoSessionArray.put(roomId, mSession);
    } catch (IrisRtcSDKException e) {
        Log.e(TAG_RNIRISSDK, e.getStackTrace().toString());
    }
}

From source file:com.reactirislibrary.RNIrisSdkModule.java

License:Open Source License

/**
 * To join a session/*from  w  w  w. j a  va 2s .  co  m*/
 * @param roomId Room Id
 * @param sessionConfig Session Config
 */
@ReactMethod
public void joinVideoSession(String roomId, ReadableMap sessionConfig) {
    Log.i(TAG_RNIRISSDK, " joinVideoSession called with " + roomId);

    // Check the room id
    if (videoSessionArray.containsKey(roomId)) {
        Log.e(TAG_RNIRISSDK, "A  session with RoomId " + roomId + " is already created");
        return;
    }

    // Check the parameters
    if (sessionConfig.getString("roomToken") == null || sessionConfig.getString("roomTokenExpiry") == null
            || sessionConfig.getString("rtcServer") == null) {
        WritableMap event = Arguments.createMap();
        event.putString("description",
                "React::IrisRtcSdk Missing mandatory parameters, check whether you have passed roomToken, roomTokenExpiry and rtcServer !!!");
        event.putInt("code ", -1); // To match with ios : TBD

        this.sendEvent(IrisEventOnSessionError, event);
        return;
    }

    // Get the notification data
    IrisRtcVideoSession mSession = new IrisRtcVideoSession(reactContext);
    mSession.isVideoBridge = true;

    // Join the session
    try {
        mSession.join(roomId, sessionConfig.getString("roomToken"), sessionConfig.getString("roomTokenExpiry"),
                videoStream, sessionConfig.getString("rtcServer"), this);
        videoSessionArray.put(roomId, mSession);
    } catch (IrisRtcSDKException e) {
        Log.e(TAG_RNIRISSDK, e.getStackTrace().toString());
    }
}

From source file:com.roihuapp.CacheClearableWebViewManager.java

License:Open Source License

@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");
            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING,
                        null);/*from   ww w.j a v  a2  s .  c om*/
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }
            return;
        }
        if (source.hasKey("uri")) {
            String url = source.getString("uri");
            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }
            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    headerMap.put(key, headers.getString(key));
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}

From source file:com.shahenlibrary.Trimmer.Trimmer.java

License:Open Source License

static void trim(ReadableMap options, final Promise promise, ReactApplicationContext ctx) {
    String source = options.getString("source");
    String startTime = options.getString("startTime");
    String endTime = options.getString("endTime");

    final File tempFile = createTempFile("mp4", promise, ctx);

    ArrayList<String> cmd = new ArrayList<String>();
    cmd.add("-y"); // NOTE: OVERWRITE OUTPUT FILE

    // NOTE: INPUT FILE
    cmd.add("-i");
    cmd.add(source);/* w w w  .j  a v a2  s  .  c o m*/

    // NOTE: PLACE ARGUMENTS FOR FFMPEG IN THIS ORDER:
    // 1. "-i" (INPUT FILE)
    // 2. "-ss" (START TIME)
    // 3. "-to" (END TIME) or "-t" (TRIM TIME)
    // OTHERWISE WE WILL LOSE ACCURACY AND WILL GET WRONG CLIPPED VIDEO

    cmd.add("-ss");
    cmd.add(startTime);

    cmd.add("-to");
    cmd.add(endTime);

    cmd.add("-preset");
    cmd.add("ultrafast");
    // NOTE: DO NOT CONVERT AUDIO TO SAVE TIME
    cmd.add("-c:a");
    cmd.add("copy");
    // NOTE: FLAG TO CONVER "AAC" AUDIO CODEC
    cmd.add("-strict");
    cmd.add("-2");
    // NOTE: OUTPUT FILE
    cmd.add(tempFile.getPath());

    executeFfmpegCommand(cmd, tempFile.getPath(), ctx, promise, "Trim error", null);
}

From source file:com.shahenlibrary.Trimmer.Trimmer.java

License:Open Source License

static void crop(String source, ReadableMap options, final Promise promise, ReactApplicationContext ctx) {
    int cropWidth = (int) (options.getDouble("cropWidth"));
    int cropHeight = (int) (options.getDouble("cropHeight"));
    int cropOffsetX = (int) (options.getDouble("cropOffsetX"));
    int cropOffsetY = (int) (options.getDouble("cropOffsetY"));

    ReadableMap videoSizes = getVideoRequiredMetadata(source, ctx);
    int videoWidth = videoSizes.getInt("width");
    int videoHeight = videoSizes.getInt("height");

    ReadableMap sizes = formatWidthAndHeightForFfmpeg(cropWidth, cropHeight,
            // NOTE: MUST CHECK AGAINST "CROPPABLE" WIDTH/HEIGHT. NOT FULL WIDTH/HEIGHT
            videoWidth - cropOffsetX, videoHeight - cropOffsetY);
    cropWidth = sizes.getInt("width");
    cropHeight = sizes.getInt("height");

    // TODO: 1) ADD METHOD TO CHECK "IS FFMPEG LOADED".
    // 2) CHECK IT HERE
    // 3) EXPORT THAT METHOD TO "JS"

    final File tempFile = createTempFile("mp4", promise, ctx);

    ArrayList<String> cmd = new ArrayList<String>();
    cmd.add("-y"); // NOTE: OVERWRITE OUTPUT FILE

    // NOTE: INPUT FILE
    cmd.add("-i");
    cmd.add(source);//from  ww w .j av  a 2 s. c o m

    // NOTE: PLACE ARGUMENTS FOR FFMPEG IN THIS ORDER:
    // 1. "-i" (INPUT FILE)
    // 2. "-ss" (START TIME)
    // 3. "-to" (END TIME) or "-t" (TRIM TIME)
    // OTHERWISE WE WILL LOSE ACCURACY AND WILL GET WRONG CLIPPED VIDEO

    String startTime = options.getString("startTime");
    if (!startTime.equals(null) && !startTime.equals("")) {
        cmd.add("-ss");
        cmd.add(startTime);
    }

    String endTime = options.getString("endTime");
    if (!endTime.equals(null) && !endTime.equals("")) {
        cmd.add("-to");
        cmd.add(endTime);
    }

    cmd.add("-vf");
    cmd.add("crop=" + Integer.toString(cropWidth) + ":" + Integer.toString(cropHeight) + ":"
            + Integer.toString(cropOffsetX) + ":" + Integer.toString(cropOffsetY));

    cmd.add("-preset");
    cmd.add("ultrafast");
    // NOTE: DO NOT CONVERT AUDIO TO SAVE TIME
    cmd.add("-c:a");
    cmd.add("copy");
    // NOTE: FLAG TO CONVER "AAC" AUDIO CODEC
    cmd.add("-strict");
    cmd.add("-2");
    // NOTE: OUTPUT FILE
    cmd.add(tempFile.getPath());

    executeFfmpegCommand(cmd, tempFile.getPath(), ctx, promise, "Crop error", null);
}

From source file:com.shahenlibrary.Trimmer.TrimmerManager.java

License:Open Source License

@ReactMethod
public void getPreviewImageAtPosition(ReadableMap options, Promise promise) {
    String source = options.getString("source");
    double sec = options.hasKey("second") ? options.getDouble("second") : 0;
    String format = options.hasKey("format") ? options.getString("format") : null;
    Trimmer.getPreviewImageAtPosition(source, sec, format, promise, reactContext);
}

From source file:com.silklabs.react.blobs.WebSocketModule.java

License:Open Source License

@ReactMethod
public void connect(final String url, @Nullable final ReadableArray protocols,
        @Nullable final ReadableMap headers, final int id) {
    OkHttpClient client = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS)
            .writeTimeout(10, TimeUnit.SECONDS).readTimeout(0, TimeUnit.MINUTES) // Disable timeouts for read
            .build();/*from   w  w w.  jav  a2 s .  co m*/

    Request.Builder builder = new Request.Builder().tag(id).url(url);

    if (headers != null) {
        ReadableMapKeySetIterator iterator = headers.keySetIterator();

        if (!headers.hasKey("origin")) {
            builder.addHeader("origin", setDefaultOrigin(url));
        }

        while (iterator.hasNextKey()) {
            String key = iterator.nextKey();
            if (ReadableType.String.equals(headers.getType(key))) {
                builder.addHeader(key, headers.getString(key));
            } else {
                FLog.w(ReactConstants.TAG, "Ignoring: requested " + key + ", value not a string");
            }
        }
    } else {
        builder.addHeader("origin", setDefaultOrigin(url));
    }

    if (protocols != null && protocols.size() > 0) {
        StringBuilder protocolsValue = new StringBuilder("");
        for (int i = 0; i < protocols.size(); i++) {
            String v = protocols.getString(i).trim();
            if (!v.isEmpty() && !v.contains(",")) {
                protocolsValue.append(v);
                protocolsValue.append(",");
            }
        }
        if (protocolsValue.length() > 0) {
            protocolsValue.replace(protocolsValue.length() - 1, protocolsValue.length(), "");
            builder.addHeader("Sec-WebSocket-Protocol", protocolsValue.toString());
        }
    }

    WebSocketCall.create(client, builder.build()).enqueue(new WebSocketListener() {

        @Override
        public void onOpen(WebSocket webSocket, Response response) {
            mWebSocketConnections.put(id, webSocket);
            WritableMap params = Arguments.createMap();
            params.putInt("id", id);
            sendEvent("websocketOpen", params);
        }

        @Override
        public void onClose(int code, String reason) {
            WritableMap params = Arguments.createMap();
            params.putInt("id", id);
            params.putInt("code", code);
            params.putString("reason", reason);
            sendEvent("websocketClosed", params);
        }

        @Override
        public void onFailure(IOException e, Response response) {
            notifyWebSocketFailed(id, e.getMessage());
        }

        @Override
        public void onPong(Buffer buffer) {
        }

        @Override
        public void onMessage(ResponseBody response) throws IOException {
            WritableMap params = Arguments.createMap();
            params.putInt("id", id);

            if (mBlobsEnabled.containsKey(id) && mBlobsEnabled.get(id)
                    && response.contentType() == WebSocket.BINARY) {
                byte[] data;
                try {
                    data = response.source().readByteArray();
                } catch (IOException e) {
                    notifyWebSocketFailed(id, e.getMessage());
                    return;
                }
                WritableMap blob = Arguments.createMap();
                blob.putString("blobId", BlobModule.store(data));
                blob.putInt("offset", 0);
                blob.putInt("size", data.length);
                params.putMap("data", blob);
                params.putString("type", "blob");
            } else {
                String message;
                try {
                    if (response.contentType() == WebSocket.BINARY) {
                        message = Base64.encodeToString(response.source().readByteArray(), Base64.NO_WRAP);
                    } else {
                        message = response.source().readUtf8();
                    }
                } catch (IOException e) {
                    notifyWebSocketFailed(id, e.getMessage());
                    return;
                }
                params.putString("data", message);
                params.putString("type", response.contentType() == WebSocket.BINARY ? "binary" : "text");
            }

            try {
                response.source().close();
            } catch (IOException e) {
                FLog.e(ReactConstants.TAG, "Could not close BufferedSource for WebSocket id " + id, e);
            }

            sendEvent("websocketMessage", params);
        }
    });

    // Trigger shutdown of the dispatcher's executor so this process can exit cleanly
    client.dispatcher().executorService().shutdown();
}