Giter Site home page Giter Site logo

pspglb / react-guacamole-player Goto Github PK

View Code? Open in Web Editor NEW

This project forked from goodwinfame/react-guacamole-player

0.0 0.0 0.0 315 KB

A React Component can play guacamole session

License: MIT License

TypeScript 81.90% HTML 0.24% JavaScript 5.53% Less 12.34%

react-guacamole-player's Introduction

react-guacamole-player

npm Version Dependencies

This reusable React component that can play guacamole session recordings uses guacamole-common-js as it's rendering core.

Requirement

  • The player is built based on React Hooks. It requires the React version >= 16.8.
  • The server side which provides session recordings needs to support Range-Content header.

Install

yarn add react-guacamole-player

or

npm i -S react-guacamole-player

Example

import React, { useState } from 'react';
import GuacaPlayer from 'react-guacamole-player'


/**
 * src is the session log URL
*/
const App: React.FC = () => {
    const [src, setSrc] = useState("");
    return (
        <div>
            <GuacaPlayer src={src}/>
        </div>
    )
}

Controlled Player Size

import React, { useState } from 'react';
import GuacaPlayer from 'react-guacamole-player'

const App: React.FC = () => {
    const [src, setSrc] = useState("");
    return (
        <div>
            <GuacaPlayer src={src} width={500} height={400}/>
        </div>
    )
}

Disable Autoplay

import React, { useState } from 'react';
import GuacaPlayer from 'react-guacamole-player'


/**
 * The player will autoplay by default
*/
const App: React.FC = () => {
    const [src, setSrc] = useState("");
    return (
        <div>
            <GuacaPlayer src={src} autoPlay={false}/>
        </div>
    )
}

Outside Control

import React, { useState, useCallback } from 'react';
import GuacaPlayer from 'react-guacamole-player'


/**
 * Player is an object contains the following callbacks:
 * 
 * play: Function;
 * pause: Function;
 * seek: (e: {inputValue: number}) => Promise<unknown>;
 * cancelSeek: Function;
 * getDuration: () => Promise<number>;
 * getCurrentDuration: () => Promise<number>;
 * 
*/
const App: React.FC = () => {
    const [src, setSrc] = useState("");
    const [player, setPlayer] = useState<null | Player>(null);

    const jumpTo = useCallback(()=>{
        // inputValue units ms
        player && player.seek({inputValue: 10000})
    }, [player])

    return (
        <div>
            <button onClick={jumpTo}>Go to 00:10</button>
            <GuacaPlayer src={src} getPlayer={(player)=>{
                setPlayer(player)
            }}/>
        </div>
    )
}

Internationalization

import React, { useState, useCallback } from 'react';
import GuacaPlayer from 'react-guacamole-player'


/**
 * translate is a callback which returns a translation object.
*/
const App: React.FC = () => {
    const [src, setSrc] = useState("");

    const translate = useCallback((default)=>{
        return {
            ...default,
            "btn.loading": "Your translation...",
        }
    }, [])

    return (
        <div>
            <GuacaPlayer src={src} translate={translate}/>
        </div>
    )
}

Dev the project

yarn start

or

npm start

Build library

yarn run build

or

npm run build

License

MIT

react-guacamole-player's People

Contributors

goodwinfame avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.