Skip to content

Commit f6d6951

Browse files
Merge pull request #1051 from Marcdj-02/master
Support Bun and Deno runtimes
2 parents 00c134c + 9b34178 commit f6d6951

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

src/lib/compatibility-check.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { isNode } from './functions';
1+
import { isServerRuntime } from './functions';
22

33
const arrayIndexOfSupport = typeof Array.prototype.indexOf !== 'undefined';
44
const postMessageSupport = typeof window !== 'undefined' && typeof window.postMessage !== 'undefined';
55

6-
if (!isNode && (!arrayIndexOfSupport || !postMessageSupport)) {
6+
if (!isServerRuntime && (!arrayIndexOfSupport || !postMessageSupport)) {
77
throw new Error('Sorry, the Vimeo Player API is not available in this browser.');
88
}

src/lib/functions.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@
33
*/
44

55
/**
6-
* Check to see this is a node environment.
7-
* @type {Boolean}
6+
* Check to see this is a Node environment.
7+
* @type {boolean}
88
*/
99
/* global global */
1010
export const isNode = typeof global !== 'undefined' &&
1111
({}).toString.call(global) === '[object global]';
1212

13+
/**
14+
* Check to see if this is a Bun environment.
15+
* @see https://bun.sh/guides/util/detect-bun
16+
* @type {boolean}
17+
*/
18+
export const isBun = typeof Bun !== 'undefined';
19+
20+
/**
21+
* Check to see if this is a Deno environment.
22+
* @see https://docs.deno.com/api/deno/~/Deno
23+
* @type {boolean}
24+
*/
25+
export const isDeno = typeof Deno !== 'undefined';
26+
27+
/**
28+
* Check if this is a server runtime
29+
* @type {boolean}
30+
*/
31+
export const isServerRuntime = isNode || isBun || isDeno;
32+
1333
/**
1434
* Get the name of the method for a given getter or setter.
1535
*

src/player.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'weakmap-polyfill';
44
import Promise from 'native-promise-only';
55

66
import { storeCallback, getCallbacks, removeCallback, swapCallbacks } from './lib/callbacks';
7-
import { getMethodName, isDomElement, isVimeoUrl, getVimeoUrl, isNode, logSurveyLink } from './lib/functions';
7+
import { getMethodName, isDomElement, isVimeoUrl, getVimeoUrl, isServerRuntime, logSurveyLink } from './lib/functions';
88
import {
99
getOEmbedParameters,
1010
getOEmbedData,
@@ -1351,8 +1351,8 @@ class Player {
13511351
}
13521352
}
13531353

1354-
// Setup embed only if this is not a node environment
1355-
if (!isNode) {
1354+
// Setup embed only if this is not a server runtime
1355+
if (!isServerRuntime) {
13561356
screenfull = initializeScreenfull();
13571357
initializeEmbeds();
13581358
resizeEmbeds();

0 commit comments

Comments
 (0)