Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chat is not wroking #12

Open
KumailHussain opened this issue Sep 15, 2017 · 1 comment
Open

chat is not wroking #12

KumailHussain opened this issue Sep 15, 2017 · 1 comment

Comments

@KumailHussain
Copy link

function textRoomPress() {
var text = document.getElementById('textRoomInput').value;
if (text == "") {
alert('Enter something');
} else {
document.getElementById('textRoomInput').value = '';
var content = document.getElementById('textRoomContent');
content.innerHTML = content.innerHTML + '

' + 'Me' + ': ' + text + '

';
for (var key in pcPeers) {
var pc = pcPeers[key];
pc.textDataChannel.send(text);
}
}
}

it is not activating this function:

dataChannel.onmessage = function (event) {
  console.log("dataChannel.onmessage:", event.data);
  var content = document.getElementById('textRoomContent');
  content.innerHTML = content.innerHTML + '<p>' + socketId + ': ' + event.data + '</p>';
};

nothing happens

@Keerato
Copy link

Keerato commented Nov 16, 2018

Yes, it's a bug, but luckily I can fix it. By just 3 steps.

  1. remove this code "var dataChannel = pc.createDataChannel("text");"
  2. At pc.oniceconnectionstatechange remove this "createDataChannel();"
  3. Change pc.onnegotiationneeded to this one
    pc.onnegotiationneeded = function () {
    console.log('onnegotiationneeded');
    if (isOffer) {
    createOffer();
    dataChannel = pc.createDataChannel('chat');
    createDataChannel();
    } else {
    // If user is not the offerer let wait for a data channel
    pc.ondatachannel = event => {
    dataChannel = event.channel;
    createDataChannel();
    }
    }
    }
    Enjoy. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants