-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplayer.tsx
67 lines (58 loc) · 1.44 KB
/
player.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* _____ __
* / ___// /_ _____
* \__ \/ / / / / _ \
* ___/ / / /_/ / __/
* /____/_/\__, /\___/
* /____/
* Copyright 2018 Parsa Ghadimi. All Rights Reserved.
* Licence: MIT License
*/
import React, { Component } from "react";
import * as types from "./types";
export interface PlayerProps {
onClose(): void;
presentation: types.Presentation;
}
export class Player extends Component<PlayerProps, {}> {
// Reference to player DOM object.
playerDiv: HTMLDivElement;
iFrame: HTMLIFrameElement;
componentWillMount() {
this.iFrame = document.createElement("iframe");
this.iFrame.src = "/player.html";
}
componentWillUnmount() {
// Send dispose event to iFrame
this.iFrame.contentWindow.postMessage(JSON.stringify({
slye: true,
type: "dispose"
}), "*");
}
shouldComponentUpdate() {
// No need to update component at this point.
return false;
}
sendToIFrame() {
setTimeout(() => {
this.iFrame.contentWindow.postMessage(JSON.stringify({
slye: true,
type: "init",
presentation: this.props.presentation
}), "*");
}, 500);
}
handleRef = async playerDiv => {
this.playerDiv = playerDiv;
if (!playerDiv) return;
this.iFrame.onload = () => {
this.sendToIFrame();
};
playerDiv.appendChild(this.iFrame);
}
render() {
return (
<div className="player" ref={ this.handleRef } />
);
}
}