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

No MediaStream in connected peers #37

Open
SashaShtal opened this issue Jul 31, 2022 · 0 comments
Open

No MediaStream in connected peers #37

SashaShtal opened this issue Jul 31, 2022 · 0 comments

Comments

@SashaShtal
Copy link

I am using simple-peer and simple-signal to connect two clients with webcams.
After creating peer connection and passing MediaStream to it, there is no video on the receiving side, just transparent/black square.

Server side:
`const signalServer = require('simple-signal-server')(io)
const allIDs = new Set()

signalServer.on('discover', (request) => {
const clientID = request.socket.id
allIDs.add(clientID)
request.discover(Array.from(allIDs))
})

signalServer.on('disconnect', (socket) => {
const clientID = socket.id
allIDs.delete(clientID)
})

signalServer.on('request', (request) => {
request.forward()
})`

Client side (Vue.js)
`var SimpleSignalClient = require("simple-signal-client");
var signalClient = new SimpleSignalClient(this.$socket.client); // Uses an existing socket.io-client instance

    function promptUserForID(ids) {
      console.log(ids);
      return ids[0];
    }

    signalClient.on("discover", async (allIDs) => {
      const id = await promptUserForID(allIDs); // Have the user choose an ID to connect to
      const { peer, metadata } = await signalClient.connect(id); // connect to target client , { asd: 123 }, { stream: stream }
      console.log(metadata);
      console.log("initiator", peer); // this is a fully-signaled simple-peer object (initiator side)
      peer.addStream(stream);
      peer.on("stream", (s) => {
        var video = document.getElementById("remote1");
        console.log(video);
        if ("srcObject" in video) {
          console.log(1);
          video.srcObject = s;
        } else {
          console.log(1);
          video.src = window.URL.createObjectURL(s); // for older browsers
        }
      });
      peer.on("error", (err) => {
        console.log(err);
      });
    });
    //console.log(stream);

    signalClient.on("request", async (request) => {
      const { peer, metadata } = await request.accept(); // Accept the incoming request
      console.log(metadata);
      peer.addStream(stream);
      console.log("answer", peer); // this is a fully-signaled simple-peer object (non-initiator side)
      peer.on("stream", (s) => {
        console.log("stream");
        console.log(s);
        var video = document.getElementById("remote1");
        console.log(video);
        if ("srcObject" in video) {
          console.log(1);
          video.srcObject = s;
        } else {
          console.log(1);
          video.src = window.URL.createObjectURL(s); // for older browsers
        }
      });
      peer.on("error", (err) => {
        console.log(err);
      });
    });

    signalClient.discover();`
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

1 participant