@pitaj Thank you for your fast response.
Could you give mit a litte example how to emit and receive messages? I'm new to javascript and also new to nodebb. It is hard for me to follow the programming language especially in plugin dev.
I have this in socket.io documentation
socket.on('chat message', (msg) => {
console.log('message: ' + msg);
});
something comeplete different ....
than
pluginSockets.calendar = {};
pluginSockets.calendar.canPostEvent = async ({ uid }, { pid, tid, cid, isMain }) => {
const neither = {
canPost: false,
canPostMandatory: false,
};
if (!isMain && await getSetting('mainPostOnly')) {
return neither;
}
if (!(pid || tid || cid)) {
return neither;
}
let promises;
if (pid) {
promises = [
can.posts(privilegeNames.canPost, pid, uid),
can.posts(privilegeNames.canMandatoryPost, pid, uid),
];
}
if (tid) {
promises = [
can.topics(privilegeNames.canPost, tid, uid),
can.topics(privilegeNames.canMandatoryPost, tid, uid),
];
}
if (cid) {
promises = [
can.categories(privilegeNames.canPost, cid, uid),
can.categories(privilegeNames.canMandatoryPost, cid, uid),
];
}
const [canPost, canPostMandatory] = await Promise.all(promises);
return {
canPost,
canPostMandatory,
};
};
Could you give me a little introduction? I'm sorry - I am a noob
but I really want to learn....
I got it
- Import custom Sockets via
const chatSockets = require.main.require('./src/socket.io/plugins');
- Define a test socket
chatSockets.sendMessage = function(socket, data, callback) {
console.log("Working?");
console.log(data);
callback(null, "It worked!");
}
- Go into Browser and Emit an Event
socket.emit('plugins.sendMessage', {data: "Some data"}, function(err, result) {
alert(result);
});
U can use this snipped in your main.js client script file:
socket.emit('plugins.sendMessage', {data: "Some data"}, function(err, result) {
alert(result);
});