1
1
"use strict" ;
2
2
3
- const Parse = require ( 'parse/node' ) . Parse ;
4
3
// TODO: apn does not support the new HTTP/2 protocal. It is fine to use it in V1,
5
4
// but probably we will replace it in the future.
6
- const apn = require ( 'apn' ) ;
5
+ import apn from 'apn' ;
6
+ import Parse from 'parse' ;
7
+ import log from 'npmlog' ;
8
+
9
+ const LOG_PREFIX = 'parse-server-push-adapter APNS' ;
7
10
8
11
/**
9
12
* Create a new connection to the APN service.
@@ -46,23 +49,23 @@ function APNS(args) {
46
49
47
50
// Set apns client callbacks
48
51
conn . on ( 'connected' , ( ) => {
49
- console . log ( 'APNS Connection %d Connected' , conn . index ) ;
52
+ log . verbose ( LOG_PREFIX , 'APNS Connection %d Connected' , conn . index ) ;
50
53
} ) ;
51
54
52
55
conn . on ( 'transmissionError' , ( errCode , notification , apnDevice ) => {
53
56
handleTransmissionError ( this . conns , errCode , notification , apnDevice ) ;
54
57
} ) ;
55
58
56
59
conn . on ( 'timeout' , ( ) => {
57
- console . log ( 'APNS Connection %d Timeout' , conn . index ) ;
60
+ log . verbose ( LOG_PREFIX , 'APNS Connection %d Timeout' , conn . index ) ;
58
61
} ) ;
59
62
60
63
conn . on ( 'disconnected' , ( ) => {
61
- console . log ( 'APNS Connection %d Disconnected' , conn . index ) ;
64
+ log . verbose ( LOG_PREFIX , 'APNS Connection %d Disconnected' , conn . index ) ;
62
65
} ) ;
63
66
64
67
conn . on ( 'socketError' , ( ) => {
65
- console . log ( 'APNS Connection %d Socket Error' , conn . index ) ;
68
+ log . verbose ( LOG_PREFIX , 'APNS Connection %d Socket Error' , conn . index ) ;
66
69
} ) ;
67
70
68
71
conn . on ( 'transmitted' , function ( notification , device ) {
@@ -76,7 +79,7 @@ function APNS(args) {
76
79
}
77
80
} ) ;
78
81
}
79
- console . log ( 'APNS Connection %d Notification transmitted to %s' , conn . index , device . token . toString ( 'hex' ) ) ;
82
+ log . verbose ( LOG_PREFIX , 'APNS Connection %d Notification transmitted to %s' , conn . index , device . token . toString ( 'hex' ) ) ;
80
83
} ) ;
81
84
82
85
this . conns . push ( conn ) ;
@@ -106,6 +109,7 @@ APNS.prototype.send = function(data, devices) {
106
109
let qualifiedConnIndexs = chooseConns ( this . conns , device ) ;
107
110
// We can not find a valid conn, just ignore this device
108
111
if ( qualifiedConnIndexs . length == 0 ) {
112
+ log . error ( LOG_PREFIX , 'no qualified connections for %s %s' , device . appIdentifier , device . deviceToken ) ;
109
113
return Promise . resolve ( {
110
114
transmitted : false ,
111
115
device : {
@@ -154,6 +158,7 @@ function handleTransmissionError(conns, errCode, notification, apnDevice) {
154
158
// There is no more available conns, we give up in this case
155
159
if ( newConnIndex < 0 || newConnIndex >= conns . length ) {
156
160
if ( apnDevice . callback ) {
161
+ log . error ( LOG_PREFIX , `cannot find vaild connection for ${ apnDevice . token . toString ( 'hex' ) } ` ) ;
157
162
apnDevice . callback ( {
158
163
response : { error : `APNS can not find vaild connection for ${ apnDevice . token . toString ( 'hex' ) } ` , code : errCode } ,
159
164
status : errCode ,
0 commit comments