Context

Context

new Context(options, socket, event, data) → {Context}

constructor

Parameters:
Name Type Description
options Object
socket Socket
event Event
data
Source:
Returns:
Type
Context
Examples
// ctx.on('before-result', callback)
//`before-result` event fire before emit result (success or not);
// You may pass function return promise as callback.
ctx.on('prepesult', (ctx) => {
    return new Promise((resolve) => {
        ctx.result.data = 'my data';
        setTimeout(resolve, 200);
    });
});
// ctx.on('result', callback)
// `result` event fire after emit result (success or not)
ctx.on('result', (ctx) => {
    console.log(\`send result ${ctx.event.name}\`, ctx.result);
});

Methods

broadcast(path, data) → {undefined}

broadcast - broadcast message with prefix ${requestName}:${path}

Parameters:
Name Type Description
path String
data
Source:
Returns:
Type
undefined

emit(path, data) → {undefined}

emit - emit message with prefix ${uuid}:${requestName}:${path}

Parameters:
Name Type Description
path String
data
Source:
Returns:
Type
undefined

error(data) → {undefined}

error - error callback. Should call once.

Parameters:
Name Type Description
data
Source:
Returns:
Type
undefined

success(data) → {undefined}

success - success callback. Should call once.

Parameters:
Name Type Description
data
Source:
Returns:
Type
undefined

to(roomName) → {object}

to - broadcast message to spicific room

Parameters:
Name Type Description
roomName String
Source:
Returns:
Type
object