0

I am trying to make a video chat using WebRTC and Node.js. I currently am trying to add a selectable microphone (e.g. being able to change mics and webcams). I made the function, but when I try to import a function from the file that generates the IDs of the the devices, it doesnt work. Note that I am not currently getting any errors, instead, when I add the import statement to the file, nothing shows up (except for the dropdowns that change the mic and webcam).

Is there a reason that node wont let me import a function?

Note that the file that I am trying to import into exports a bunch of functions (thats the purpose of it), RTC.js. However, I also tried importing into another file and it didnt work either (the file that imports the first file, rtc.js).

Thanks in advance

The github repository is located here

asked Aug 17, 2020 at 4:33
4
  • Can you share your code where you import/export Commented Aug 17, 2020 at 4:39
  • As far as I know, the server is needed only for signaling. All the logic that you've mentioned for changing the input media device belongs to the client-side. Paste some code so it can give more insight into what are you doing wrong. Commented Aug 17, 2020 at 4:47
  • @JatinMehrotra the code is located here Commented Aug 17, 2020 at 16:46
  • @AniketKariya I imported the file into this file, im tryng to import devices.js Commented Aug 17, 2020 at 16:49

2 Answers 2

1

Export is like this line you already did https://github.com/divinelemon/VideoChatAppSwitchMics/blob/master/ws/stream.js#L34

module.exports = stream;

Import is like here you did https://github.com/divinelemon/VideoChatAppSwitchMics/blob/master/app.js#L5

let stream = require( './ws/stream' );
answered Aug 17, 2020 at 16:53
Sign up to request clarification or add additional context in comments.

Comments

0

you can also ES6 import/export function:-

const someFunction = (){
...
}
 export default someFuntion ( in the case on single function)

When you want to export multiple functions

export { someFunction1, someFunction2}.

Now the place where you want to import

import somFunction from 'filelocation' ( note in case of default exports you need to use the same name of the function)

In the case of multiple functions.You can change the function name but keep in mind the order of exports and imports.

import { myFunction1,myFunction2} from 'fileLocation'
answered Aug 18, 2020 at 5:41

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.