Replies: 32 comments
-
When you use it in your React-driven page, do you embed the player outside of your React tree, or you add |
Beta Was this translation helpful? Give feedback.
-
Directly in jsx! Is it wrong? |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Hmmm, interesting thought. I`ll try it! Whait for response :) |
Beta Was this translation helpful? Give feedback.
-
@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:
|
Beta Was this translation helpful? Give feedback.
-
Looks like you just found a bug with iframe embedding ;) I need to modify or remove this X-Frame-Options header. |
Beta Was this translation helpful? Give feedback.
-
Ah, and now I see you already suggested solution in the other issue, thx! |
Beta Was this translation helpful? Give feedback.
-
I can confirm that the iframe embed works with react. Minor issues with fullscreen at: asciinema/asciinema-server#286 (comment) |
Beta Was this translation helpful? Give feedback.
-
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? |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
A React npm package would be fantastic! |
Beta Was this translation helpful? Give feedback.
-
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' /> |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@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? |
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
I've also considered using a tool like xterm to embed a terminal directly in my slides, with |
Beta Was this translation helpful? Give feedback.
-
@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 |
Beta Was this translation helpful? Give feedback.
-
@ultrox One thing you can try is to play along with the travis build log. The winning move for me was to install java10.
|
Beta Was this translation helpful? Give feedback.
-
@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 ?
|
Beta Was this translation helpful? Give feedback.
-
@Zeljkomk You can add asciinema-player.js to your HTML page, then call |
Beta Was this translation helpful? Give feedback.
-
@AlanFoster's solution works very well! |
Beta Was this translation helpful? Give feedback.
-
@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.... |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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 🙌 |
Beta Was this translation helpful? Give feedback.
-
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://docs.asciinema.org/manual/player/quick-start/ |
Beta Was this translation helpful? Give feedback.
-
Anyone coming here who is still confused on how to use Asciinema with React, see the following example: npm install --save-dev [email protected] 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} /> 🎉 |
Beta Was this translation helpful? Give feedback.
-
Works for me!!! Well done and thank you. |
Beta Was this translation helpful? Give feedback.
-
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
}
)
} |
Beta Was this translation helpful? Give feedback.
-
Does anyone has an example that works with nextjs , react 18 and typescript please ? |
Beta Was this translation helpful? Give feedback.
-
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.
Beta Was this translation helpful? Give feedback.
All reactions