Cómo enviar y recibir eventos efímeros
Product deprecation notice
Effective April 30th, 2026, Vonage In-App Messaging will no longer be available. Access for new users will be closed, and the service will be discontinued for all existing users.
If you have any questions regarding this product’s discontinuation, please contact your account manager or our support team.
Esta guía explica cómo enviar y recibir eventos efímeros con el Vonage Client SDK. Antes de comenzar, asegúrate de haber agregado el SDK a tu aplicación, creado una sesión (Android, iOS, JS), y se unió a una conversación.
Los Eventos efímeros son Eventos de corta duración que se entregan a todos los App Miembros en una conversación. No se almacenan en la Conversación a diferencia de Eventos personalizados. Por lo tanto, cuando se obtiene un Eventos de Conversación no se devolverán.
Los Eventos Efímeros son los más adecuados para implementar Eventos Personalizados recurrentes, como los indicadores de tecleo.
Envío de eventos efímeros
Dado un ID de Conversación, puedes enviar un Evento Efímero. Se recomienda utilizar un JSON para los datos personalizados e incluir un parámetro de tipo, p. ej. type: 'ephemeral:typingStart'.
const typingStartEvent = {
member: memberId,
type: "typing:start"
};
client.sendEphemeralEvent(conversationId, typingStartEvent)
.then(timestamp => {
console.log("Successfully sent ephemeral event at ", timestamp);
}).catch(error => {
console.error("Error sending ephemeral event: ", error);
});
client.sendEphemeralEvent("CONV_ID", "MY_CUSTOM_BODY") { error, timestamp ->
error?.takeIf { it is VGError }?.let {/* Handle Vonage Error */ } ?:
error?.let {/* Handle generic Error */ }
timestamp?.let { /* event sent at timestamp */ }
}
client.sendEphemeralEvent("CONV_ID", customBody: "MY_CUSTOM_BODY") { error, timestamp in
...
}
Recepción de eventos efímeros
Puede recibir todos los Eventos de Conversación en su aplicación configurando una Función de Receptor/Delegado de Eventos. Aquí puede comprobar el tipo de Evento entrante.
client.on("conversationEvent", event => {
switch (event.kind) {
case "ephemeral":
handleEphemeralEvent(event);
break;
};
});
client.setOnConversationEventListener {
when(it) {
is EphemeralConversationEvent -> {}
}
}
func chatClient(_ client: VGChatClient, didReceiveConversationEvent event: VGConversationEvent) {
switch event.kind {
case .ephemeral:
// Handle Ephemeral Event
let ephemeralEvent = event as! VGEphemeralConversationEvent
...
}
}