So I have a place in my current project where I am initializing an APN (Apple Push Notification) connection but I need to initialize it one as I do not need more than a single instance of the connection. Currently I have a class that creates the connection and puts our needed listeners on the connection to watch for errors and such. It looks something like this:
export default class pushService {
constructor(options) {
... check that options is proper ...
this.apnConnection = apn.Provider(options);
... add listeners ...
}
sendMessage(message, recipents) {
this.apnConnection.send() messages
}
}
Now there are potentially multiple locations where this will need to be used, but as I said I'd prefer to have only one connected instance of the APN connection for the whole of the application.
So, is it best to initialize this in the main file of the application and make it a named export, or should it be initiated in some other way? I don't think importing the whole main application file is a great idea if it can be avoided, but maybe there is no issue in doing so?
Also if this is too subjective I am sorry, but this is something I don't think I've seen asked here yet nor answered in my Google searching, and it seems like something that may have one or more good solutions.