Giter VIP home page Giter VIP logo

walkie-talkie's People

Contributors

ajshres avatar isaurssaurav avatar saurssauravjs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

walkie-talkie's Issues

An HTTPS server solves the navigator.mediaDevices HTTP issue

Hi Saurav,

I enjoyed your 2018 article, thanks.
No way to run it using HTTP. I guess the issue is here:

navigator.mediaDevices is undefined in an insecure context.

See: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

Problem solved using an HTTPS server. To thank you, here the running code, that could substitute the original index.js:

/*
 * @see https://stackoverflow.com/questions/31156884/how-to-use-https-on-node-js-using-express-socket-io
 *
 * $ sudo ufw allow 8443
 * $ sudo ufw status verbose
 *
 */
const fs = require('fs')
const https = require('https')

const express = require('express')
const app = express()

//
// HTTPS server setup
//

// configurations
const PORT = 8443
const KEY_FILENAME = 'selfsigned.key'
const CERT_FILENAME = 'selfsigned.cert'

//
// get SSL certificate
//
const credentials = {
  key: fs.readFileSync(KEY_FILENAME, 'utf8'),
  cert: fs.readFileSync(CERT_FILENAME, 'utf8')
}

// create the https server and the socketio channel
const server = https.createServer(credentials, app)
const io = require('socket.io')(server)

// root route
app.get('/', (req, res) =>
  res.sendFile(__dirname + '/index.html'))

// run the https server
server.listen(PORT, () => {
    console.log('server running.')
    console.log(`Listening on port: ${PORT}`)
    console.log()
  })


//
// socketio messaging application
//

// applicaction variables
let Usercounter = 0

//
// connection/disconnection logic
//
io.on('connection', (socket) => {

  Usercounter = Usercounter + 1
  io.emit('user', Usercounter)
  console.log('a user is connected')

  socket.on('disconnect', () => {

    Usercounter = Usercounter - 1
    io.emit('user', Usercounter)
    console.log('user disconnected')

  })


  //
  // echo server logic:
  // the audio message received is returned back
  //
  socket.on('audioMessage', (msg) => {
    io.emit('audioMessage', msg)
  })

})

respect
giorgio

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.