-
-
Notifications
You must be signed in to change notification settings - Fork 2
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
asciinema-player with React #251
Comments
When you use it in your React-driven page, do you embed the player outside of your React tree, or you add |
Directly in jsx! Is it wrong? |
I don't think this will work our of the box. Maybe we could expose the component directly, without the wrapper, so it can be used within existing React component tree. Not sure how to do that yet though. |
Hmmm, interesting thought. I`ll try it! Whait for response :) |
@sickill So is there no way of using the asciinema player inside a react component? Should I try the iframe route: <div className={styles.playerContainer}>
<iframe src="https://asciinema.org/a/113463/iframe">
</iframe>
</div> This doesn't work for me though. Working my way through this, but I was wondering what the recommended workaround at the moment is? EDIT: Doesn't work because:
|
Looks like you just found a bug with iframe embedding ;) I need to modify or remove this X-Frame-Options header. |
Ah, and now I see you already suggested solution in the other issue, thx! |
I can confirm that the iframe embed works with react. Minor issues with fullscreen at: asciinema/asciinema-server#286 (comment) |
I’m hoping to add hosted asciicasts to my React site. Has anyone had any further luck or tips for using the self hosted player in React? |
The player component is reagent component, and it seems it can be converted into native React component as described here: https://github.com/reagent-project/reagent/blob/master/docs/InteropWithReact.md#creating-react-components-from-reagent-components The released It seems to me that in order to support consuming it as React component it would be better if asciinema-player was released as npm package with React defined as proper npm dependency, without bundled React code in the player itself, and with a proper way to Latest versions of ClojureScript compiler made lots of improvements for integrating with node/npm so I think it's something we could try implementing already. |
A React npm package would be fantastic! |
A standalone version would be great; But for now I have included the CSS and JS file as static assets, and I've written a simple wrapper for now: class Asciinema extends React.Component {
render() {
return (
<asciinema-player
src={this.props.src}
preload
poster="npt:0:3"
idle-time-limit="2"
/>
);
}
}
...
<Asciinema src='/example.cast'/> The full screen functionality doesn't resize the text as I would have expected, but I believe this isn't supported out of the box currently. Update: I noticed some weird quirks the directly using the above custom I am now directly using the class Asciinema extends React.Component {
static defaultProps = {
theme: 'monokai',
idleTimeLimit: 2,
poster: 'npt:0:3'
};
bindRef = (ref) => {
this.ref = ref;
};
componentDidMount() {
asciinema.player.js.CreatePlayer(
this.ref,
this.props.src,
this.props
);
}
componentWillUnmount() {
if (!this.ref) return;
asciinema.player.js.UnmountPlayer(this.ref);
this.ref = null;
}
render() {
return (
<div ref={this.bindRef}/>
);
}
} Example usage: <Asciinema src='/example.cast'/>
<Asciinema src='/example.cast' theme='etc' /> |
Have there been any updates on an npm package for a React player? Looking forward to this to use in my React websites and slide decks. |
@AlanFoster I've tried to use your suggestions without success. Would you mind publishing your wrapping pieces as to npm for others to use directly in React applications without having to download and host the static .js and .css files? |
@trevordmiller The API for refs changed in the latest versions of React, what version are you currently using? As you might have to tweak the example code a little if you're using the latest and greatest react |
@AlanFoster Callback refs like you are using work in latest react as well as previous versions and I've also tried |
I've also considered using a tool like xterm to embed a terminal directly in my slides, with |
@sickill is there any news on releasing proper npm package? I'm interested in creating minimal asciinema editor in react, and so far I'm getting hit hard by need for learning tooling system of clojure & java, which is demotivating. Namely I tried to install |
@ultrox One thing you can try is to play along with the travis build log. The winning move for me was to install java10.
|
@AlanFoster this functions are coming from asciinema-player.js file.But the problem is that it says to me Unresolved function or method CreatePlayer and UnmountPlayer.How can i solve this ?
|
@Zeljkomk You can add asciinema-player.js to your HTML page, then call |
@AlanFoster's solution works very well! |
@AlanFoster , not sure why I'm getting 'asciinema' is not defined Tried importing it multiple (incorrect) ways.. import "./asciinema-player"; (having it locally in the component path) Also tried putting a <script> tag in index.html placing asciinema-player,js in public.... |
- Based on https://www.figma.com/file/AHM9ZSowavRtfl8E21ZHQc/Home-Page?node-id=33%3A3 - Dark green-blue background for features list and footer - All cyan feature headings - Matched the asciinema component's color scheme to the site style - Blue Netlify badge to match new site color scheme Functional improvements: - Self-hosted asciinema component based on suggestions at: * https://github.com/asciinema/asciinema-player#self-hosting-quick-start * https://github.com/asciinema/asciinema-player/issues/72#issuecomment-380950743 - Menus have a subtle pink on hover
I was able to get this integration working by following @AlanFoster's approach. Just thought I'd share a Hooks example in case others find it useful! I am using it in a Gatsby project so the inclusion of the |
👌 |
The next version of the player (3.0, see It's also a rewrite from ClojureScript to modern JS. For rendering it doesn't use React.js anymore, instead it uses small and fast Solid.js. There's been several different issues raised in this thread and I hope the new version will address most, if not all, of them 🤞 It's around the corner, there's just a few small missing bits I plan to address in next few weeks. I plan to publish a series of alpha/beta releases to npmjs.org and would love a feedback from you 🙌 |
The new version of the player has been published to npmjs.org (currently at 3.0.0-rc.1). Feel free to give it a spin. Check out the updated self-hosting quick-start guide: https://github.com/asciinema/asciinema-player#quick-start |
Anyone coming here who is still confused on how to use Asciinema with React, see the following example: npm install --save-dev asciinema-player@3.0.0-rc.1 import React, { useEffect, useRef } from 'react';
import * as AsciinemaPlayerLibrary from 'asciinema-player';
type AsciinemaPlayerProps = {
src: string;
// START asciinemaOptions
cols: string;
rows: string;
autoPlay: boolean
preload: boolean;
loop: boolean | number;
startAt: number | string;
speed: number;
idleTimeLimit: number;
theme: string;
poster: string;
fit: string;
fontSize: string;
// END asciinemaOptions
};
const AsciinemaPlayer: React.FC<AsciinemaPlayerProps> = ({
src,
...asciinemaOptions
}) => {
const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
const currentRef = ref.current;
AsciinemaPlayerLibrary.create(src, currentRef, asciinemaOptions);
}, [src]);
return <div ref={ref} />;
};
export default AsciinemaPlayer; Use like so: import AsciinemaPlayer from './components/AsciinemaPlayer';
import 'asciinema-player/dist/bundle/asciinema-player.css'; <AsciinemaPlayer src="/fseval/cast/examples_quick_start.cast" rows={30} idleTimeLimit={3} preload={true} /> 🎉 |
Works for me!!! Well done and thank you. |
So for anyone who runs into a double rendering problem with react 18, here is my solution, including typescript types: AsciinemaPlayer.tsx: import React, { useEffect, useRef, useState } from 'react';
import 'asciinema-player/dist/bundle/asciinema-player.css';
type AsciinemaPlayerProps = {
src: string;
// START asciinemaOptions
cols?: string;
rows?: string;
autoPlay?: boolean
preload?: boolean;
loop?: boolean | number;
startAt?: number | string;
speed?: number;
idleTimeLimit?: number;
theme?: string;
poster?: string;
fit?: string;
fontSize?: string;
// END asciinemaOptions
};
function AsciinemaPlayer ({src, ...asciinemaOptions}: AsciinemaPlayerProps) {
const ref = useRef<HTMLDivElement>(null);
const [player, setPlayer] = useState<typeof import("asciinema-player")>()
useEffect(() => {
import("asciinema-player").then(p => {setPlayer(p)})
}, [])
useEffect(() => {
const currentRef = ref.current
const instance = player?.create(src, currentRef, asciinemaOptions);
return () => {instance?.dispose()}
}, [src, player, asciinemaOptions]);
return <div ref={ref} />;
}
export default AsciinemaPlayer asciinema-player.d.ts: declare module "asciinema-player" {
export function create(
src: string,
element: HTMLElement | null,
// START asciinemaOptions
opts: {
cols?: string,
rows?: string,
autoPlay?: boolean,
preload?: boolean,
loop?: boolean | number,
startAt?: number | string,
speed?: number,
idleTimeLimit?: number,
theme?: string,
poster?: string,
fit?: string,
fontSize?: string
}
)
} |
Does anyone has an example that works with nextjs , react 18 and typescript please ? |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hello.
Asciinema player has very strange behavior in my small React project. On static page with same parametrs it works perfetct both online and offline. On React it doesn't work properly. It shows on page, but when I click on play button it start endless loading. Also there is no any errors in console.
Anybody know how to fix it?
Thanks.
The text was updated successfully, but these errors were encountered: