Skip to content

Commit f57f5da

Browse files
committed
Forked getFPVersion + isFPVersionSupported into SWFPlayerVersion module
1 parent 5fbdca1 commit f57f5da

File tree

8 files changed

+118
-252
lines changed

8 files changed

+118
-252
lines changed

README.md

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Supports all browsers supported by React.
66

77
Depends on [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Polyfill_for_non-ES6_browsers) and [`Object.assign()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill)
88

9-
```
9+
Use [SWFPlayerVersion](https://github.com/syranide/swf-player-version) to determine SWF Player support.
10+
11+
```jsx
1012
<ReactSWF
1113
src="example.swf"
1214
id="guid_001"
@@ -16,22 +18,62 @@ Depends on [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
1618
flashVars={{foo: 'A', bar: 1}}
1719
/>
1820
```
19-
```js
20-
// Test if Flash Player version is supported and output the actual version.
21-
if (ReactSWF.isFPVersionSupported('10.0')) {
22-
alert('Flash Player ' + ReactSWF.getFPVersion() + ' is installed');
21+
```jsx
22+
const SWF_ID_PREFIX = '__MyExternalInterfaceExample_SWFID_';
23+
const SWF_CALL_NAME_PREFIX = '__MyExternalInterfaceExample_SWFCall_';
24+
25+
let nextUID = 0;
26+
27+
class MyExternalInterfaceExample extends React.Component {
28+
constructor(props) {
29+
super(props);
30+
31+
// For most purposes nextUID is sufficient. However, if you rely on
32+
// non-trivial server rendering you must generate deterministic UIDs per
33+
// React root to avoid markup mismatch.
34+
this._uid = nextUID++;
35+
36+
window[SWF_CALL_NAME_PREFIX + this._uid] = this.handleSWFCall.bind(this);
37+
}
38+
39+
componentWillUnmount() {
40+
delete window[SWF_CALL_NAME_PREFIX + this._uid];
41+
}
42+
43+
handleSWFCall() {
44+
// Beware; SWF calls are executed in the context of SWF Player.
45+
console.log('SWFCall', arguments);
46+
return 'foobar';
47+
}
48+
49+
invokeSWFMyCallback(arg) {
50+
// Beware; SWF Player does not sufficiently escape serialized arguments.
51+
return this._swfPlayerNode.myCallback(arg);
52+
}
53+
54+
render() {
55+
// Globally unique ID is required for IE<11 for ExternalInterface callbacks.
56+
return (
57+
<ReactSWF
58+
...
59+
ref={c => this._swfPlayerNode = c}
60+
id={SWF_ID_PREFIX + this._uid}
61+
flashVars={{myCallbackName: SWF_CALL_NAME_PREFIX + this._uid}}
62+
/>
63+
);
64+
}
2365
}
2466
```
25-
```js
26-
// ExternalInterface callbacks are invoked on the DOM node as usual.
27-
var returnValue = ref.getFPDOMNode().myEICallback(...);
28-
```
2967

3068
## Breaking changes
3169

70+
#### 0.13.0
71+
72+
* `getFPVersion` and `isFPVersionSupported` forked to [SWFPlayerVersion](https://github.com/syranide/swf-player-version) and dropped from ReactSWF. Replace `ReactSWF.getFPVersion => SWFPlayerVersion.get` and `ReactSWF.isFPVersionSupported => SWFPlayerVersion.isSupported`.
73+
3274
#### 0.12.3
3375

34-
* Depends on `Object.assign()`, [polyfills are available.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill)
76+
* Depends on `Object.assign()`, [polyfills are available](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill).
3577

3678
#### 0.11.0
3779

@@ -76,24 +118,6 @@ Detailed explanation of most properties found at [[Flash OBJECT and EMBED tag at
76118

77119
## API
78120

79-
#### Static methods
80-
81-
```
82-
getFPVersion()
83-
returns {?string} 'X.Y.Z'-version or null.
84-
85-
Returns installed Flash Player version. Result is cached.
86-
Must not be called in a non-browser environment.
87-
```
88-
```
89-
isFPVersionSupported(versionString)
90-
versionString {string} 'X.Y.Z', 'X.Y' or 'X'.
91-
returns {boolean} true if supported.
92-
93-
Returns if installed Flash Player meets version requirement.
94-
Must not be called in a non-browser environment.
95-
```
96-
97121
#### Instance methods
98122

99123
```

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-swf",
3-
"version": "0.12.3",
3+
"version": "0.13.0",
44
"license": "MIT",
55
"description": "Shockwave Flash Player component for React",
66
"authors": ["Andreas Svensson <[email protected]>"],
@@ -12,7 +12,7 @@
1212
"url": "https://github.com/syranide/react-swf"
1313
},
1414
"dependencies": {
15-
"react": "^0.14.0-beta1"
15+
"react": "^0.14.0"
1616
},
1717
"keywords": [
1818
"react",

npm-react-swf/README.md

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Supports all browsers supported by React.
66

77
Depends on [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is#Polyfill_for_non-ES6_browsers) and [`Object.assign()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill)
88

9-
```
9+
Use [SWFPlayerVersion](https://github.com/syranide/swf-player-version) to determine SWF Player support.
10+
11+
```jsx
1012
<ReactSWF
1113
src="example.swf"
1214
id="guid_001"
@@ -16,22 +18,62 @@ Depends on [`Object.is()`](https://developer.mozilla.org/en-US/docs/Web/JavaScri
1618
flashVars={{foo: 'A', bar: 1}}
1719
/>
1820
```
19-
```js
20-
// Test if Flash Player version is supported and output the actual version.
21-
if (ReactSWF.isFPVersionSupported('10.0')) {
22-
alert('Flash Player ' + ReactSWF.getFPVersion() + ' is installed');
21+
```jsx
22+
var SWF_ID_PREFIX = '__MyExternalInterfaceExample_SWFID_';
23+
var SWF_CALL_NAME_PREFIX = '__MyExternalInterfaceExample_SWFCall_';
24+
25+
var nextUID = 0;
26+
27+
class MyExternalInterfaceExample extends React.Component {
28+
constructor(props) {
29+
super(props);
30+
31+
// For most purposes nextUID is sufficient. However, if you rely on
32+
// non-trivial server rendering you must generate deterministic UIDs per
33+
// React root to avoid markup mismatch.
34+
this._uid = nextUID++;
35+
36+
window[SWF_CALL_NAME_PREFIX + this._uid] = this.handleSWFCall.bind(this);
37+
}
38+
39+
componentWillUnmount() {
40+
delete window[SWF_CALL_NAME_PREFIX + this._uid];
41+
}
42+
43+
handleSWFCall() {
44+
// Beware; SWF calls are executed in the context of SWF Player.
45+
console.log('SWFCall', arguments);
46+
return 'foobar';
47+
}
48+
49+
invokeSWFMyCallback(arg) {
50+
// Beware; SWF Player does not sufficiently escape serialized arguments.
51+
return this._swfPlayerNode.myCallback(arg);
52+
}
53+
54+
render() {
55+
// Globally unique ID is required for IE<11 for ExternalInterface callbacks.
56+
return (
57+
<ReactSWF
58+
...
59+
ref={c => this._swfPlayerNode = c}
60+
id={SWF_ID_PREFIX + this._uid}
61+
flashVars={{myCallbackName: SWF_CALL_NAME_PREFIX + this._uid}}
62+
/>
63+
);
64+
}
2365
}
2466
```
25-
```js
26-
// ExternalInterface callbacks are invoked on the DOM node as usual.
27-
var returnValue = ref.getFPDOMNode().myEICallback(...);
28-
```
2967

3068
## Breaking changes
3169

70+
#### 0.13.0
71+
72+
* `getFPVersion` and `isFPVersionSupported` forked to [SWFPlayerVersion](https://github.com/syranide/swf-player-version) and dropped from ReactSWF. Replace `ReactSWF.getFPVersion => SWFPlayerVersion.get` and `ReactSWF.isFPVersionSupported => SWFPlayerVersion.isSupported`.
73+
3274
#### 0.12.3
3375

34-
* Depends on `Object.assign()`, [polyfills are available.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill)
76+
* Depends on `Object.assign()`, [polyfills are available](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill).
3577

3678
#### 0.11.0
3779

@@ -76,24 +118,6 @@ Detailed explanation of most properties found at [[Flash OBJECT and EMBED tag at
76118

77119
## API
78120

79-
#### Static methods
80-
81-
```
82-
getFPVersion()
83-
returns {?string} 'X.Y.Z'-version or null.
84-
85-
Returns installed Flash Player version. Result is cached.
86-
Must not be called in a non-browser environment.
87-
```
88-
```
89-
isFPVersionSupported(versionString)
90-
versionString {string} 'X.Y.Z', 'X.Y' or 'X'.
91-
returns {boolean} true if supported.
92-
93-
Returns if installed Flash Player meets version requirement.
94-
Must not be called in a non-browser environment.
95-
```
96-
97121
#### Instance methods
98122

99123
```

npm-react-swf/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-swf",
3-
"version": "0.12.3",
3+
"version": "0.13.0",
44
"license": "MIT",
55
"description": "Shockwave Flash Player component for React",
66
"author": "Andreas Svensson <[email protected]>",
@@ -12,7 +12,7 @@
1212
"url": "https://github.com/syranide/react-swf"
1313
},
1414
"peerDependencies": {
15-
"react": "^0.14.0-beta1"
15+
"react": "^0.14.0"
1616
},
1717
"keywords": [
1818
"react",

npm-react-swf/react-swf.js

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/*! react-swf v0.12.3 | @syranide | MIT license */
1+
/*! react-swf v0.13.0 | @syranide | MIT license */
22

33
'use strict';
44

55
var React = require('react');
66
var PropTypes = React.PropTypes;
77

8-
var mimeTypeFP = 'application/x-shockwave-flash';
9-
108
/*
119
flashVars = {key: string} or "key=value&..."
1210
@@ -98,92 +96,6 @@ function encodeFlashVarsObject(object) {
9896
}
9997

10098

101-
var memoizedFPVersion;
102-
103-
function getMemoizedFPVersion() {
104-
if (memoizedFPVersion === undefined) {
105-
memoizedFPVersion = getFPVersion();
106-
}
107-
108-
return memoizedFPVersion;
109-
}
110-
111-
/**
112-
* Detect installed Flash Player version. Cached.
113-
*
114-
* @return {?string} 'X.Y.Z'-version or null.
115-
*/
116-
function getFPVersion() {
117-
if (typeof navigator !== 'undefined') {
118-
var navFPPlugin = (
119-
navigator.plugins &&
120-
navigator.plugins['Shockwave Flash']
121-
);
122-
var navFPMimeType = (
123-
navigator.mimeTypes &&
124-
navigator.mimeTypes[mimeTypeFP]
125-
);
126-
127-
if (navFPPlugin && navFPMimeType && navFPMimeType.enabledPlugin) {
128-
try {
129-
return (
130-
navFPPlugin
131-
.description
132-
.match(/(\d+)\.(\d+) r(\d+)/)
133-
.slice(1)
134-
.join('.')
135-
);
136-
} catch (e) {
137-
}
138-
}
139-
}
140-
141-
// ActiveXObject-fallback for IE8-10
142-
if (typeof ActiveXObject !== 'undefined') {
143-
try {
144-
return (
145-
new ActiveXObject('ShockwaveFlash.ShockwaveFlash')
146-
.GetVariable('$version')
147-
.match(/(\d+),(\d+),(\d+)/)
148-
.slice(1)
149-
.join('.')
150-
);
151-
} catch (e) {
152-
}
153-
}
154-
155-
return null;
156-
}
157-
158-
/**
159-
* Detect if installed Flash Player meets version requirement.
160-
*
161-
* @param {string} versionString 'X.Y.Z', 'X.Y' or 'X'.
162-
* @return {boolean} true if supported.
163-
*/
164-
function isFPVersionSupported(versionString) {
165-
var installedString = getMemoizedFPVersion();
166-
167-
if (installedString == null) {
168-
return false;
169-
}
170-
171-
var installedFields = installedString.split('.');
172-
var requiredFields = versionString.split('.');
173-
174-
for (var i = 0; i < 3; i++) {
175-
var installedNumber = +installedFields[i];
176-
var requiredNumber = +(requiredFields[i] || 0);
177-
178-
if (installedNumber !== requiredNumber) {
179-
return installedNumber > requiredNumber;
180-
}
181-
}
182-
183-
return true;
184-
}
185-
186-
18799
/** @constructor */
188100
function ReactSWF(props) {
189101
React.Component.call(this, props);
@@ -229,12 +141,9 @@ function ReactSWF(props) {
229141
};
230142
}
231143

232-
Object.assign(ReactSWF, React.Component);
233144
ReactSWF.prototype = Object.create(React.Component.prototype);
234145
ReactSWF.prototype.constructor = ReactSWF;
235-
236-
ReactSWF.getFPVersion = getMemoizedFPVersion;
237-
ReactSWF.isFPVersionSupported = isFPVersionSupported;
146+
Object.assign(ReactSWF, React.Component);
238147

239148
ReactSWF.propTypes = {
240149
src: PropTypes.string.isRequired,
@@ -313,7 +222,7 @@ ReactSWF.prototype.render = function() {
313222
var objectProps = {
314223
ref: this._refCallback,
315224
children: [],
316-
type: mimeTypeFP,
225+
type: 'application/x-shockwave-flash',
317226
data: state.src,
318227
// Discard `props.src`
319228
src: null

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-swf",
3-
"version": "0.12.3",
3+
"version": "0.13.0",
44
"license": "MIT",
55
"description": "Shockwave Flash Player component for React",
66
"author": "Andreas Svensson <[email protected]>",
@@ -12,7 +12,7 @@
1212
"url": "https://github.com/syranide/react-swf"
1313
},
1414
"peerDependencies": {
15-
"react": "^0.14.0-beta1"
15+
"react": "^0.14.0"
1616
},
1717
"keywords": [
1818
"react",

0 commit comments

Comments
 (0)