paullouisageneau / libdatachannel

C/C++ WebRTC network library featuring Data Channels, Media Transport, and WebSockets
https://libdatachannel.org/
Mozilla Public License 2.0
1.8k stars 362 forks source link

WSS #146

Closed alicera closed 4 years ago

alicera commented 4 years ago

I have a key and a cert for server, how to use them for libdatachannel?

paullouisageneau commented 4 years ago

They should be installed on the server, after that you don't have anything special to do with libdatachannel.

alicera commented 4 years ago

I only do the "wss://localhost:8000/"? Thanks, I will try it

alicera commented 4 years ago

I try to use peerjs to create a server and let client (c++) to listen the ip port , but I cant listen it. Is it something different from web(javascript)?

https://elements.heroku.com/buttons/peers/peerjs-server image I have change the port to 8000

paullouisageneau commented 4 years ago

The peerjs server requires a compatible client. You have to use the same way to send description and candidates in your client and your server. For instance, you can send JSON just like in the example clients and servers.

alicera commented 4 years ago

For peerjs test (fail)

  1. I use peerjs server to create server.
  2. I change the client "ws://localhost:8000/" or "wss://localhost:8000/"
  3. I cant connect to the peerjs server with client(c++) at first.

For simple websocket test (successful)

  1. I use the code to create server and then open client (c++)

    // Node.js WebSocket server script const http = require('http'); const WebSocketServer = require('websocket').server; const server = http.createServer(); server.listen(8000); const wsServer = new WebSocketServer({ httpServer: server }); wsServer.on('request', function(request) { const connection = request.accept(null, request.origin); connection.on('message', function(message) { console.log('Received Message:', message.utf8Data); connection.sendUTF('Hi this is WebSocket server!'); }); connection.on('close', function(reasonCode, description) { console.log('Client has disconnected.'); }); });

  2. client (c++) show WebSocket connected, signaling ready

  3. this is client for html """ <!DOCTYPE html>

    WebSocket Playground

    """

paullouisageneau commented 4 years ago

Oh yes, since you connect to localhost while your certificate is not for localhost, you have to disable certificate name verification when creating the WebSocket:

auto ws = std::make_shared<WebSocket>(WebSocket::Configuration{.disableTlsVerification = true});
alicera commented 4 years ago

Hi, Paul-Louis How does the "web" project produce sdp message?

paullouisageneau commented 4 years ago

In the JavaScript WebRTC API, the calls to PeerConnection.createOffer() or PeerConnection.createAnswer() request generation of an SDP description which is returned by the browser in a promise. The candidates are then gathered by the browser and passed to a dedicated onicecandidate callback.

paullouisageneau commented 4 years ago

I'm closing this if you have no more WSS-related questions.