Search in sources :

Example 1 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class HardwareServiceImpl method removeVideoSurface.

@Override
public void removeVideoSurface(String id) {
    Log.i(TAG, "removeVideoSurface " + id);
    Shm shm = videoInputs.get(id);
    if (shm == null) {
        return;
    }
    if (shm.window != 0) {
        try {
            stopVideo(shm.id, shm.window);
        } catch (Exception e) {
            Log.e(TAG, "removeVideoSurface error" + e);
        }
        shm.window = 0;
    }
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_CALL, shm.id);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_STARTED, false);
    setChanged();
    notifyObservers(event);
}
Also used : ServiceEvent(cx.ring.model.ServiceEvent) IOException(java.io.IOException)

Example 2 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class HardwareServiceImpl method addVideoSurface.

@Override
public void addVideoSurface(String id, Object holder) {
    if (!(holder instanceof SurfaceHolder)) {
        return;
    }
    Log.w(TAG, "addVideoSurface " + id + holder.hashCode());
    Shm shm = videoInputs.get(id);
    WeakReference<SurfaceHolder> surfaceHolder = new WeakReference<>((SurfaceHolder) holder);
    videoSurfaces.put(id, surfaceHolder);
    if (shm != null && shm.window == 0) {
        shm.window = startVideo(shm.id, surfaceHolder.get().getSurface(), shm.w, shm.h);
    }
    if (shm == null || shm.window == 0) {
        Log.i(TAG, "DRingService.addVideoSurface() no window !");
        ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
        event.addEventInput(ServiceEvent.EventInput.VIDEO_START, true);
        setChanged();
        notifyObservers(event);
        return;
    }
    ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_CALL, shm.id);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_STARTED, true);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_WIDTH, shm.w);
    event.addEventInput(ServiceEvent.EventInput.VIDEO_HEIGHT, shm.h);
    setChanged();
    notifyObservers(event);
}
Also used : SurfaceHolder(android.view.SurfaceHolder) ServiceEvent(cx.ring.model.ServiceEvent) WeakReference(java.lang.ref.WeakReference)

Example 3 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class HardwareServiceImpl method stopCapture.

@Override
public void stopCapture() {
    Log.d(TAG, "stopCapture: " + previewCamera);
    if (previewCamera != null) {
        final Camera preview = previewCamera;
        final VideoParams params = previewParams;
        previewCamera = null;
        try {
            preview.setPreviewCallback(null);
            preview.setErrorCallback(null);
            preview.stopPreview();
            preview.release();
        } catch (Exception e) {
            Log.e(TAG, "stopCapture error" + e);
        }
        ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.VIDEO_EVENT);
        event.addEventInput(ServiceEvent.EventInput.VIDEO_STARTED, false);
        event.addEventInput(ServiceEvent.EventInput.VIDEO_WIDTH, params.width);
        event.addEventInput(ServiceEvent.EventInput.VIDEO_HEIGHT, params.height);
        setChanged();
        notifyObservers(event);
    }
}
Also used : ServiceEvent(cx.ring.model.ServiceEvent) Camera(android.hardware.Camera) IOException(java.io.IOException)

Example 4 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class ConversationFacade method handleDataTransferEvent.

private void handleDataTransferEvent(DataTransfer transfer, DataTransferEventCode transferEventCode) {
    CallContact contact = mContactService.findContactByNumber(transfer.getPeerId());
    Conversation conversation = startConversation(contact);
    if (transferEventCode == DataTransferEventCode.CREATED) {
        if (transfer.isPicture() && !transfer.isOutgoing()) {
            File path = mDeviceRuntimeService.getConversationPath(transfer.getPeerId(), transfer.getStoragePath());
            mAccountService.acceptFileTransfer(transfer.getDataTransferId(), path.getAbsolutePath(), 0);
        }
        conversation.addFileTransfer(transfer);
        setChanged();
        notifyObservers(new ServiceEvent(ServiceEvent.EventType.DATA_TRANSFER));
    } else {
        conversation.updateFileTransfer(transfer, transferEventCode);
        setChanged();
        ServiceEvent event = new ServiceEvent(ServiceEvent.EventType.DATA_TRANSFER_UPDATE);
        event.addEventInput(ServiceEvent.EventInput.TRANSFER_INFO, transfer);
        notifyObservers(event);
    }
    mNotificationService.showFileTransferNotification(transfer, transferEventCode, contact);
}
Also used : ServiceEvent(cx.ring.model.ServiceEvent) Conversation(cx.ring.model.Conversation) File(java.io.File) CallContact(cx.ring.model.CallContact)

Example 5 with ServiceEvent

use of cx.ring.model.ServiceEvent in project ring-client-android by savoirfairelinux.

the class ConversationFacade method update.

@Override
public void update(Observable observable, ServiceEvent event) {
    if (event == null) {
        return;
    }
    ServiceEvent mEvent;
    if (observable instanceof HistoryService) {
        switch(event.getEventType()) {
            case INCOMING_MESSAGE:
                {
                    TextMessage txt = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
                    if (txt == null) {
                        Log.d(TAG, "Received a null text message");
                        return;
                    }
                    parseNewMessage(txt);
                    updateTextNotifications();
                    setChanged();
                    mEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
                    notifyObservers(mEvent);
                    break;
                }
            case ACCOUNT_MESSAGE_STATUS_CHANGED:
                {
                    TextMessage newMsg = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
                    Conversation conv = getConversationByContact(mContactService.findContactByNumber(newMsg.getNumber()));
                    if (conv != null) {
                        conv.updateTextMessage(newMsg);
                    }
                    setChanged();
                    mEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
                    notifyObservers(mEvent);
                    break;
                }
            case HISTORY_LOADED:
                Account account = mAccountService.getCurrentAccount();
                if (account != null) {
                    boolean acceptAllMessages = account.getDetailBoolean(ConfigKey.DHT_PUBLIC_IN);
                    mConversationMap.clear();
                    addContacts(acceptAllMessages);
                    List<HistoryCall> historyCalls = (List<HistoryCall>) event.getEventInput(ServiceEvent.EventInput.HISTORY_CALLS, ArrayList.class);
                    parseHistoryCalls(historyCalls, acceptAllMessages);
                    List<HistoryText> historyTexts = (List<HistoryText>) event.getEventInput(ServiceEvent.EventInput.HISTORY_TEXTS, ArrayList.class);
                    parseHistoryTexts(historyTexts, acceptAllMessages);
                    List<DataTransfer> historyTransfers = (List<DataTransfer>) event.getEventInput(ServiceEvent.EventInput.HISTORY_TRANSFERS, ArrayList.class);
                    parseHistoryTransfers(historyTransfers, acceptAllMessages);
                    aggregateHistory();
                    searchForRingIdInBlockchain();
                }
                setChanged();
                mEvent = new ServiceEvent(ServiceEvent.EventType.CONVERSATIONS_CHANGED);
                notifyObservers(mEvent);
                break;
            case HISTORY_MODIFIED:
                refreshConversations();
                break;
        }
    } else if (observable instanceof CallService) {
        Conversation conversation = null;
        Conference conference = null;
        SipCall call;
        switch(event.getEventType()) {
            case CALL_STATE_CHANGED:
                call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                if (call == null) {
                    Log.w(TAG, "CALL_STATE_CHANGED : call is null");
                    return;
                }
                int newState = call.getCallState();
                mHardwareService.updateAudioState(newState == SipCall.State.RINGING && call.isIncoming(), call.isOnGoing() && !call.isAudioOnly());
                for (Conversation conv : mConversationMap.values()) {
                    conference = conv.getConference(call.getCallId());
                    if (conference != null) {
                        conversation = conv;
                        Log.w(TAG, "CALL_STATE_CHANGED : found conversation " + call.getCallId());
                        break;
                    }
                }
                if (conversation == null) {
                    conversation = startConversation(call.getContact());
                    conference = new Conference(call);
                    conversation.addConference(conference);
                }
                Log.w(TAG, "CALL_STATE_CHANGED : updating call state to " + newState);
                if ((call.isRinging() || newState == SipCall.State.CURRENT) && call.getTimestampStart() == 0) {
                    call.setTimestampStart(System.currentTimeMillis());
                }
                if ((newState == SipCall.State.CURRENT && call.isIncoming()) || newState == SipCall.State.RINGING && call.isOutGoing()) {
                    mAccountService.sendProfile(call.getCallId(), call.getAccount());
                } else if (newState == SipCall.State.HUNGUP || newState == SipCall.State.BUSY || newState == SipCall.State.FAILURE || newState == SipCall.State.OVER) {
                    mNotificationService.cancelCallNotification(call.getCallId().hashCode());
                    mHardwareService.closeAudioState();
                    if (newState == SipCall.State.HUNGUP) {
                        call.setTimestampEnd(System.currentTimeMillis());
                    }
                    if (call.getTimestampStart() == 0) {
                        call.setTimestampStart(System.currentTimeMillis());
                    }
                    if (call.getTimestampEnd() == 0) {
                        call.setTimestampEnd(System.currentTimeMillis());
                    }
                    mHistoryService.insertNewEntry(conference);
                    conference.removeParticipant(call);
                    conversation.addHistoryCall(new HistoryCall(call));
                    mCallService.removeCallForId(call.getCallId());
                }
                if (conference.getParticipants().isEmpty()) {
                    conversation.removeConference(conference);
                }
                setChanged();
                mEvent = new ServiceEvent(ServiceEvent.EventType.CALL_STATE_CHANGED);
                notifyObservers(mEvent);
                break;
            case INCOMING_CALL:
                call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                conversation = startConversation(call.getContact());
                conference = new Conference(call);
                conversation.addConference(conference);
                mNotificationService.showCallNotification(conference);
                mHardwareService.setPreviewSettings();
                Conference currenConf = getCurrentCallingConf();
                mHardwareService.updateAudioState(currenConf.getState() == SipCall.State.RINGING && currenConf.isIncoming(), false);
                setChanged();
                ServiceEvent serviceEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_CALL);
                notifyObservers(serviceEvent);
                break;
        }
    } else if (observable instanceof ContactService) {
        switch(event.getEventType()) {
            case CONTACTS_CHANGED:
                refreshConversations();
                break;
        }
    } else if (observable instanceof AccountService) {
        switch(event.getEventType()) {
            case REGISTERED_NAME_FOUND:
                {
                    int state = event.getEventInput(ServiceEvent.EventInput.STATE, Integer.class);
                    if (state != 0) {
                        break;
                    }
                    String accountId = event.getEventInput(ServiceEvent.EventInput.ACCOUNT_ID, String.class);
                    String name = event.getEventInput(ServiceEvent.EventInput.NAME, String.class);
                    Uri address = new Uri(event.getEventInput(ServiceEvent.EventInput.ADDRESS, String.class));
                    if (mContactService.setRingContactName(accountId, address, name)) {
                        setChanged();
                        notifyObservers(new ServiceEvent(ServiceEvent.EventType.USERNAME_CHANGED));
                    }
                    break;
                }
            case DATA_TRANSFER:
                {
                    DataTransferEventCode transferEventCode = event.getEventInput(ServiceEvent.EventInput.TRANSFER_EVENT_CODE, DataTransferEventCode.class);
                    DataTransfer transfer = event.getEventInput(ServiceEvent.EventInput.TRANSFER_INFO, DataTransfer.class);
                    handleDataTransferEvent(transfer, transferEventCode);
                    break;
                }
        }
    }
}
Also used : Account(cx.ring.model.Account) SipCall(cx.ring.model.SipCall) SecureSipCall(cx.ring.model.SecureSipCall) HistoryText(cx.ring.model.HistoryText) ArrayList(java.util.ArrayList) HistoryService(cx.ring.services.HistoryService) Conversation(cx.ring.model.Conversation) Conference(cx.ring.model.Conference) Uri(cx.ring.model.Uri) HistoryCall(cx.ring.model.HistoryCall) ContactService(cx.ring.services.ContactService) DataTransfer(cx.ring.model.DataTransfer) ServiceEvent(cx.ring.model.ServiceEvent) ArrayList(java.util.ArrayList) List(java.util.List) AccountService(cx.ring.services.AccountService) TextMessage(cx.ring.model.TextMessage) DataTransferEventCode(cx.ring.model.DataTransferEventCode) CallService(cx.ring.services.CallService)

Aggregations

ServiceEvent (cx.ring.model.ServiceEvent)43 Account (cx.ring.model.Account)13 DataTransfer (cx.ring.model.DataTransfer)4 HistoryText (cx.ring.model.HistoryText)4 TextMessage (cx.ring.model.TextMessage)4 SQLException (java.sql.SQLException)4 SurfaceHolder (android.view.SurfaceHolder)3 CallContact (cx.ring.model.CallContact)3 Conversation (cx.ring.model.Conversation)3 HistoryCall (cx.ring.model.HistoryCall)3 SipCall (cx.ring.model.SipCall)3 Uri (cx.ring.model.Uri)3 IOException (java.io.IOException)3 Camera (android.hardware.Camera)2 StringMap (cx.ring.daemon.StringMap)2 DataTransferEventCode (cx.ring.model.DataTransferEventCode)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Point (android.graphics.Point)1 DataTransferInfo (cx.ring.daemon.DataTransferInfo)1