Imagine a chat server persisting the messages, a simplified Slack chat. The domain is designed in the object-orientated style. In order to get realtime updates, we need to transport events emitted on the model constructor ("static" events) and on a model instance ("instance" events).
While it may not be immediately clear, the example is covering few other important LoopBack concepts too:
- authorization (
loopback.token
in REST) - current context (
loopback.context
in REST)
What is not covered:
- file uploads and downloads
Oh cool... so this is using the original remote
on()
method approach. I like how easy this makes creating rooms... Under the hood I'm not sure how we can ensure only events emitted on a model instance will be sent to users who are listening. My current thinking is:The other benefit of using
on()
as a remote method is that you can protect data sent over events by controlling access (ACLs) to theon()
method (which could be a READ operation).Here's what an ACL might look like to secure the data sent over web sockets: