![](/img/trans.png)
[英]Socket.io 'message' event fires, but individual listeners don't fire. Listeners registered in iframe
[英]Event listeners don't seem to be triggering
我正在使用Asterisk ARI Node.js客戶端,並希望偵聽某些事件然后執行操作。 根據我的理解,連接到服務器后,您可以為通過WebSockets發布的事件設置幾種不同類型的事件偵聽器來執行任務。 在我的下面的代碼中,即使我觸發這些特定事件並且可以通過WSCat連接並觀看事件流,我也不會收到任何輸出。
我正在構建的應用程序應該只監聽要發生的事件並更新數據庫。 我永遠不需要通過HTTP請求訪問Node應用程序,這就是我每次請求返回服務器時禁止的原因。 我的最終目標是讓這個應用程序坐在服務器上對事件作出反應。
'use strict';
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const client = require('ari-client');
const util = require('util');
const server = http.createServer((req, res) => {
res.statusCode = 403;
res.end('FORBIDDEN');
});
server.listen(port, hostname, () => {
client.connect('http://127.0.0.1:8088', 'username', 'password')
.then(function(ari) {
ari.on('DeviceStateChanged', function(event) {
console.log(event);
})
ari.on('ChannelCreated', function(event) {
console.log(event);
})
ari.on('BridgeCreated', function(event) {
console.log(event);
})
ari.on('StasisStart', function(event) {
console.log(event);
})
ari.on('PeerStatusChange', function(event) {
console.log('blah', event);
})
ari.on('Dial', function(event) {
console.log('Dial', event);
})
})
.catch(function(err) {
console.log(err);
})
});
為什么要創建服務器呢? 您可以測試以下內容。
'use strict';
const client = require('ari-client');
const util = require('util');
client.connect('http://127.0.0.1:8088', 'username', 'password')
.then(function(ari) {
ari.on('DeviceStateChanged', function(event) {
console.log(event);
})
ari.on('ChannelCreated', function(event) {
console.log(event);
})
ari.on('BridgeCreated', function(event) {
console.log(event);
})
ari.on('StasisStart', function(event) {
console.log(event);
})
ari.on('PeerStatusChange', function(event) {
console.log('blah', event);
})
ari.on('Dial', function(event) {
console.log('Dial', event);
})
})
.catch(function(err) {
console.log(err);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.