mirror of
https://github.com/aljazceru/signal-cli.git
synced 2026-01-17 12:44:25 +01:00
61 lines
2.2 KiB
Java
61 lines
2.2 KiB
Java
package org.asamk.signal.json;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
|
import org.asamk.signal.manager.api.MessageEnvelope;
|
|
|
|
import java.util.Base64;
|
|
import java.util.List;
|
|
|
|
record JsonCallMessage(
|
|
@JsonInclude(JsonInclude.Include.NON_NULL) Offer offerMessage,
|
|
@JsonInclude(JsonInclude.Include.NON_NULL) Answer answerMessage,
|
|
@JsonInclude(JsonInclude.Include.NON_NULL) Busy busyMessage,
|
|
@JsonInclude(JsonInclude.Include.NON_NULL) Hangup hangupMessage,
|
|
@JsonInclude(JsonInclude.Include.NON_EMPTY) List<IceUpdate> iceUpdateMessages
|
|
) {
|
|
|
|
static JsonCallMessage from(MessageEnvelope.Call callMessage) {
|
|
return new JsonCallMessage(callMessage.offer().map(Offer::from).orElse(null),
|
|
callMessage.answer().map(Answer::from).orElse(null),
|
|
callMessage.busy().map(Busy::from).orElse(null),
|
|
callMessage.hangup().map(Hangup::from).orElse(null),
|
|
callMessage.iceUpdate().stream().map(IceUpdate::from).toList());
|
|
}
|
|
|
|
record Offer(long id, String type, String opaque) {
|
|
|
|
public static Offer from(final MessageEnvelope.Call.Offer offer) {
|
|
return new Offer(offer.id(), offer.type().name(), Base64.getEncoder().encodeToString(offer.opaque()));
|
|
}
|
|
}
|
|
|
|
public record Answer(long id, String opaque) {
|
|
|
|
public static Answer from(final MessageEnvelope.Call.Answer answer) {
|
|
return new Answer(answer.id(), Base64.getEncoder().encodeToString(answer.opaque()));
|
|
}
|
|
}
|
|
|
|
public record Busy(long id) {
|
|
|
|
public static Busy from(final MessageEnvelope.Call.Busy busy) {
|
|
return new Busy(busy.id());
|
|
}
|
|
}
|
|
|
|
public record Hangup(long id, String type, int deviceId) {
|
|
|
|
public static Hangup from(final MessageEnvelope.Call.Hangup hangup) {
|
|
return new Hangup(hangup.id(), hangup.type().name(), hangup.deviceId());
|
|
}
|
|
}
|
|
|
|
public record IceUpdate(long id, String opaque) {
|
|
|
|
public static IceUpdate from(final MessageEnvelope.Call.IceUpdate iceUpdate) {
|
|
return new IceUpdate(iceUpdate.id(), Base64.getEncoder().encodeToString(iceUpdate.opaque()));
|
|
}
|
|
}
|
|
}
|