GithubHelp home page GithubHelp logo

Comments (4)

jackblackCH avatar jackblackCH commented on July 29, 2024

Facing same issues. Is there any good workaround?

from opentok-react.

stevelong-at-prplrs avatar stevelong-at-prplrs commented on July 29, 2024

Delay loading the OpenTok library until the app is running in the browser.

How you do that will change depending on your particular framework.

from opentok-react.

nimrabaig-embrace avatar nimrabaig-embrace commented on July 29, 2024

@stevelong-at-prplrs How to do that on NextJs?

from opentok-react.

rogercbe avatar rogercbe commented on July 29, 2024

As @stevelong-at-prplrs mentioned, the problem is that NextJs will try to render it server side and OpenTok needs to be run on the client because it needs access to the browser. It wont work server side hence: ReferenceError: window is not defined.

To overcome that you need to run OpenTok only on the client, one solution is to use next/dynamic to avoid rendering the component server side.

A working solution could be wrapping up all your OpenTok session in a component and dinamically import it.

/pages/index.js

import dynamic from "next/dynamic";

const OpenTokWrap = dynamic(() => import("../../components/OpenTokWrap"), {
  ssr: false, // important to disable SSR
});

export default function Home() {
  return (
      <OpenTokWrap />
  )
};

/components/OpenTokWrap.jsx

import {
  preloadScript,
  OTSession,
  OTPublisher,
  OTStreams,
  OTSubscriber,
} from "opentok-react";

const OpenTokWrap = ({ session }) => (
  <OTSession apiKey="api-key" sessionId="session-id token="token">
    <OTPublisher />
    <OTStreams>
      <OTSubscriber />
    </OTStreams>
  </OTSession>
);

export default preloadScript(OpenTokWrap);

from opentok-react.

Related Issues (20)

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.