var params = {'PlatformApplicationArn':platformApplicationArn,'Token': token};
sns.createPlatformEndpoint(params,function(err,EndPointResult)
{
if(EndPointResult != null){
var clientArn = EndPointResult["EndpointArn"];
sns.publish(
{
TargetArn: clientArn,
Message: JSON.stringify(clientMessage),
Subject: JSON.stringify(subject),
MessageStructure: 'json'
},
function(err,data){
if (err) {
console.log("Error sending a message "+err+JSON.stringify(params.Token));
if(err == "EndpointDisabled: Endpoint is disabled"){
sns.deleteEndpoint({'EndpointArn': clientArn}, function(err, data) {
if (err) console.log("Error removing Endpoint Arn: "+err);
});
message.deleteMessage(function(err, data) {
if(err){
console.log("Error deleting message: "+err);
}
message.next();
});
}
message.next();
} else {
var messagedate = new Date();
console.log("Sent message: "+data.MessageId+messagedate+JSON.stringify(params));
sns.deleteEndpoint({'EndpointArn': clientArn}, function(err, data) {
if (err) console.log("Error removing Endpoint Arn: "+err);
});
message.deleteMessage(function(err, data) {
if(err){
console.log("Error deleting message: "+err);
}
message.next();
});
}
}
);
}
if(EndPointResult == null){
message.next();
}
});
sns.createPlatformEndpoint(params,function(err,EndPointResult)
{
if(EndPointResult != null){
var clientArn = EndPointResult["EndpointArn"];
sns.publish(
{
TargetArn: clientArn,
Message: JSON.stringify(clientMessage),
Subject: JSON.stringify(subject),
MessageStructure: 'json'
},
function(err,data){
if (err) {
console.log("Error sending a message "+err+JSON.stringify(params.Token));
if(err == "EndpointDisabled: Endpoint is disabled"){
sns.deleteEndpoint({'EndpointArn': clientArn}, function(err, data) {
if (err) console.log("Error removing Endpoint Arn: "+err);
});
message.deleteMessage(function(err, data) {
if(err){
console.log("Error deleting message: "+err);
}
message.next();
});
}
message.next();
} else {
var messagedate = new Date();
console.log("Sent message: "+data.MessageId+messagedate+JSON.stringify(params));
sns.deleteEndpoint({'EndpointArn': clientArn}, function(err, data) {
if (err) console.log("Error removing Endpoint Arn: "+err);
});
message.deleteMessage(function(err, data) {
if(err){
console.log("Error deleting message: "+err);
}
message.next();
});
}
}
);
}
if(EndPointResult == null){
message.next();
}
});
No comments:
Post a Comment