我正在使用Firebase的FriendlyChat codelab中的代码在我的网络应用中实现聊天功能。我想发送推送通知,Firebase解释这是可能的。但是,我不断得到“firebase.messaging不是一个功能”,我完全迷失了它的含义。
有没有人碰到这个?有没有人找到解决方案?
我的html脚本初始化firebase:
// Saves the messaging device token to the datastore.
FriendlyChat.prototype.saveMessagingDeviceToken = function() {
firebase.messaging().getToken().then(function(currentToken) {
if (currentToken) {
console.log('Got FCM device token:', currentToken);
// Saving the Device Token to the datastore.
firebase.database().ref('/fcmTokens').child(currentToken)
.set(firebase.auth().currentUser.uid);
} else {
// Need to request permissions to show notifications.
this.requestNotificationsPermissions();
}
}.bind(this)).catch(function(error){
console.error('Unable to get messaging token.', error);
});
};
// Requests permissions to show notifications.
FriendlyChat.prototype.requestNotificationsPermissions = function() {
console.log('Requesting notifications permission...');
firebase.messaging().requestPermission().then(function() {
// Notification permission granted.
this.saveMessagingDeviceToken();
}.bind(this)).catch(function(error) {
console.error('Unable to get permission to notify.', error);
});
};
Messenger.js:
import pandas as pd
groups = pd.DataFrame({'Name': [['Matt','Adam','John','James'], ['Sam','Andrew','John', 'Boss']], 'Job': ['Peon', 'Owner'], 'Group': ['Boss', 'Leader']})
# Build a list of tuples with row to draw group and job from and name
x = [(idx, i) for idx, j in enumerate(groups['Name']) for i in j]
# Search the list for group names, if found resolve group
# names to additional members of row where group was found
for i, j in x:
if j in set(groups.Group):
x.remove((i, j))
for n in list(*list(groups['Name'][groups.Group == j])):
x.append((i, n))
# Create new DataFrame
idx, names = zip(*x)
z = pd.DataFrame(list(names), index=list(idx))
# Join on the old one
groups = groups.drop('Name', axis=1).join(z)