此代码在使用浏览器打开时可以完美地工作,但是当我剪切并粘贴js文件中的相同代码时,未调用回调函数。即使它能够建立连接
<script src="https://cdnjs.cloudflare.com/ajax/libs/pusher/2.1.6/pusher.min.js" type="text/javascript"></script>
Pusher.host = 'slanger1.chain.so'; // the location of our websocket server
Pusher.ws_port = 443;
Pusher.wss_port = 443;
var pusher = new Pusher('e9f5cc20074501ca7395', { encrypted: true, disabledTransports: ['sockjs'], disableStats: true });
pusher.connection.bind('state_change', function(states) {
// states = {previous: 'oldState', current: 'newState'}
console.log(states);
});
// get updates for the DOGE blockchain
var blockchain_channel = pusher.subscribe('blockchain_update_dash');
// process transaction announcements
blockchain_channel.bind('tx_update', function(data) {
console.log("CALLLBACK IS BEING CALLED")
console.log(data);
});
唯一的区别是在我使用的js文件中
const Pusher = require('pusher-js');
要导入推送程序而不是脚本标签。