Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Bun and Deno runtimes #1051

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/compatibility-check.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isNode } from './functions';
import { isServerRuntime } from './functions';

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

if (!isNode && (!arrayIndexOfSupport || !postMessageSupport)) {
if (!isServerRuntime && (!arrayIndexOfSupport || !postMessageSupport)) {
throw new Error('Sorry, the Vimeo Player API is not available in this browser.');
}
20 changes: 20 additions & 0 deletions src/lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@
export const isNode = typeof global !== 'undefined' &&
({}).toString.call(global) === '[object global]';

/**
* Check to see if this is a bun environment.
* @type {Boolean}
*
* @docs https://bun.sh/guides/util/detect-bun
*/
export const isBun = typeof Bun !== 'undefined';

/**
* Check to see if this is a deno environment.
* @type {Boolean}
*/
export const isDeno = typeof Deno !== 'undefined';

/**
* Check if this is a server runtime
* @type {Boolean}
*/
export const isServerRuntime = isNode || isBun || isDeno;

/**
* Get the name of the method for a given getter or setter.
*
Expand Down
6 changes: 3 additions & 3 deletions src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'weakmap-polyfill';
import Promise from 'native-promise-only';

import { storeCallback, getCallbacks, removeCallback, swapCallbacks } from './lib/callbacks';
import { getMethodName, isDomElement, isVimeoUrl, getVimeoUrl, isNode } from './lib/functions';
import { getMethodName, isDomElement, isVimeoUrl, getVimeoUrl, isServerRuntime } from './lib/functions';
import {
getOEmbedParameters,
getOEmbedData,
Expand Down Expand Up @@ -1344,8 +1344,8 @@ class Player {
}
}

// Setup embed only if this is not a node environment
if (!isNode) {
// Setup embed only if this is not a server runtime
if (!isServerRuntime) {
screenfull = initializeScreenfull();
initializeEmbeds();
resizeEmbeds();
Expand Down