本文整理汇总了TypeScript中xev.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了on函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: subscribe
subscribe(channelName: string): void {
if (this.list[channelName] == null) {
const handler = this.handler(channelName);
this.parentEmitter.on(channelName, handler);
this.list[channelName] = handler;
}
}
示例2: function
/**
* Report server stats regularly
*/
export default function() {
const log = new Deque<any>();
ev.on('requestServerStatsLog', id => {
ev.emit('serverStatsLog:' + id, log.toArray());
});
async function tick() {
const cpu = await cpuUsage();
const usedmem = await usedMem();
const totalmem = await totalMem();
const disk = diskusage.checkSync(os.platform() == 'win32' ? 'c:' : '/');
const stats = {
cpu_usage: cpu,
mem: {
total: totalmem,
used: usedmem
},
disk,
os_uptime: os.uptime(),
process_uptime: process.uptime()
};
ev.emit('serverStats', stats);
log.push(stats);
if (log.length > 50) log.shift();
}
tick();
setInterval(tick, interval);
}
示例3: function
export default async function(
request: websocket.request,
connection: websocket.connection,
subscriber: Xev,
user: IUser
) {
const mute = await Mute.find({ muterId: user._id });
const mutedUserIds = mute.map(m => m.muteeId.toString());
// Subscribe stream
subscriber.on('global-timeline', async note => {
//#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (mutedUserIds.indexOf(note.userId) != -1) {
return;
}
if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
return;
}
if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
return;
}
//#endregion
connection.send(JSON.stringify({
type: 'note',
body: note
}));
});
}
示例4: function
export default function(request: websocket.request, connection: websocket.connection, subscriber: Xev, user: any): void {
const q = request.resourceURL.query as ParsedUrlQuery;
const listId = q.listId as string;
// Subscribe stream
subscriber.on(`user-list-stream:${listId}`, data => {
connection.send(JSON.stringify(data));
});
}
示例5: function
export default async function(
request: websocket.request,
connection: websocket.connection,
subscriber: Xev,
user: IUser
) {
// Subscribe stream
subscriber.on('hybrid-timeline', onEvent);
subscriber.on(`hybrid-timeline:${user._id}`, onEvent);
const mute = await Mute.find({ muterId: user._id });
const mutedUserIds = mute.map(m => m.muteeId.toString());
async function onEvent(note: any) {
//#region 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
if (mutedUserIds.indexOf(note.userId) != -1) {
return;
}
if (note.reply != null && mutedUserIds.indexOf(note.reply.userId) != -1) {
return;
}
if (note.renote != null && mutedUserIds.indexOf(note.renote.userId) != -1) {
return;
}
//#endregion
// Renoteなら再pack
if (note.renoteId != null) {
note.renote = await pack(note.renoteId, user, {
detail: true
});
}
connection.send(JSON.stringify({
type: 'note',
body: note
}));
}
}
示例6: switch
connection.on('message', async data => {
const msg = JSON.parse(data.utf8Data);
switch (msg.type) {
case 'api':
// 新鮮なデータを利用するためにユーザーをフェッチ
call(msg.endpoint, await User.findOne({ _id: user._id }), app, msg.data).then(res => {
connection.send(JSON.stringify({
type: `api-res:${msg.id}`,
body: { res }
}));
}).catch(e => {
connection.send(JSON.stringify({
type: `api-res:${msg.id}`,
body: { e }
}));
});
break;
case 'alive':
// Update lastUsedAt
User.update({ _id: user._id }, {
$set: {
'lastUsedAt': new Date()
}
});
break;
case 'read_notification':
if (!msg.id) return;
readNotification(user._id, msg.id);
break;
case 'capture':
if (!msg.id) return;
log(`CAPTURE: ${msg.id} by @${user.username}`);
subscriber.on(`note-stream:${msg.id}`, onNoteStream);
break;
case 'decapture':
if (!msg.id) return;
log(`DECAPTURE: ${msg.id} by @${user.username}`);
subscriber.off(`note-stream:${msg.id}`, onNoteStream);
break;
}
});
示例7: function
export default function() {
const log = new Deque<any>();
const p = childProcess.fork(__dirname + '/notes-stats-child.js');
p.on('message', stats => {
ev.emit('notesStats', stats);
log.push(stats);
if (log.length > 100) log.shift();
});
ev.on('requestNotesStatsLog', id => {
ev.emit('notesStatsLog:' + id, log.toArray());
});
process.on('exit', code => {
process.kill(p.pid);
});
}
示例8: function
export default function(request: websocket.request, connection: websocket.connection, subscriber: Xev, user: any): void {
const q = request.resourceURL.query as ParsedUrlQuery;
const otherparty = q.otherparty as string;
// Subscribe messaging stream
subscriber.on(`messaging-stream:${user._id}-${otherparty}`, data => {
connection.send(JSON.stringify(data));
});
connection.on('message', async (data) => {
const msg = JSON.parse(data.utf8Data);
switch (msg.type) {
case 'read':
if (!msg.id) return;
read(user._id, otherparty, msg.id);
break;
}
});
}
示例9: function
export default function(request: websocket.request, connection: websocket.connection, subscriber: Xev, user: any): void {
// Subscribe reversi stream
subscriber.on(`reversi-stream:${user._id}`, data => {
connection.send(JSON.stringify(data));
});
connection.on('message', async (data) => {
const msg = JSON.parse(data.utf8Data);
switch (msg.type) {
case 'ping':
if (msg.id == null) return;
const matching = await Matching.findOne({
parentId: user._id,
childId: new mongo.ObjectID(msg.id)
});
if (matching == null) return;
publishUserStream(matching.childId, 'reversi_invited', await pack(matching, matching.childId));
break;
}
});
}
示例10: function
export default function(request: websocket.request, connection: websocket.connection, subscriber: Xev, user: any): void {
// Subscribe messaging index stream
subscriber.on(`messaging-index-stream:${user._id}`, data => {
connection.send(JSON.stringify(data));
});
}