1.2.6 • Published 1 year ago

@skywatch/react v1.2.6

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

Installation

Step 1

npm install @skywatch/react

or

yarn add @skywatch/react

Step 2

Option 1:

Use Oauth 2.0 to get access token

Option 2:

Before you start developing, you have to implement Skywatch library on your server. Please follow the guide below to create a POST method url on your server, and then keep the POST method url you generated.

Ex. Implement Skywatch library on node server, and then generate the POST API - https://localhost:3000/skywatch_service_url

Guide:

Skywatch Server Installation Guide

Usage

import React, {useState, useEffect} from 'react';
import {ArchivesPlayer, initialize} from '@skywatch/react';

const APP = () => {
  const [player, setPlayer] = useState(null);

  useEffect(() => {
    initialize('/your_server_url_with_skywatch_library', 'token');
  }, []);

  const options = {
    autoplay: true,
    muted: true,
    aspectRatio: '16:9',
    mobileView: false,
  };

  return (
    <ArchivesPlayer
      onPlayerInit={setPlayer}
      onPlayerDispose={setPlayer}
      deviceId={'1234'}
      archiveId={'123456'}
      smart_ff={0}
      seek={0}
      playerOptions={options}
    />
  );
};

API Document

initialize

This method is required before using any Skywatch API.

import Skywatch from '@skywatch/react';

Skywatch.initialize('/your_server_url_with_skywatch_library', 'token');

ArchivesPlayer

This is a component for playing archive video.

<ArchivesPlayer
  onPlayerInit={}
  onPlayerDispose={}
  deviceId={}
  archiveId={}
  smart_ff={}
  seek={}
  playerOptions={}
  style={}
  controls={}
  onTimeUpdate={}
  onEnded={}
  onReady={}
/>
PropertyTypeRequiredDefaultDescription
onPlayerInitfunctionYESPass state into player to allow control of player. For more info please check Video.js doc.
onPlayerDisposeFunctionYESPass state into player to dispose when video is released.
deviceIdstringYESDecide on which camera is going to play.
archiveIdstringYESDecide on which archive is going to play.
smart_ffnumberNO00 -> close, 1 -> open
seeknumberNO0Jump to specific time when video begins to play.
playerOptionsobjectNO{ autoplay: true, muted: true, aspectRatio: '16:9', mobileView: false, };Video option setting. For more info please check Video.js doc.
styleinline-styleNOCustom style for video player.
controlsboolNOtrueShow video controls
onTimeUpdatefuncNOCallback fired when the current playback position has changed
onEndedfuncNOCallback fired when the end of the media resource is reached
onReadyfuncNOCallback fired when the video is ready to play

FlvPlayer

This is a component for playing live streaming.

<FlvPlayer
  deviceId={}
  onPlayerInit={}
  onPlayerDispose={}
  style={}
  controls={}
  onReady={}
/>
PropertyTypeRequiredDefaultDescription
deviceIdstringYESDecide on which camera is going to play.
onPlayerInitfunctionYESPass state into player to allow control of player. For more info please check flv.js doc.
onPlayerDisposefunctionYESPass state into player to dispose when video is released.
styleinline-styleNOCustom style for video player.
controlsboolNOtrueShow video controls
onReadyfuncNOCallback fired when the video is ready to play

CameraView

This is a component for playing live streaming and archive video.

<CameraView deviceId={} renderLoading={} />

You need to import the CSS file to your JavaScript file

import '@skywatch/react/lib/style/camera-view.css';

Custom Style

If you want to overwrite the default style, you can use the browser dev tool to find out the id/class of the element, and create your own CSS file to overwrite it.

/* overwrite.css */
#controlbar_container {
  background-color: burlywood;
}
.meta_timeline_i {
  background-color: coral !important;
}

Then, import the overwrite.css file

import '@skywatch/react/lib/style/camera-view.css';
import 'overwrite.css';

Custom Controls

Methods to control the video are exposed by useImperativeHandle hook. To access these methods, you need to create your ref and pass it to CameraView component. Also, you have to disable the default controls. Then you can use the exposed methods by the ref. For example,

const APP = () => {
  const cameraViewRef = useRef();
  return (
    <>
      <CameraView deviceId={DEVICE_ID} controls={false} ref={cameraViewRef} />
      <button onClick={() => cameraViewRef.current.play()}>play</button>
      <button onClick={() => cameraViewRef.current.pause()}>pause</button>
    </>
  );
};

Methods

MethodParametersReturnsDescription
play()nonenonePlay the video.
pause()nonenonePause the current video.
fastForward()nonenoneStart fast forward mode.
toggleMute()nonenoneMute or unmute the video.
goLive()nonenoneStart playing live video.
seek(string)Number\|StringnonePlay video at the provided unix timestamp.
getAllArchives()nonearrayGet data of all archives.
isLive()noneboolCheck if the video is in live mode.

Props

PropertyTypeRequiredDefaultDescription
deviceIdstringYESDecide on which camera is going to play.
renderLoadingfunctionNO() => <div style={loadingStyle}></div>Function returns the loading element.
controlsboolNOtrueIf false, the default controls will not be used.

License

  • This project is inspired by video.js.
  • This project is inspired by flv.js.
  • Licensed under the Apache License, Version 2.0 (the "License");
1.2.6

1 year ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.0

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago