Search in sources :

Example 6 with PodChatException

use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.

the class Chat method setupCall.

public void setupCall(VideoCallParam videoCallParam, AudioCallParam audioCallParam, ScreenShareParam screenShareParam, CallConfig callConfig, List<CallPartnerView> remoteViews) {
    this.localPartnerView = videoCallParam.getCameraPreview();
    this.videoCallPartnerViews = new ArrayList<>(remoteViews);
    callServiceManager = new CallServiceManager(context, callConfig);
    podVideoCall = new PodCallBuilder(context, new IPodCall() {

        @Override
        public void onError(String s) {
            captureError(new PodChatException(s, ChatConstant.ERROR_CODE_CALL_INITIAL_ERROR));
        }

        @Override
        public void onEvent(String s) {
            showLog(s);
        }

        @Override
        public void onCameraReady(PodCall podCall) {
            showLog("Call is ready");
        }

        @Override
        public void onCameraIsNotAvailable(String message) {
            captureError(new PodChatException(ChatConstant.ERROR_CAMERA_NOT_AVAILABLE, ChatConstant.ERROR_CODE_CAMERA_NOT_AVAILABLE));
        }

        @Override
        public void onMicrophoneIsNotAvailable(String message) {
            captureError(new PodChatException(ChatConstant.ERROR_MICROPHONE_NOT_AVAILABLE, ChatConstant.ERROR_CODE_MICROPHONE_NOT_AVAILABLE));
        }

        @Override
        public void onDeviceIsNear() {
            listenerManager.callOnDeviceIsNear();
        }

        @Override
        public void onDeviceGotFar() {
            listenerManager.callOnDeviceGotFar();
        }
    }).setVideoCallParam(videoCallParam).setAudioCallParam(audioCallParam).setScreenShareParam(screenShareParam).build();
    podVideoCall.initial();
}
Also used : CallServiceManager(com.fanap.podchat.call.audio_call.CallServiceManager) PodChatException(com.fanap.podchat.util.PodChatException) PodCallBuilder(com.fanap.podcall.PodCallBuilder) IPodCall(com.fanap.podcall.IPodCall) IPodCall(com.fanap.podcall.IPodCall) PodCall(com.fanap.podcall.PodCall)

Example 7 with PodChatException

use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.

the class Chat method swapPartnerViews.

public void swapPartnerViews(SwapViewsRequest request) {
    if (podVideoCall != null) {
        if (viewPool != null) {
            if (viewPool.isScreenShareViewChanging(request.getFirstPartnerUserId(), request.getFirstPartnerView())) {
                captureError(new PodChatException("It's not possible to change screen share view during call", ChatConstant.ERROR_CODE_INVALID_REQUEST));
                return;
            }
            if (viewPool.isScreenShareViewChanging(request.getSecondPartnerUserId(), request.getSecondPartnerView())) {
                captureError(new PodChatException("It's not possible to change screen share view during call", ChatConstant.ERROR_CODE_INVALID_REQUEST));
                return;
            }
            boolean result = viewPool.swapPartnerViews(request.getFirstPartnerUserId(), request.getFirstPartnerView(), request.getSecondPartnerUserId(), request.getSecondPartnerView());
            if (result) {
                podVideoCall.updatePartnerSurface(request.getFirstPartnerUserId(), request.getSecondPartnerView());
                podVideoCall.updatePartnerSurface(request.getSecondPartnerUserId(), request.getFirstPartnerView());
            }
        }
    }
}
Also used : PodChatException(com.fanap.podchat.util.PodChatException)

Example 8 with PodChatException

use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method captureError.

@NonNull
protected String captureError(String errorMessage, long errorCode, String uniqueId, Throwable throwable) {
    ErrorOutPut error = new ErrorOutPut(true, errorMessage, errorCode, uniqueId);
    String jsonError = gson.toJson(error);
    listenerManager.callOnError(jsonError, error);
    showErrorLog(jsonError);
    if (sentryLog) {
        SentryEvent event = new SentryEvent(throwable);
        event.setEnvironment("PODCHAT");
        event.setLevel(SentryLevel.ERROR);
        event.setTag("FROM_SDK", "PODCHAT");
        event.setExtra("CACHE ENABLED", " >>> " + cache);
        Sentry.captureEvent(event, new PodChatException(errorMessage, uniqueId, getToken()));
    }
    if (log) {
        Log.e(TAG, "ErrorMessage: " + errorMessage + " *Code* " + errorCode + " *uniqueId* " + uniqueId);
    }
    return jsonError;
}
Also used : PodChatException(com.fanap.podchat.util.PodChatException) SentryEvent(io.sentry.core.SentryEvent) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) NonNull(android.support.annotation.NonNull)

Example 9 with PodChatException

use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.

the class ChatCore method captureError.

@NonNull
private String captureError(String errorMessage, long errorCode, String uniqueId) {
    ErrorOutPut error = new ErrorOutPut(true, errorMessage, errorCode, uniqueId);
    String jsonError = gson.toJson(error);
    listenerManager.callOnError(jsonError, error);
    showErrorLog(jsonError);
    if (errorCode != ChatConstant.ERROR_CODE_CHAT_READY && errorCode != 21) {
        if (sentryLog) {
            SentryEvent event = new SentryEvent(new PodChatException(errorMessage, uniqueId, getToken()));
            event.setEnvironment("PODCHAT");
            event.setLevel(SentryLevel.ERROR);
            event.setTag("FROM_SDK", "PODCHAT");
            event.setExtra("CACHE ENABLED", " >>> " + cache);
            Sentry.captureEvent(event, error);
        }
    }
    if (log) {
        Log.e(TAG, "ErrorMessage: " + errorMessage + " *Code* " + errorCode + " *uniqueId* " + uniqueId);
    }
    return jsonError;
}
Also used : PodChatException(com.fanap.podchat.util.PodChatException) SentryEvent(io.sentry.core.SentryEvent) ErrorOutPut(com.fanap.podchat.model.ErrorOutPut) NonNull(android.support.annotation.NonNull)

Example 10 with PodChatException

use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.

the class PodUploader method uploadImageToPodSpace.

private static Subscription uploadImageToPodSpace(String uniqueId, String threadHashCode, String fileServer, String token, int tokenIssuer, String xC, String yC, String hC, String wC, IPodUploadFileToPodSpace listener, String mimeType, File file, long fileSize) throws FileNotFoundException {
    int width = 0;
    int height = 0;
    String nWidth = "0";
    String nHeight = "0";
    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.getAbsolutePath(), options);
        width = options.outWidth;
        height = options.outHeight;
        nWidth = !Util.isNullOrEmpty(wC) ? wC : String.valueOf(width);
        nHeight = !Util.isNullOrEmpty(hC) ? hC : String.valueOf(height);
    } catch (Exception e) {
        throw new FileNotFoundException("Invalid image!");
    }
    listener.onUploadStarted(mimeType, file, fileSize);
    RetrofitHelperFileServer retrofitHelperFileServer = new RetrofitHelperFileServer(fileServer);
    FileApi fileApi = retrofitHelperFileServer.getService(FileApi.class);
    RequestBody namePart = RequestBody.create(MediaType.parse("multipart/form-data"), file.getName());
    RequestBody hashGroupPart = RequestBody.create(MediaType.parse("multipart/form-data"), threadHashCode);
    RequestBody xCPart = RequestBody.create(MediaType.parse("multipart/form-data"), !Util.isNullOrEmpty(xC) ? xC : "0");
    RequestBody yCPart = RequestBody.create(MediaType.parse("multipart/form-data"), !Util.isNullOrEmpty(yC) ? yC : "0");
    RequestBody hCPart = RequestBody.create(MediaType.parse("multipart/form-data"), nWidth);
    RequestBody wCPart = RequestBody.create(MediaType.parse("multipart/form-data"), nHeight);
    ProgressRequestBody requestFile = new ProgressRequestBody(file, mimeType, uniqueId, new ProgressRequestBody.UploadCallbacks() {

        @Override
        public void onProgress(String uniqueId, int progress, int totalBytesSent, int totalBytesToSend) {
            if (progress < 95)
                listener.onProgressUpdate(progress, totalBytesSent, totalBytesToSend);
        }
    });
    MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
    Observable<Response<UploadToPodSpaceResponse>> uploadObservable = fileApi.uploadImageToPodSpace(filePart, token, tokenIssuer, namePart, hashGroupPart, xCPart, yCPart, wCPart, hCPart);
    int finalWidth = width;
    int finalHeight = height;
    String finalNWidth = nWidth;
    String finalNHeight = nHeight;
    return uploadObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnError(error -> listener.onFailure(error.getMessage(), error)).subscribe(response -> {
        if (response.isSuccessful() && response.body() != null) {
            if (response.body().isHasError()) {
                listener.onFailure(response.body().getMessage(), new PodChatException(response.body().getMessage(), uniqueId, token));
                return;
            }
            listener.onProgressUpdate(100, (int) fileSize, 0);
            listener.onSuccess(response.body().getUploadToPodSpaceResult(), file, mimeType, fileSize, finalWidth, finalHeight, Integer.parseInt(finalNWidth), Integer.parseInt(finalNHeight));
        } else {
            try {
                if (response.errorBody() != null) {
                    listener.onFailure(response.errorBody().string(), new PodChatException(response.errorBody().string(), uniqueId, token));
                } else {
                    listener.onFailure(response.message(), new PodChatException(response.message(), uniqueId, token));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }, error -> listener.onFailure(error.getMessage(), error));
}
Also used : Context(android.content.Context) PodChatException(com.fanap.podchat.util.PodChatException) RetrofitHelperFileServer(com.fanap.podchat.networking.retrofithelper.RetrofitHelperFileServer) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) BitmapFactory(android.graphics.BitmapFactory) NonNull(android.support.annotation.NonNull) ResultFile(com.fanap.podchat.model.ResultFile) Response(retrofit2.Response) FileUpload(com.fanap.podchat.mainmodel.FileUpload) ChatConstant(com.fanap.podchat.util.ChatConstant) ChatResponse(com.fanap.podchat.model.ChatResponse) RequestBody(okhttp3.RequestBody) Observable(rx.Observable) Schedulers(rx.schedulers.Schedulers) FilePick(com.fanap.podchat.util.FilePick) Log(android.util.Log) MediaType(okhttp3.MediaType) TAG(com.fanap.podchat.chat.Chat.TAG) IOException(java.io.IOException) ProgressRequestBody(com.fanap.podchat.networking.ProgressRequestBody) FileApi(com.fanap.podchat.networking.api.FileApi) Util(com.fanap.podchat.util.Util) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ResultImageFile(com.fanap.podchat.model.ResultImageFile) FileImageUpload(com.fanap.podchat.model.FileImageUpload) MultipartBody(okhttp3.MultipartBody) Subscription(rx.Subscription) UploadingQueueCache(com.fanap.podchat.cachemodel.queue.UploadingQueueCache) FileUtils(com.fanap.podchat.util.FileUtils) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PodChatException(com.fanap.podchat.util.PodChatException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) RetrofitHelperFileServer(com.fanap.podchat.networking.retrofithelper.RetrofitHelperFileServer) Response(retrofit2.Response) ChatResponse(com.fanap.podchat.model.ChatResponse) PodChatException(com.fanap.podchat.util.PodChatException) MultipartBody(okhttp3.MultipartBody) BitmapFactory(android.graphics.BitmapFactory) ProgressRequestBody(com.fanap.podchat.networking.ProgressRequestBody) FileApi(com.fanap.podchat.networking.api.FileApi) RequestBody(okhttp3.RequestBody) ProgressRequestBody(com.fanap.podchat.networking.ProgressRequestBody)

Aggregations

PodChatException (com.fanap.podchat.util.PodChatException)24 NonNull (android.support.annotation.NonNull)8 ChatResponse (com.fanap.podchat.model.ChatResponse)7 Response (retrofit2.Response)7 Context (android.content.Context)6 BitmapFactory (android.graphics.BitmapFactory)6 Uri (android.net.Uri)6 Log (android.util.Log)6 UploadingQueueCache (com.fanap.podchat.cachemodel.queue.UploadingQueueCache)6 TAG (com.fanap.podchat.chat.Chat.TAG)6 FileUpload (com.fanap.podchat.mainmodel.FileUpload)6 FileImageUpload (com.fanap.podchat.model.FileImageUpload)6 ResultFile (com.fanap.podchat.model.ResultFile)6 ResultImageFile (com.fanap.podchat.model.ResultImageFile)6 ProgressRequestBody (com.fanap.podchat.networking.ProgressRequestBody)6 FileApi (com.fanap.podchat.networking.api.FileApi)6 RetrofitHelperFileServer (com.fanap.podchat.networking.retrofithelper.RetrofitHelperFileServer)6 ChatConstant (com.fanap.podchat.util.ChatConstant)6 FilePick (com.fanap.podchat.util.FilePick)6 FileUtils (com.fanap.podchat.util.FileUtils)6