question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Difficulty with use in reactjs

See original GitHub issue

I’m attempting to use videojs-ima as a plugin on top of the reactjs example found in the guides page. But It seems like videojs-ima really disagrees with being used in webpack.

I have an instance of the player on my page, but when I try to load the plugin using this.player.ima I get an error and no advertisement appears as expected

Error in question:

Uncaught TypeError: this.player.ima is not a function

Is there a way to implement this plugin with react?

This is the component I’m using, that I attempted to modify to use reactjs-ima

import React from 'react';
import videojs from 'video.js'
import 'videojs-ima'

export default class VideoPlayer extends React.Component {
  componentDidMount() {
    // instantiate Video.js
    this.player = videojs(this.videoNode, this.props, function onPlayerReady() {
      console.log('onPlayerReady', this)
      let options = {
          id: this.videoNode,
          adTagUrl: 'http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=xml_vmap1&unviewed_position_start=1&cust_params=sample_ar%3Dpremidpostpod%26deployment%3Dgmf-js&cmsid=496&vid=short_onecue&correlator='
      }
      this.player.ima(options)
    });
  }

  // destroy player on unmount
  componentWillUnmount() {
    if (this.player) {
      this.player.dispose()
    }
  }

  // wrap the player in a div with a `data-vjs-player` attribute
  // so videojs won't create additional wrapper in the DOM
  // see https://github.com/videojs/video.js/pull/3856
  render() {
    return (
      <div>    
        <div data-vjs-player>
          <video ref={ node => this.videoNode = node } className="video-js"></video>
        </div>
      </div>
    )
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jackson-sandlandcommented, Mar 16, 2018

Same exact issue. Would really appreciate some insight into getting this to work. I’ve got all the required dependencies, but the player object does not have an ima key, and this results in the above error.

Was able to resolve this by including all the dependencies in the head of the app html doc. Not ideal, but at least it works. Here’s a working example using imports into the document head: https://codepen.io/anon/pen/MVejgR

0reactions
Kiro705commented, Oct 15, 2019

Hi all,

I recently had trouble using the videojs-ima plugin using a webpack setup as well. Because of the difficulty we decided to update the readme with a guide for this implementation.

Please see this: https://github.com/googleads/videojs-ima#es6-imports

I will be closing the issue, but please feel free to reopen it if there are changes to the guide that should be made.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Deal With Common React JS Problems - Actionable Tips
A common repeating performance problem in React JS is a complex and long list of items. Say the app needs to render many...
Read more >
Why React JS is Hard to Learn? - Medium
React is difficult to learn for beginners. This is due to its modular nature. Most React modules are interrelated and require you to...
Read more >
React.js Frequently Faced Problems - DEV Community ‍ ‍
1 — Not starting a component name with a capital letter​​ If the component name does not start with a capital letter, the...
Read more >
More Than React: Why You Shouldn't Use ReactJS for ... - InfoQ
ReactJS components are difficult to reuse in complex interactive web projects. · ReactJS's Virtual DOM algorithm is time-consuming and imprecise.
Read more >
Tutorial: Intro to React
In particular, render returns a React element, which is a lightweight description of what to render. Most React developers use a special syntax...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found