mister-ben / videojs-flvjs

Video.js tech using flv.js for FLV playback
https://mister-ben.github.io/videojs-flvjs/
Other
124 stars 31 forks source link

Example importing to typescript/webpack? #18

Open d9k opened 4 years ago

d9k commented 4 years ago

Hello! Please include examples for using module with import.

import * as videojs from 'video.js'
import "flv.js"
import "videojs-flvjs"

doesn't work in my typescript project: flvjs is undefined

If I use ugly

let videojs = require('video.js')
let flvjs = require('flv.js')
window.flvjs = flvjs
let videoJsFlvJsModule = require("videojs-flvjs")

tech becomes attached to another instance of video.js module! videojs.getTech('Flvjs') is undefined

If I try to fix it with

let videojs = require('video.js')
let flvjs = require('flv.js')
window.flvjs = flvjs
let videoJsFlvJsModule = window.videoJsFlvJsModule = require("videojs-flvjs")
let videoJsFlvJsTech = window.videoJsFlvJsTech = videoJsFlvJsModule.default
videojs.registerTech('Flvjs', videoJsFlvJsTech)

then registerTech fails with an error because tech generated with another videojs module instance I get an error Tech Flvjs must be a Tech because the component.prototype instanceof Tech check fails.

d9k commented 4 years ago

Code generated by webpack uses different modules ids in __webpack_require__(), for me 1325 and 1327. Why so?

d9k commented 4 years ago

Now works. I had to copy /src/plugin.js in this repo to my project (to the lib/VideoJsFlvJs.ts file) and change there

import videojs from 'video.js'

to

import * as videojs from 'video.js'.

On my application code:

import * as videojs from 'video.js'
window.flvjs = require('flv.js')
require('./lib/VideoJsFlvJs')

BTW, I'm using Webpack 3, no time for migrate to 4+ yet.

yexk commented 4 years ago

I used your solution. It's not good in webpack 4+, report errors: TypeError: video_js__WEBPACK_IMPORTED_MODULE_1__ is not a function {D0948380-0192-4AD7-9620-41F44C9C19E9}_20191226112607