mirror of
https://github.com/cheveguerra/Pusher_2.0.git
synced 2026-04-19 04:09:20 +00:00
Initial commit
This commit is contained in:
84
FirebaseMessaging.bas
Normal file
84
FirebaseMessaging.bas
Normal file
@@ -0,0 +1,84 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Service
|
||||
Version=10.5
|
||||
@EndOfDesignText@
|
||||
Sub Process_Globals
|
||||
Private fm As FirebaseMessaging
|
||||
End Sub
|
||||
|
||||
Sub Service_Create
|
||||
fm.Initialize("fm")
|
||||
End Sub
|
||||
|
||||
Public Sub SubscribeToTopics
|
||||
fm.SubscribeToTopic("Trckr") 'Global (you can subscribe to more topics)
|
||||
fm.SubscribeToTopic("Sprvsr")
|
||||
fm.SubscribeToTopic("Sprv-ML")
|
||||
fm.SubscribeToTopic("Sprv-This")
|
||||
fm.SubscribeToTopic("Sprv-Cedex")
|
||||
fm.SubscribeToTopic("Sprv-GunaReparto")
|
||||
fm.SubscribeToTopic("Sprv-Durakelo")
|
||||
' Log(fm.token)
|
||||
End Sub
|
||||
|
||||
Sub Service_Start (StartingIntent As Intent)
|
||||
If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
|
||||
'Sleep(0)
|
||||
'Service.StopAutomaticForeground 'remove if not using B4A v8+.
|
||||
End Sub
|
||||
|
||||
Sub fm_MessageArrived (Message As RemoteMessage)
|
||||
Log("Mensaje recibido")
|
||||
Log($"Message data: ${Message.GetData}"$)
|
||||
|
||||
'Si recibimos Pong, lo agregamos a la lista de dispositivos activos
|
||||
If Message.GetData.ContainsKey("t") And Message.GetData.Get("t") = "pong" Then
|
||||
Log("Recibimos pong "&Message.GetData.Get("d"))
|
||||
If Main.dispositivos.ContainsKey(Message.GetData.Get("d")) Then
|
||||
Dim dMap As Map = Main.dispositivos.Get(Message.GetData.Get("d"))
|
||||
Dim dispData As Map = dMap
|
||||
Else
|
||||
Dim dispData As Map = CreateMap("coords": "0,0", "d": Message.GetData.Get("d"),"v": Message.GetData.Get("v"), "w": Message.GetData.Get("w"))
|
||||
End If
|
||||
Log("** "&dispData)
|
||||
Main.dispositivos.Put(Message.GetData.Get("d"), dispData)
|
||||
End If
|
||||
|
||||
'Si el mensaje es de ubicacion recibida
|
||||
If Message.GetData.ContainsKey("t") And (Message.GetData.Get("t") = "u" Or Message.GetData.Get("t") = "au") Then
|
||||
Log("Recibimos ubicacion")
|
||||
Log("Llamamos UbicacionRecibida")
|
||||
If Message.GetData.Get("t") = "au" Then ToastMessageShow("Ubicacion recibida:"&Message.GetData.Get("d"),False)
|
||||
CallSub2(Main, "ubicacionRecibida", Message.GetData)
|
||||
End If
|
||||
|
||||
'Si el mensaje es de ruta gps recibida
|
||||
If Message.GetData.ContainsKey("t") And Message.GetData.Get("t") = "ruta" Then
|
||||
Log("Recibimos Ruta GPS")
|
||||
If Message.GetData.ContainsKey("r") Then
|
||||
Log("Tenemos Ruta")
|
||||
Main.base64=Message.GetData.Get("r")
|
||||
descomprimeRuta
|
||||
' ToastMessageShow("Ruta Recibida: "&Message.GetData.Get("d"),False)
|
||||
Main.rRuta = Message.GetData.Get("d")
|
||||
CallSub(Main, "muestraRuta")
|
||||
End If
|
||||
End If
|
||||
CallSub(Main,"agregaAListview")
|
||||
End Sub
|
||||
|
||||
Sub Service_Destroy
|
||||
|
||||
End Sub
|
||||
|
||||
Sub descomprimeRuta
|
||||
Dim su As StringUtils
|
||||
Dim decompressedbytes() As Byte = su.DecodeBase64(Main.base64)
|
||||
Log($"decompressedbytesLength: ${decompressedbytes.Length}"$)
|
||||
Dim bc As ByteConverter
|
||||
Main.rutaGPS = bc.StringFromBytes(decompressedbytes,"UTF8")
|
||||
Log($"uncompressedLength: ${Main.rutaGPS.Length}"$)
|
||||
' Log($"Decompressed String = ${Main.rutaGPS}"$)
|
||||
End Sub
|
||||
Reference in New Issue
Block a user