mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
Video elements constructor params refactored
This commit is contained in:
parent
b456024dba
commit
f398bf3516
5 changed files with 8 additions and 65 deletions
|
|
@ -21,7 +21,7 @@ class Video extends Component {
|
|||
this.dispatch('command', 'destroy');
|
||||
}
|
||||
|
||||
selectVideoImplementation = (stream, extra) => {
|
||||
selectVideoImplementation = (stream, options) => {
|
||||
if (stream.ytId) {
|
||||
return YouTubeVideo;
|
||||
} else {
|
||||
|
|
@ -34,7 +34,7 @@ class Video extends Component {
|
|||
const Video = this.selectVideoImplementation(args[2], args[3]);
|
||||
if (this.video === null || this.video.constructor !== Video) {
|
||||
this.dispatch('command', 'destroy');
|
||||
this.video = new Video(this.containerRef.current);
|
||||
this.video = new Video({ containerElement: this.containerRef.current });
|
||||
this.video.on('ended', this.props.onEnded);
|
||||
this.video.on('error', this.props.onError);
|
||||
this.video.on('propValue', this.props.onPropValue);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
var EventEmitter = require('events');
|
||||
var HTMLSubtitles = require('./HTMLSubtitles');
|
||||
|
||||
function HTMLVideo(containerElement) {
|
||||
function HTMLVideo(options) {
|
||||
var containerElement = options && options.containerElement;
|
||||
if (!(containerElement instanceof HTMLElement) || !containerElement.hasAttribute('id')) {
|
||||
throw new Error('Instance of HTMLElement with id attribute required as a first argument');
|
||||
throw new Error('Instance of HTMLElement with id attribute required');
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
var EventEmitter = require('events');
|
||||
var HTMLSubtitles = require('./HTMLSubtitles');
|
||||
|
||||
function YouTubeVideo(containerElement) {
|
||||
function YouTubeVideo(options) {
|
||||
var containerElement = options && options.containerElement;
|
||||
if (!(containerElement instanceof HTMLElement) || !containerElement.hasAttribute('id')) {
|
||||
throw new Error('Instance of HTMLElement with id attribute required as a first argument');
|
||||
throw new Error('Instance of HTMLElement with id attribute required');
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
const ipc = require('./ipc');
|
||||
|
||||
module.exports = {
|
||||
ipc
|
||||
};
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
var events = require("events");
|
||||
|
||||
var ipc = new events.EventEmitter();
|
||||
|
||||
ipc.props = { };
|
||||
ipc.send = function() { };
|
||||
ipc.isDesktop = false;
|
||||
|
||||
// New method of communication
|
||||
window.initShellComm = function() {
|
||||
var transport = window.qt && window.qt.webChannelTransport
|
||||
if (! transport) throw "no viable transport found (qt.webChannelTransport)"
|
||||
|
||||
ipc.isDesktop = true;
|
||||
|
||||
var QtMsgTypes = { signal: 1, propertyUpdate: 2, init: 3, idle: 4, debug: 5, invokeMethod: 6, connectToSignal: 7, disconnectFromSignal: 8, setProperty: 9, response: 10 };
|
||||
var QtObjId = "transport"; // the ID of our transport object
|
||||
|
||||
var id = 0;
|
||||
function send(msg) {
|
||||
msg.id = id++;
|
||||
transport.send(JSON.stringify(msg))
|
||||
}
|
||||
|
||||
transport.onmessage = function(message) {
|
||||
var msg = JSON.parse(message.data)
|
||||
|
||||
if (msg.id === 0) {
|
||||
var obj = msg.data[QtObjId]
|
||||
|
||||
obj.properties.slice(1).forEach(function(prop) {
|
||||
ipc.props[prop[1]] = prop[3]
|
||||
})
|
||||
ipc.emit("received-props", ipc.props)
|
||||
|
||||
obj.signals.forEach(function(sig) {
|
||||
send({ type: QtMsgTypes.connectToSignal, object: QtObjId, signal: sig[1] })
|
||||
})
|
||||
|
||||
var onEvent = obj.methods.filter(function(x) { return x[0] === "onEvent" })[0]
|
||||
|
||||
ipc.send = function(ev, args) {
|
||||
send({ type: QtMsgTypes.invokeMethod, object: QtObjId, method: onEvent[1], args: [ev, args || { }] })
|
||||
}
|
||||
ipc.send("app-ready", { }) // signal that we're ready to take events
|
||||
}
|
||||
|
||||
if (msg.object == QtObjId && msg.type === QtMsgTypes.signal) ipc.emit(msg.args[0], msg.args[1])
|
||||
}
|
||||
|
||||
send({ type: QtMsgTypes.init })
|
||||
}
|
||||
|
||||
module.exports = ipc;
|
||||
Loading…
Reference in a new issue