feat: add tokenType and deviceId to push notification packet
Support FCM/VOIP_APNS token types and device identification for improved push notification routing.
This commit is contained in:
@@ -8,14 +8,24 @@ enum class PushNotificationAction(val value: Int) {
|
|||||||
UNSUBSCRIBE(1)
|
UNSUBSCRIBE(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token type for push notifications.
|
||||||
|
*/
|
||||||
|
enum class PushTokenType(val value: Int) {
|
||||||
|
FCM(0),
|
||||||
|
VOIP_APNS(1)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push Notification packet (ID: 0x10)
|
* Push Notification packet (ID: 0x10)
|
||||||
* Отправка FCM/APNS токена на сервер для push-уведомлений (новый формат)
|
* Отправка FCM/APNS токена на сервер для push-уведомлений
|
||||||
* Совместим с React Native версией
|
* Передаёт tokenType (fcm/voip) и deviceId
|
||||||
*/
|
*/
|
||||||
class PacketPushNotification : Packet() {
|
class PacketPushNotification : Packet() {
|
||||||
var notificationsToken: String = ""
|
var notificationsToken: String = ""
|
||||||
var action: PushNotificationAction = PushNotificationAction.SUBSCRIBE
|
var action: PushNotificationAction = PushNotificationAction.SUBSCRIBE
|
||||||
|
var tokenType: PushTokenType = PushTokenType.FCM
|
||||||
|
var deviceId: String = ""
|
||||||
|
|
||||||
override fun getPacketId(): Int = 0x10
|
override fun getPacketId(): Int = 0x10
|
||||||
|
|
||||||
@@ -25,6 +35,11 @@ class PacketPushNotification : Packet() {
|
|||||||
1 -> PushNotificationAction.UNSUBSCRIBE
|
1 -> PushNotificationAction.UNSUBSCRIBE
|
||||||
else -> PushNotificationAction.SUBSCRIBE
|
else -> PushNotificationAction.SUBSCRIBE
|
||||||
}
|
}
|
||||||
|
tokenType = when (stream.readInt8()) {
|
||||||
|
1 -> PushTokenType.VOIP_APNS
|
||||||
|
else -> PushTokenType.FCM
|
||||||
|
}
|
||||||
|
deviceId = stream.readString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun send(): Stream {
|
override fun send(): Stream {
|
||||||
@@ -32,6 +47,8 @@ class PacketPushNotification : Packet() {
|
|||||||
stream.writeInt16(getPacketId())
|
stream.writeInt16(getPacketId())
|
||||||
stream.writeString(notificationsToken)
|
stream.writeString(notificationsToken)
|
||||||
stream.writeInt8(action.value)
|
stream.writeInt8(action.value)
|
||||||
|
stream.writeInt8(tokenType.value)
|
||||||
|
stream.writeString(deviceId)
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -738,9 +738,12 @@ object ProtocolManager {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val deviceId = appContext?.let { getOrCreateDeviceId(it) } ?: ""
|
||||||
val subPacket = PacketPushNotification().apply {
|
val subPacket = PacketPushNotification().apply {
|
||||||
notificationsToken = token
|
notificationsToken = token
|
||||||
action = PushNotificationAction.SUBSCRIBE
|
action = PushNotificationAction.SUBSCRIBE
|
||||||
|
tokenType = PushTokenType.FCM
|
||||||
|
this.deviceId = deviceId
|
||||||
}
|
}
|
||||||
send(subPacket)
|
send(subPacket)
|
||||||
lastSubscribedToken = token
|
lastSubscribedToken = token
|
||||||
|
|||||||
Reference in New Issue
Block a user