Quickstart
Everything you will need to get up and running in 5 mins or less!
Installation
- js
- react
- reactnative
// Install Libraries
npm install @pushprotocol/restapi@latest ethers@^5.7
// Install Libraries
npm install @pushprotocol/restapi@latest ethers@^5.7
// Install Libraries
npm install @pushprotocol/restapi@latest ethers@^5.7
Import libraries
- js
- react
- reactnative
// Import restapi for function calls
import { PushAPI, CONSTANTS } from '@pushprotocol/restapi';
// Ethers or Viem, both are supported
import { ethers } from 'ethers';
// Import restapi for function calls
import { PushAPI, CONSTANTS } from '@pushprotocol/restapi';
// Ethers or Viem, both are supported
import { ethers } from 'ethers';
// Import restapi for function calls
import { PushAPI, CONSTANTS } from '@pushprotocol/restapi';
// Ethers or Viem, both are supported
import { ethers } from 'ethers';
Initialize User
- js
- react
- reactnative
// Creating a random signer from a wallet, ideally this is the wallet you will connect
const signer = ethers.Wallet.createRandom();
// Initialize wallet user, use 'PROD' instead of 'STAGING' for mainnet apps
const userAlice = await PushAPI.initialize(signer, {
env: CONSTANTS.ENV.STAGING,
});
// Creating a random signer from a wallet, ideally this is the wallet you will connect
const signer = ethers.Wallet.createRandom();
// Initialize wallet user, use 'PROD' instead of 'STAGING' for mainnet apps
const userAlice = await PushAPI.initialize(signer, {
env: CONSTANTS.ENV.STAGING,
});
// Creating a random signer from a wallet, ideally this is the wallet you will connect
const signer = ethers.Wallet.createRandom();
// Initialize wallet user, use 'PROD' instead of 'STAGING' for mainnet apps
const userAlice = await PushAPI.initialize(signer, {
env: CONSTANTS.ENV.STAGING,
});
Setup Video Stream
- js
- react
- reactnative
// Initialize Stream
const stream = await userAlice.initStream([CONSTANTS.STREAM.VIDEO]);
// Configure stream listen events and what to do
stream.on(CONSTANTS.STREAM.VIDEO, (data) => {
if (data.event === CONSTANTS.VIDEO.EVENT.REQUEST) {
// handle call request
}
if (data.event === CONSTANTS.VIDEO.EVENT.APPROVE) {
// handle call approve
}
if (data.event === CONSTANTS.VIDEO.EVENT.DENY) {
// handle call denied
}
if (data.event === CONSTANTS.VIDEO.EVENT.CONNECT) {
// handle call connected
}
if (data.event === CONSTANTS.VIDEO.EVENT.DISCONNECT) {
// handle call disconnected
}
});
// Connect Stream
stream.connect();
// Initialize Stream
const stream = await userAlice.initStream([CONSTANTS.STREAM.VIDEO]);
// Configure stream listen events and what to do
stream.on(CONSTANTS.STREAM.VIDEO, (data) => {
if (data.event === CONSTANTS.STREAM.VIDEO.REQUEST) {
// handle call request
}
if (data.event === CONSTANTS.VIDEO.EVENT.APPROVE) {
// handle call approve
}
if (data.event === CONSTANTS.VIDEO.EVENT.DENY) {
// handle call denied
}
if (data.event === CONSTANTS.VIDEO.EVENT.CONNECT) {
// handle call connected
}
if (data.event === CONSTANTS.VIDEO.EVENT.DISCONNECT) {
// handle call disconnected
}
});
// Connect Stream
stream.connect();
// Initialize Stream
const stream = await userAlice.initStream([CONSTANTS.STREAM.VIDEO]);
// Configure stream listen events and what to do
stream.on(CONSTANTS.STREAM.VIDEO, (data) => {
if (data.event === CONSTANTS.STREAM.VIDEO.REQUEST) {
// handle call request
}
if (data.event === CONSTANTS.VIDEO.EVENT.APPROVE) {
// handle call approve
}
if (data.event === CONSTANTS.VIDEO.EVENT.DENY) {
// handle call denied
}
if (data.event === CONSTANTS.VIDEO.EVENT.CONNECT) {
// handle call connected
}
if (data.event === CONSTANTS.VIDEO.EVENT.DISCONNECT) {
// handle call disconnected
}
});
// Connect Stream
stream.connect();
Setup Video State
- js
- react
- reactnative
// data will store the video call state, we will only use this to read the video call state
// and update the UI accordingly
let data = CONSTANTS.VIDEO.INITIAL_DATA;
// setData is a function that will update the video call state
const setData = (fn) => {
data = fn(data);
};
// state to handle current video call data
const [data, setData] = useState(CONSTANTS.VIDEO.INITIAL_DATA);
// data will store the video call state, we will only use this to read the video call state
// and update the UI accordingly
let data = CONSTANTS.VIDEO.INITIAL_DATA;
// setData is a function that will update the video call state
const setData = (fn) => {
data = fn(data);
};
Initialize Video API
- js
- react
- reactnative
// Initialising the video API
const aliceVideoCall = await userAlice.video.initialize(setData, {
stream: stream,
config: {
video: true, // to enable video on start
audio: true, // to enable audio on start
},
media?: MediaStream, // to pass your existing media stream(only for backend use)
});
// Initialising the video API
const aliceVideoCall = await userAlice.video.initialize(setData, {
stream: stream,
config: {
video: true, // to enable video on start
audio: true, // to enable audio on start
},
media?: MediaStream, // to pass your existing media stream(only for backend use)
});
// Initialising the video API
const aliceVideoCall = await userAlice.video.initialize(setData, {
stream: stream,
config: {
video: true, // to enable video on start
audio: true, // to enable audio on start
},
media?: MediaStream, // to pass your existing media stream(only for backend use)
});
Request Video Call
- js
- react
- reactnative
// request a call to a recipient wallet address
await aliceVideoCall.request([recipientWallet]); // see supported wallet standards - https://push.org/docs/video/supported-wallet-standards
// request a call to a recipient wallet address
await aliceVideoCall.request([recipientWallet]); // see supported wallet standards - https://push.org/docs/video/supported-wallet-standards
// request a call to a recipient wallet address
await aliceVideoCall.request([recipientWallet]); // see supported wallet standards - https://push.org/docs/video/supported-wallet-standards
Manage Video Call
- js
- react
- reactnative
// Approve the request, you can also pass the address that we received from the stream listener.
// aliceVideoCall.approve(address?);
await aliceVideoCall.approve();
// or deny the request, you can also pass the address that we received from the stream listener.
// aliceVideoCall.deny(address?);
await aliceVideoCall.deny();
// to disconnect the call
await aliceVideoCall.disconnect();
// to toggle local audio or video
aliceVideoCall.config({ audio: true, video: false });
// Approve the request, you can also pass the address that we received from the stream listener.
// aliceVideoCall.approve(address?);
await aliceVideoCall.approve();
// or deny the request, you can also pass the address that we received from the stream listener.
// aliceVideoCall.deny(address?);
await aliceVideoCall.deny();
// to disconnect the call
await aliceVideoCall.disconnect();
// to toggle local audio or video
aliceVideoCall.config({ audio: true, video: false });
// Approve the request, you can also pass the address that we received from the stream listener.
// aliceVideoCall.approve(address?);
await aliceVideoCall.approve();
// or deny the request, you can also pass the address that we received from the stream listener.
// aliceVideoCall.deny(address?);
await aliceVideoCall.deny();
// to disconnect the call
await aliceVideoCall.disconnect();
// to toggle local audio or video
aliceVideoCall.config({ audio: true, video: false });