angular / angular/angularfire

Angularfire and NodeJS firebase chat application by using topics

未关闭
#3,223 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
7.8k
派生
2.2k
平均合并
22 小时 28 分钟
30 天内合并 PR
6

描述

I'm a newbie on the firebase. I'm trying to make a chat application with multiple users and multiple rooms by using `AngularJS` (`angularfire`) for the frontend and `NodeJS` for the backend. I want to send many-to-many notifications. I'll use `topics` for this.

Here are the steps I followed:

1. Register user to firebase (backend-NodeJS)
2. Save user UID to the database (MongoDB)
3. Subscribe this user to the topics (backend-NodeJS)
4. Receive notifications from the topics which user has subscribed (frontend-Angular)

I can listen notifications by using `AngularFireMessaging` module (requesting permission and listening) by using these methods in my app.component.ts:

```typescript
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
constructor( private afMessaging: AngularFireMessaging ) { }

ngOnInit(): void {
this.requestPermission();
this.listen();
}

requestPermission() {
this.afMessaging.requestPermission
.pipe(mergeMapTo(this.afMessaging.tokenChanges))
.subscribe(
(token) => { console.log('Permission granted! Save to the server!', token); },
(error) => { console.error(error); },
);
}

listen() {
console.log('messages are being listened');
this.afMessaging.messages
.subscribe((message) => {
console.log("messages from firebase");
console.log(message);
});
}
}
```

But as I understand this just registers the token and listens it.

I know I can use realtime databases of firebase. But the app is already prepared and we're storing users' UIds in the database. Also chat rooms and users' relations are also stored in the database.

I thought I can send notifications to the `topic`s named as `roomId`s. Then I can listen these topics.

But how can I listen these topics? I have `topic`'s names, I have also users' UIds. How can I listen these topics?

Or am I missing something?

贡献指南

打开贡献指南

调研方向

从 app.component.ts 中的通知流程开始,尤其是 requestPermission() 和 listen(),然后检查 NodeJS 的主题订阅步骤以及 MongoDB 中用户和房间之间的关系。完成的标准是定义现有 Angular 和 NodeJS 应用如何订阅和接收 roomId 主题。

由索引模型根据 Issue 内容生成。

评估

技术栈
angularjs, mongodb, node.js, typescript
领域
backend, databases, frontend
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。