在浏览器中执行的代码与在Node中执行的代码有什么区别

时间:2018-09-27 16:06:00

标签: node.js browser pusher pusher-js

此代码在使用浏览器打开时可以完美地工作,但是当我剪切并粘贴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');

要导入推送程序而不是脚本标签。

0 个答案:

没有答案