N.live (realtime)
Used to:
- get instant server messages (notifications about updates)
- store small user data without creating new requests every time (scroll positions, activities and so on).
Methods
N.live.emit(channel, data)- sends data into thechannelN.live.debounce(channel, data)- server only. Filer messages via debouncer (3 sec) and send thenN.live.on(channel, handler)- registershandlerto be executed upon messages in thechannelN.live.off(channel [, handler])- unsubscribe handler (or all) from channel
Namespaces
Client side specific things:
local.*- messages will go to local tabs only, and will not pass to server at all.private.*- our internal conventions, for convenience. All posting should be done only here.
Server extensions
Every incoming message (subscribe/post) from client is forwarded to internal methods.
internal.live.subscribe:{channel.name}- check subscribe permissioninternal.live.post:{channel.name}- to handle message from client
Current files location:
.
└─ internal/
└─ <namespace>/
└─ live/
├─ post/*.js
└─ subscribe/*.js
Code example:
N.wire.on('internal.live.subscribe:forum.topic.*', function (data, callback) {
// check permission...
data.allowed = true;
callback();
});
Data object:
- allowed (Boolean) -
falseby default, server handler should check permission and set totrue - message (Object)
- data (Object) - data received from client
- channel (String) - channel name
- getSession (Function) -
function (err, session), session loader helper
Channels examples
private.core.marker.set_scroll- set scroll position in topic and etc.forum.topic.{topic_hid}- topic updatesforum.section.{section_hid}- section updates