I'm looking into converting some basic JS to Kotlin but I'm stuck on the new keyword. I'm not sure how to convert the following JS to Kotlin
var FCM = require('fcm-node');
var fcm = new FCM('YOURSERVERKEYHERE');
var message = { ... };
fcm.send(message, function(err, response){ ... }
I tried
fun sendTestPush() {
val FCM = require("fcm-push")
val fcm = new FCM("YOURSERVERKEYHERE")
val data = Data("Title", "Message")
val message = Message("registration_id", data)
fcm.send(message)
}
data class Message(val to: String, val data: Data)
data class Data(val title: String, val message: String)
I get the compile error Unresolved reference: new as Kotlin doesn't have it.
Without the 'new' I get the expected error Attempting to TypeError: Cannot read property 'send' of undefined
Any idea to get around this problem?
Edit: FCM class is the npm package https://www.npmjs.com/package/fcm-push