|
@@ -5,25 +5,25 @@ import admin from "firebase-admin";
|
|
|
export function initializeFirebase() {
|
|
export function initializeFirebase() {
|
|
|
admin.initializeApp({
|
|
admin.initializeApp({
|
|
|
credential: admin.credential.cert(config),
|
|
credential: admin.credential.cert(config),
|
|
|
- databaseURL: "https://maa-client.firebaseio.com"
|
|
|
|
|
|
|
+ databaseURL: "https://maa-client.firebaseio.com",
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function sendUpdateRequest() {
|
|
export function sendUpdateRequest() {
|
|
|
var message: admin.messaging.Message = {
|
|
var message: admin.messaging.Message = {
|
|
|
data: {
|
|
data: {
|
|
|
- type: "update request"
|
|
|
|
|
|
|
+ type: "update request",
|
|
|
},
|
|
},
|
|
|
- topic: "maa"
|
|
|
|
|
|
|
+ topic: "maa",
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
admin
|
|
admin
|
|
|
.messaging()
|
|
.messaging()
|
|
|
.send(message)
|
|
.send(message)
|
|
|
- .then(response => {
|
|
|
|
|
|
|
+ .then((response) => {
|
|
|
console.log("Message sent", response);
|
|
console.log("Message sent", response);
|
|
|
})
|
|
})
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ .catch((error) => {
|
|
|
console.log("Message error ", error);
|
|
console.log("Message error ", error);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -32,22 +32,25 @@ export function sendAlarm(equipmentName: string, alarmType: string) {
|
|
|
var message: admin.messaging.Message = {
|
|
var message: admin.messaging.Message = {
|
|
|
data: {
|
|
data: {
|
|
|
name: equipmentName,
|
|
name: equipmentName,
|
|
|
- type: alarmType
|
|
|
|
|
|
|
+ type: alarmType,
|
|
|
},
|
|
},
|
|
|
android: {
|
|
android: {
|
|
|
priority: "high",
|
|
priority: "high",
|
|
|
- ttl: 0
|
|
|
|
|
|
|
+ ttl: 0,
|
|
|
|
|
+ },
|
|
|
|
|
+ topic: "maa",
|
|
|
|
|
+ fcmOptions: {
|
|
|
|
|
+ analyticsLabel: "Alarm",
|
|
|
},
|
|
},
|
|
|
- topic: "maa"
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
admin
|
|
admin
|
|
|
.messaging()
|
|
.messaging()
|
|
|
.send(message)
|
|
.send(message)
|
|
|
- .then(response => {
|
|
|
|
|
|
|
+ .then((response) => {
|
|
|
console.log("Message sent", response);
|
|
console.log("Message sent", response);
|
|
|
})
|
|
})
|
|
|
- .catch(error => {
|
|
|
|
|
|
|
+ .catch((error) => {
|
|
|
console.log("Message error ", error);
|
|
console.log("Message error ", error);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|