1.0.14 • Published 6 months ago

@veyetals/react-vitals-online v1.0.14

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

react-vitals-online

Made with create-react-library

NPM JavaScript Style Guide

Install

npm install @veyetals/react-vitals-online

Usage

username: username to authenticate user.

password: password to authenticate user.

channelName: Required* Create Channel to connect to for video and veyetals scanning. Maximum length: 128 characters. May include numbers, letters, underscores (_), and hyphens (-).

application: ie. 'veyetals'

platform: ie. 'ios'

environment: ie. 'prd' / 'stg'

userType: either 'master' or 'viewer.

mode: either 'video' or 'audio.

onCallEnd: Function to be called when user ends call.

onVitalsCompleted: Function to be called when veyetals is completed.

useWebSocket

isConnected: indicates connection to socket - true or false

connect: function to connect to socket *connection limit: 2 hrs

Arguments: userId

callUser: function to send info needed for a call

Arguments: userId, recipientId, channelName, mode

answerCall: function to notify caller of answer

Arguments: callerId, callerConnectionId, userId, answer

socketMessage: messages from socket

functionuserdescriptionsocketMessage
callUsercallerrecipient is not in db{ status: 'callFailed', message: "recipientId not found" }
callUsercallerrecipient is offline{ status: 'callFailed', message: "recipientId is offline" }
callUserrecipientrecipient receives caller info{ status: 'callIncoming', callerId: 'callerId', callerConnectionId: 'callerConnectionId', channelName: 'channelName', mode: 'mode' }
answerCallrecipientcaller is offline{ status: 'answerFailed', message: "recipientId is offline" }
answerCallcallercaller receives answer from callee{ status: "answerToCall", recipientId: 'recipientId', answer: true \ false }

Example

import React, { useState } from 'react'

import { VitalsOnline, useWebSocket } from '@veyetals/react-vitals-online'

import '@veyetals/react-vitals-online/dist/index.css'

export default function App() {
  const {
    isConnected,
    socketMessage,
    connect,
    disconnect,
    callUser,
    answerCall
  } = useWebSocket()

  const [active, setActive] = useState(false)

  const [username, setUsername] = useState('')
  const [password, setPassword] = useState('')
  const [channelName, setChannelName] = useState('testChannel')
  const [userType, setUserType] = useState('master')
  const [mode, setMode] = useState('video')

  const [callerId, setCallerId] = useState('')
  const [recipientId, setRecipientId] = useState('')
  const [callerConnectionId, setCallerConnectionId] = useState('')
  const [callAnswer, setCallAnswer] = useState('')

  const startMaster = () => {
    setUserType('master')
    setActive(true)
  }

  const startViewer = () => {
    setUserType('viewer')
    setActive(true)
  }

  // Callback function to receive the final reading from the component
  const handleVitalsCompleted = (vitals) => {
    console.log(vitals)
  }

  // Callback function for message from mobile call
  const handleOnMobileCall = (resp) => {
    console.log('handleOnMobileCall: ', resp)
  }

  useEffect(() => {
    console.log('socketMessage: ', socketMessage)
  }, [socketMessage])

  return (
    <div>
      <span>isConnected: {isConnected.toString()}</span>
      <button onClick={() => connect(username)}>Connect</button>
      <label>
        recipientId:
        <input
          type='text'
          value={recipientId}
          onChange={(e) => setRecipientId(e.target.value)}
        />
      </label>
      <button
        onClick={() => callUser(username, recipientId, channelName, mode)}
      >
        Call
      </button>
      <label>
        callerId:
        <input
          type='text'
          value={callerId}
          onChange={(e) => setCallerId(e.target.value)}
        />
      </label>
      <label>
        callerConnectionId:
        <input
          type='text'
          value={callerConnectionId}
          onChange={(e) => setCallerConnectionId(e.target.value)}
        />
      </label>
      <label>
        callAnswer:
        <input
          type='text'
          value={callAnswer}
          onChange={(e) => setCallAnswer(e.target.value)}
        />
      </label>
      <button
        onClick={() =>
          answerCall(callerId, callerConnectionId, username, callAnswer)
        }
      >
        answerCall
      </button>
      <button onClick={startMaster}>startMaster</button>;
      <button onClick={startViewer}>startViewer</button>;
      {active && (
        <VitalsOnline
          username={username}
          password={password}
          channelName={channelName}
          application={application}
          platform={platform}
          environment={environment}
          userType={userType}
          mode={mode}
          onCallEnd={() => setActive(false)}
          onMobileCall={handleOnMobileCall}
          onVitalsCompleted={handleVitalsCompleted}
        />
      )}
    </div>
  )
}

License

MIT ©

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

9 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

12 months ago