Description: Today many people use NextJS for building webapps. But when they importing Peer from peerjs they get this error because when webpack compile it in server side, navigator is not present there.
In peerjs/dist/bundel.mjs : I made change in this file as given below literally remove the error from compiling and building in simple import without using useeffect or dynamic import. Only 'use client' is defined at top.
Title: Fix Issue #1165: Navigator is not defined.
Description: Today many people use NextJS for building webapps. But when they importing Peer from peerjs they get this error because when webpack compile it in server side, navigator is not present there.
Issue: link of issue #1165
Changes Made:
In peerjs/dist/bundel.mjs : I made change in this file as given below literally remove the error from compiling and building in simple import without using useeffect or dynamic import. Only 'use client' is defined at top.
So this means, checking the navigator in support.ts is able to solve this problem.
Now :
readonly isIOS = ["iPad", "iPhone", "iPod"].includes(navigator.platform);
Change to :
readonly isIOS = navigator ? (["iPad", "iPhone", "iPod"].includes(navigator.platform)) : false;
The navigator.platform only works when navigator is available else isIOS assigned false.
Reviewer Requests:
@jonasgloning : Please review the changes and provide feedback.