Reputation:
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
Upvotes: 0
Views: 179
Reputation: 11523
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'
Upvotes: 0
Reputation: 677
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' );
Upvotes: 1