本文整理匯總了TypeScript中nextgen-events.Proxy類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Proxy類的具體用法?TypeScript Proxy怎麽用?TypeScript Proxy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Proxy類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: connection
emitter.on('connection', function connection(ws: any) {
// Create a proxy for this client
const proxy = new NgEmitter.Proxy();
// Add the local service exposed to this client and grant it all right
proxy.addLocalService('heartBeatService', heartBeatEmitter, {
listen: true,
emit: true,
ack: true,
});
// message received: just hook to proxy.receive()
ws.on('message', function incoming(message: any) {
proxy.receive(message);
});
// Define the receive method: should call proxy.push()
// after decoding the raw message
proxy.receive = function receive(raw: any) {
try {
proxy.push(JSON.parse(raw));
} catch (error) {}
};
// Define the send method
proxy.send = function send(message: any) {
ws.send(JSON.stringify(message));
};
// Clean up after everything is done
ws.on('close', function close() {
proxy.destroy();
});
});
示例2: open
ws.on('open', function open() {
// Add the remote service we want to access
proxy.addRemoteService('heartBeatService');
// Listen to the event 'heartBeat' on this service
proxy.remoteServices.heartBeatService.on('heartBeat', (beat: any) => {});
});
示例3: close
ws.on('close', function close() {
proxy.destroy();
});
示例4: receive
proxy.receive = function receive(raw: any) {
try {
proxy.push(JSON.parse(raw));
} catch (error) {}
};
示例5:
ws.on('message', (message: any) => {
proxy.receive(message);
});
示例6: incoming
ws.on('message', function incoming(message: any) {
proxy.receive(message);
});