Search in sources :

Example 11 with IceUpdateMessage

use of org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage in project Signal-Android by WhisperSystems.

the class SignalServiceMessageSender method createCallContent.

private Content createCallContent(SignalServiceCallMessage callMessage) {
    Content.Builder container = Content.newBuilder();
    CallMessage.Builder builder = CallMessage.newBuilder();
    if (callMessage.getOfferMessage().isPresent()) {
        OfferMessage offer = callMessage.getOfferMessage().get();
        CallMessage.Offer.Builder offerBuilder = CallMessage.Offer.newBuilder().setId(offer.getId()).setType(offer.getType().getProtoType());
        if (offer.getOpaque() != null) {
            offerBuilder.setOpaque(ByteString.copyFrom(offer.getOpaque()));
        }
        if (offer.getSdp() != null) {
            offerBuilder.setSdp(offer.getSdp());
        }
        builder.setOffer(offerBuilder);
    } else if (callMessage.getAnswerMessage().isPresent()) {
        AnswerMessage answer = callMessage.getAnswerMessage().get();
        CallMessage.Answer.Builder answerBuilder = CallMessage.Answer.newBuilder().setId(answer.getId());
        if (answer.getOpaque() != null) {
            answerBuilder.setOpaque(ByteString.copyFrom(answer.getOpaque()));
        }
        if (answer.getSdp() != null) {
            answerBuilder.setSdp(answer.getSdp());
        }
        builder.setAnswer(answerBuilder);
    } else if (callMessage.getIceUpdateMessages().isPresent()) {
        List<IceUpdateMessage> updates = callMessage.getIceUpdateMessages().get();
        for (IceUpdateMessage update : updates) {
            CallMessage.IceUpdate.Builder iceBuilder = CallMessage.IceUpdate.newBuilder().setId(update.getId()).setMid("audio").setLine(0);
            if (update.getOpaque() != null) {
                iceBuilder.setOpaque(ByteString.copyFrom(update.getOpaque()));
            }
            if (update.getSdp() != null) {
                iceBuilder.setSdp(update.getSdp());
            }
            builder.addIceUpdate(iceBuilder);
        }
    } else if (callMessage.getHangupMessage().isPresent()) {
        CallMessage.Hangup.Type protoType = callMessage.getHangupMessage().get().getType().getProtoType();
        CallMessage.Hangup.Builder builderForHangup = CallMessage.Hangup.newBuilder().setType(protoType).setId(callMessage.getHangupMessage().get().getId());
        if (protoType != CallMessage.Hangup.Type.HANGUP_NORMAL) {
            builderForHangup.setDeviceId(callMessage.getHangupMessage().get().getDeviceId());
        }
        if (callMessage.getHangupMessage().get().isLegacy()) {
            builder.setLegacyHangup(builderForHangup);
        } else {
            builder.setHangup(builderForHangup);
        }
    } else if (callMessage.getBusyMessage().isPresent()) {
        builder.setBusy(CallMessage.Busy.newBuilder().setId(callMessage.getBusyMessage().get().getId()));
    } else if (callMessage.getOpaqueMessage().isPresent()) {
        OpaqueMessage opaqueMessage = callMessage.getOpaqueMessage().get();
        ByteString data = ByteString.copyFrom(opaqueMessage.getOpaque());
        CallMessage.Opaque.Urgency urgency = opaqueMessage.getUrgency().toProto();
        builder.setOpaque(CallMessage.Opaque.newBuilder().setData(data).setUrgency(urgency));
    }
    builder.setMultiRing(callMessage.isMultiRing());
    if (callMessage.getDestinationDeviceId().isPresent()) {
        builder.setDestinationDeviceId(callMessage.getDestinationDeviceId().get());
    }
    container.setCallMessage(builder);
    return container.build();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) CallMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.CallMessage) ByteString(com.google.protobuf.ByteString) SignalGroupSessionBuilder(org.whispersystems.signalservice.api.crypto.SignalGroupSessionBuilder) GroupSessionBuilder(org.whispersystems.libsignal.groups.GroupSessionBuilder) SessionBuilder(org.whispersystems.libsignal.SessionBuilder) SignalSessionBuilder(org.whispersystems.signalservice.api.crypto.SignalSessionBuilder) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Example 12 with IceUpdateMessage

use of org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage in project Signal-Android by signalapp.

the class SignalServiceMessageSender method createCallContent.

private Content createCallContent(SignalServiceCallMessage callMessage) {
    Content.Builder container = Content.newBuilder();
    CallMessage.Builder builder = CallMessage.newBuilder();
    if (callMessage.getOfferMessage().isPresent()) {
        OfferMessage offer = callMessage.getOfferMessage().get();
        CallMessage.Offer.Builder offerBuilder = CallMessage.Offer.newBuilder().setId(offer.getId()).setType(offer.getType().getProtoType());
        if (offer.getOpaque() != null) {
            offerBuilder.setOpaque(ByteString.copyFrom(offer.getOpaque()));
        }
        if (offer.getSdp() != null) {
            offerBuilder.setSdp(offer.getSdp());
        }
        builder.setOffer(offerBuilder);
    } else if (callMessage.getAnswerMessage().isPresent()) {
        AnswerMessage answer = callMessage.getAnswerMessage().get();
        CallMessage.Answer.Builder answerBuilder = CallMessage.Answer.newBuilder().setId(answer.getId());
        if (answer.getOpaque() != null) {
            answerBuilder.setOpaque(ByteString.copyFrom(answer.getOpaque()));
        }
        if (answer.getSdp() != null) {
            answerBuilder.setSdp(answer.getSdp());
        }
        builder.setAnswer(answerBuilder);
    } else if (callMessage.getIceUpdateMessages().isPresent()) {
        List<IceUpdateMessage> updates = callMessage.getIceUpdateMessages().get();
        for (IceUpdateMessage update : updates) {
            CallMessage.IceUpdate.Builder iceBuilder = CallMessage.IceUpdate.newBuilder().setId(update.getId()).setMid("audio").setLine(0);
            if (update.getOpaque() != null) {
                iceBuilder.setOpaque(ByteString.copyFrom(update.getOpaque()));
            }
            if (update.getSdp() != null) {
                iceBuilder.setSdp(update.getSdp());
            }
            builder.addIceUpdate(iceBuilder);
        }
    } else if (callMessage.getHangupMessage().isPresent()) {
        CallMessage.Hangup.Type protoType = callMessage.getHangupMessage().get().getType().getProtoType();
        CallMessage.Hangup.Builder builderForHangup = CallMessage.Hangup.newBuilder().setType(protoType).setId(callMessage.getHangupMessage().get().getId());
        if (protoType != CallMessage.Hangup.Type.HANGUP_NORMAL) {
            builderForHangup.setDeviceId(callMessage.getHangupMessage().get().getDeviceId());
        }
        if (callMessage.getHangupMessage().get().isLegacy()) {
            builder.setLegacyHangup(builderForHangup);
        } else {
            builder.setHangup(builderForHangup);
        }
    } else if (callMessage.getBusyMessage().isPresent()) {
        builder.setBusy(CallMessage.Busy.newBuilder().setId(callMessage.getBusyMessage().get().getId()));
    } else if (callMessage.getOpaqueMessage().isPresent()) {
        OpaqueMessage opaqueMessage = callMessage.getOpaqueMessage().get();
        ByteString data = ByteString.copyFrom(opaqueMessage.getOpaque());
        CallMessage.Opaque.Urgency urgency = opaqueMessage.getUrgency().toProto();
        builder.setOpaque(CallMessage.Opaque.newBuilder().setData(data).setUrgency(urgency));
    }
    builder.setMultiRing(callMessage.isMultiRing());
    if (callMessage.getDestinationDeviceId().isPresent()) {
        builder.setDestinationDeviceId(callMessage.getDestinationDeviceId().get());
    }
    container.setCallMessage(builder);
    return container.build();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) CallMessage(org.whispersystems.signalservice.internal.push.SignalServiceProtos.CallMessage) ByteString(com.google.protobuf.ByteString) SignalGroupSessionBuilder(org.whispersystems.signalservice.api.crypto.SignalGroupSessionBuilder) GroupSessionBuilder(org.whispersystems.libsignal.groups.GroupSessionBuilder) SessionBuilder(org.whispersystems.libsignal.SessionBuilder) SignalSessionBuilder(org.whispersystems.signalservice.api.crypto.SignalSessionBuilder) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) EnvelopeContent(org.whispersystems.signalservice.api.crypto.EnvelopeContent) PlaintextContent(org.whispersystems.libsignal.protocol.PlaintextContent) Content(org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Example 13 with IceUpdateMessage

use of org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage in project Signal-Android by signalapp.

the class SignalServiceContent method createCallMessage.

private static SignalServiceCallMessage createCallMessage(SignalServiceProtos.CallMessage content) {
    boolean isMultiRing = content.getMultiRing();
    Integer destinationDeviceId = content.hasDestinationDeviceId() ? content.getDestinationDeviceId() : null;
    if (content.hasOffer()) {
        SignalServiceProtos.CallMessage.Offer offerContent = content.getOffer();
        return SignalServiceCallMessage.forOffer(new OfferMessage(offerContent.getId(), offerContent.hasSdp() ? offerContent.getSdp() : null, OfferMessage.Type.fromProto(offerContent.getType()), offerContent.hasOpaque() ? offerContent.getOpaque().toByteArray() : null), isMultiRing, destinationDeviceId);
    } else if (content.hasAnswer()) {
        SignalServiceProtos.CallMessage.Answer answerContent = content.getAnswer();
        return SignalServiceCallMessage.forAnswer(new AnswerMessage(answerContent.getId(), answerContent.hasSdp() ? answerContent.getSdp() : null, answerContent.hasOpaque() ? answerContent.getOpaque().toByteArray() : null), isMultiRing, destinationDeviceId);
    } else if (content.getIceUpdateCount() > 0) {
        List<IceUpdateMessage> iceUpdates = new LinkedList<>();
        for (SignalServiceProtos.CallMessage.IceUpdate iceUpdate : content.getIceUpdateList()) {
            iceUpdates.add(new IceUpdateMessage(iceUpdate.getId(), iceUpdate.hasOpaque() ? iceUpdate.getOpaque().toByteArray() : null, iceUpdate.hasSdp() ? iceUpdate.getSdp() : null));
        }
        return SignalServiceCallMessage.forIceUpdates(iceUpdates, isMultiRing, destinationDeviceId);
    } else if (content.hasLegacyHangup()) {
        SignalServiceProtos.CallMessage.Hangup hangup = content.getLegacyHangup();
        return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId(), HangupMessage.Type.fromProto(hangup.getType()), hangup.getDeviceId(), content.hasLegacyHangup()), isMultiRing, destinationDeviceId);
    } else if (content.hasHangup()) {
        SignalServiceProtos.CallMessage.Hangup hangup = content.getHangup();
        return SignalServiceCallMessage.forHangup(new HangupMessage(hangup.getId(), HangupMessage.Type.fromProto(hangup.getType()), hangup.getDeviceId(), content.hasLegacyHangup()), isMultiRing, destinationDeviceId);
    } else if (content.hasBusy()) {
        SignalServiceProtos.CallMessage.Busy busy = content.getBusy();
        return SignalServiceCallMessage.forBusy(new BusyMessage(busy.getId()), isMultiRing, destinationDeviceId);
    } else if (content.hasOpaque()) {
        SignalServiceProtos.CallMessage.Opaque opaque = content.getOpaque();
        return SignalServiceCallMessage.forOpaque(new OpaqueMessage(opaque.getData().toByteArray(), null), isMultiRing, destinationDeviceId);
    }
    return SignalServiceCallMessage.empty();
}
Also used : IceUpdateMessage(org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage) SignalServiceCallMessage(org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage) AnswerMessage(org.whispersystems.signalservice.api.messages.calls.AnswerMessage) LinkedList(java.util.LinkedList) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) HangupMessage(org.whispersystems.signalservice.api.messages.calls.HangupMessage) OfferMessage(org.whispersystems.signalservice.api.messages.calls.OfferMessage) BusyMessage(org.whispersystems.signalservice.api.messages.calls.BusyMessage) OpaqueMessage(org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)

Aggregations

IceUpdateMessage (org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage)13 AnswerMessage (org.whispersystems.signalservice.api.messages.calls.AnswerMessage)7 OfferMessage (org.whispersystems.signalservice.api.messages.calls.OfferMessage)7 SignalServiceCallMessage (org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage)7 CallId (org.signal.ringrtc.CallId)4 BusyMessage (org.whispersystems.signalservice.api.messages.calls.BusyMessage)4 HangupMessage (org.whispersystems.signalservice.api.messages.calls.HangupMessage)4 RemotePeer (org.thoughtcrime.securesms.ringrtc.RemotePeer)3 OpaqueMessage (org.whispersystems.signalservice.api.messages.calls.OpaqueMessage)3 Context (android.content.Context)2 Intent (android.content.Intent)2 ResultReceiver (android.os.ResultReceiver)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 Stream (com.annimon.stream.Stream)2 ByteString (com.google.protobuf.ByteString)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2