我正在开发一个使用 node.js 和 angular js 的 Twilio 可编程聊天 API 的应用程序。我在 twilio 聊天实例中启用了推送配置。我已经使用 firebase 密钥在 twilio 中创建了推送凭证。在此之后,我使用带有 twilio 凭证 sid 的 chatGrant 获取了 twilio 令牌。我已经包含了 firebase.js 文件并初始化了 firebase。在此之后,我获得了用户的许可以显示通知。这一切都很好。但是当我试图让设备令牌注册到 chatclientinstance 时,它会失败。这是我初始化firebase并获得许可的代码,
var config = {
apiKey: "my_key",
authDomain: "example.firebaseapp.com",
databaseURL: "https://example.firebaseio.com",
projectId: "example",
storageBucket: "example.appspot.com",
messagingSenderId: "861813283864"
};
if (firebase) {
firebase.initializeApp(config);
console.log("firbase initialized.");
}
if (firebase && firebase.messaging()) {
// requesting permission to use push notifications
firebase.messaging().requestPermission().then(() => {
// getting FCM token
console.log("got permission for showing notification.");
firebase.messaging().getToken().then((fcmToken) => {
// continue with Step 7 here
console.log("got fcm token.",fcmToken);
// ...
// ...
}).catch((err) => {
// can't get token
console.log("error in getting token for notification.",err);
});
}).catch((err) => {
// can't request permission or permission hasn't been granted to the web app by the user
console.log("error in getting permission for notification.",err);
});
} else {
// no Firebase library imported or Firebase library wasn't correctly initialized
console.log("no Firebase library imported or Firebase library wasn't correctly initialized");
}
}
我在控制台中得到了这个,
firbase initialized.
got permission for showing notification.
The script has an unsupported MIME type ('text/html').
Failed to load resource: net::ERR_INSECURE_RESPONSE firebase-messaging-sw.js
error in getting token for notification.
e {code: "messaging/failed-serviceworker-registration", message: "Messaging: We are unable to register the default s…). (messaging/failed-serviceworker-registration).", browserErrorMessage: "Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html').", stack: "FirebaseError: Messaging: We are unable to registe…o/polyfills.bundle.js:3152:35)↵ at <anonymous>"}
正如 twilio docs 在PUSH NOTIFICATIONS ON WEB上所说的那样,我已经做了所有事情
但是我没有在我的服务器中添加“firebase-messaging-sw.js”。是否需要添加此 js 文件或 twilio 会自动创建并初始化它?
请为我找到解决方案。提前致谢。