В чем разница между кодом, выполняемым в браузере, и узлом - PullRequest
0 голосов
/ 27 сентября 2018

Этот код отлично работает при открытии в браузере, но когда я вырезал и вставил тот же код в 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');

Для импортатолкатель, а не тег сценария.

...