Когда узел 1 подключается к узлу 2
- the highlighted code in the picture should fire
- узел 2 должен отправить узлу 1 привет!
- коллега 1 должен приветствовать! напечатано в его консоли
Пир 1 подключается к пиру 2
Проблема: у узла 1 нет приветствия! печатается в консоли
// make a new peer
const peer = new Peer('', {
host: '/',
port: '3001'
});
// "connection" event fires when someone tries to connect to us
peer.on('connection', (conn) => {
console.log('someone connected');
// "data" event fires when someone sends us a message
conn.on('data', (data) => {
console.log(data);
});
// ===========================================================================
// Problem: Both Attempt 1 and Attempt 2 fail to run
// ATTEMPT 1: "open" event fires when the connection is opened
conn.on('open', () => {
conn.send('hello!');
});
// ATTEMPT 2:
conn.send('hello!');
// ===========================================================================
});
// connect to a peer
const conn = peer.connect('another-peers-id');
// after connecting to peer, send "hi" to them
conn.on('open', () => {
conn.send('hi!');
});