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

How to do two way audio Communication? #2

Open
crosofg opened this issue Sep 20, 2017 · 13 comments
Open

How to do two way audio Communication? #2

crosofg opened this issue Sep 20, 2017 · 13 comments

Comments

@crosofg
Copy link

crosofg commented Sep 20, 2017

How can I send audio stream from browser to the device?

@KensakuKOMATSU
Copy link
Contributor

KensakuKOMATSU commented Sep 23, 2017

Hi, I implemented this as a hidden feature before.

Since I need to check and test it, I will respond you back by next weekend.

@crosofg
Copy link
Author

crosofg commented Sep 23, 2017 via email

@KensakuKOMATSU
Copy link
Contributor

Sorry for late. I finished to check.

You can send audio stream, by simply calling skyway.call() method. Here is a snipet leveraging SiRuClient.

const client = new SiRuClient('testroom', {key: 'YOUR_SKYWAY_APIKEY_HERE'})

client.on('connect', () => {
  client.on('device:connected', (uuid, profile) => {
    // when device has connected, you can get peerid of it by calling getPeerid()
    // then you can call startAudioStream()
    const peerid = client.deviceManager.getPeerid(uuid)
    startAudioStream(peerid)
  })
})

function startAudioStream(peerid) {
  navigator.mediaDevices.getUserMedia({ audio: true, video: false})
    .then( stream => {
      // skyway is still internal property, but you can use it for sending stream
      const call = client.skyway.call(peerid, stream)
      call.on('stream', stream => {
        console.log(stream) // #=> nothing streamed from device, but you can detect sending stream started
      })
    })
}

After that janus will send audio stream from browser to localhost:25000/udp as a default. For instance, gstreamer pipeline shown below will record this audio stream as a raw wav file. (I assume the audio stream is opus encoded )

gst-launch-1.0 -v udpsrc port=25000 \
  caps="application/x-rtp,media=(string)audio,clock-rate=(int)48000,encoding-name=(string)X-GST-OPUS-DRAFT-SPITTKA-00 " ! \
  rtpopusdepay ! opusdec ! wavenc !  \
    filesink location=recorded_audio.wav

If you want to change destination address and port from the default setting, you can do it by updating /opt/janus/etc/janus/janus.plugin.skywayiot.cfg ( media_send_dest and media_send_port ).

@crosofg
Copy link
Author

crosofg commented Oct 7, 2017

 filesink location=recorded_audio.wav

Does this create a file? I need the stream to be played on the speaker of raspberry pi.

@KensakuKOMATSU
Copy link
Contributor

Yes, above sample pipeline is to create wave file.

In your case, autoaudiosink shown below will work,
(although I have not been tested on raspberry pi yet ...)

gst-launch-1.0 -v udpsrc port=25000 \
  caps="application/x-rtp,media=(string)audio,clock-rate=(int)48000,encoding-name=(string)X-GST-OPUS-DRAFT-SPITTKA-00 " ! \
  rtpopusdepay ! opusdec ! \
  audioconvert ! audioresample ! \
  autoaudiosink

@KensakuKOMATSU
Copy link
Contributor

I tested. autoaudiosink should work for playing on raspberry PI, even though there is no GUI.

@crosofg
Copy link
Author

crosofg commented Oct 16, 2017

I am getting api key is invalid error.

failed: WebSocket is closed before the connection is established.

@crosofg
Copy link
Author

crosofg commented Oct 16, 2017

[ERR] [sctp.c:janus_sctp_send_text:662] [1570878384403988] Channel 0 is neither open nor connecting (state=3)...

What is this due to?

@crosofg
Copy link
Author

crosofg commented Oct 16, 2017

[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...
[ERR] [sctp.c:janus_sctp_send_text:662] [6253374261417522] Channel 0 is neither open nor connecting (state=3)...

@crosofg
Copy link
Author

crosofg commented Oct 16, 2017


[skywayiotsdk-example] New audio stream! (ssrc=2532007687)
[skywayiotsdk-example] New video stream! (ssrc=2998286943)
Creating new session: 6629971329624684
Creating new handle in session 6629971329624684: 3141049738596687
[3141049738596687] Creating ICE agent (ICE Full mode, controlled)
[WARN] [3141049738596687] Still waiting for the DTLS stack for component 1 in st                                                 ream 1...
[WARN] [3141049738596687] Still waiting for the DTLS stack for component 1 in st                                                 ream 1...
[3141049738596687] The DTLS handshake has been completed
WebRTC media is now available
[-563734272, 28849048] (null)
[0]matched!!!  has_video => 28849048, has_audio => 0, has_data => 0
[28849048, 0] WebRTC media : has_audio[28890528], has_video[0], has_data[1]
[WARN] [3141049738596687] Not video and not audio? dropping (SSRC 2950583010)...
No WebRTC media anymore
[3141049738596687] WebRTC resources freed
Creating new session: 7440658924689462
Creating new handle in session 7440658924689462: 6773618269006429
[6773618269006429] Creating ICE agent (ICE Full mode, controlled)
[WARN] [6773618269006429] Still waiting for the DTLS stack for component 1 in st                                                 ream 1...
[WARN] [6773618269006429] Still waiting for the DTLS stack for component 1 in st                                                 ream 1...
[WARN] [6773618269006429]     Missing valid SRTP session (packet arrived too ear                                                 ly?), skipping...
[-563734272, 28849048] (null)
[-563734272, 1873881624] (null)
[0]matched!!!  has_video => 1873881624, has_audio => 0, has_data => 0
[6773618269006429] The DTLS handshake has been completed
WebRTC media is now available
[1873881624, 0] WebRTC media : has_audio[1873881640], has_video[0], has_data[1]
No WebRTC media anymore
[6773618269006429] WebRTC resources freed

the janus process is not recognising the browser connection

@KensakuKOMATSU
Copy link
Contributor

Do you set localhost in Available domain in dashboard page? (sample is shown below)

image

And also, in most case, the permission Enabled API Key authentication should not be checked.

@crosofg
Copy link
Author

crosofg commented Oct 17, 2017

yes I have set localhost in available domains. Most of times the janus process did not send the sstream. In the chromes developers console I could see that a media stream object is returend once. but client.on('stream') was never called.

@KensakuKOMATSU
Copy link
Contributor

Hmmm,

Could you send your APIKEY to my mail address, shown here ?

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