🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@interactify-live/player-react

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@interactify-live/player-react

A React component for playing interactive media with MQTT connectivity.

latest
npmnpm
Version
1.0.24
Version published
Maintainers
1
Created
Source

@interactify-live/player-react

A React component for playing interactive media with MQTT connectivity.

Features

  • Video and image playback
  • Interactive elements overlay
  • MQTT real-time messaging
  • Connection status management
  • Message subscription capabilities

Installation

npm install @interactify-live/player-react

Basic Usage

import React, { useRef } from "react";
import {
  InteractifyPlayer,
  InteractifyPlayerHandle,
} from "@interactify-live/player-react";

function App() {
  const playerRef = useRef<InteractifyPlayerHandle>(null);

  const handleStatusChange = (status: string) => {
    console.log("Connection status:", status);
  };

  const handleMessagesReceived = (messages: any[]) => {
    console.log("New messages received:", messages);
    // Handle new messages here
  };

  return (
    <InteractifyPlayer
      ref={playerRef}
      media={{
        id: "video1",
        type: "video",
        url: "https://example.com/video.mp4",
      }}
      interactions={[]}
      options={{
        user_id: "user123",
        token: "your-token",
        scope: "short",
        space_slug: "space1",
        slug: "video1",
        session: "session123",
      }}
      onStatusChange={handleStatusChange}
      onMessagesReceived={handleMessagesReceived}
    />
  );
}

Advanced Usage - Manual Message Subscription

You can also subscribe to messages manually using the player ref:

import React, { useRef, useEffect } from "react";
import {
  InteractifyPlayer,
  InteractifyPlayerHandle,
} from "@interactify-live/player-react";

function App() {
  const playerRef = useRef<InteractifyPlayerHandle>(null);

  useEffect(() => {
    if (playerRef.current) {
      // Subscribe to new messages
      const unsubscribe = playerRef.current.subscribeToNewMessages(
        (message) => {
          console.log("New message received:", message.text);
          console.log("From:", message.display_name);
          console.log("Timestamp:", message.created_at);
        }
      );

      // Cleanup subscription on unmount
      return unsubscribe;
    }
  }, []);

  return (
    <InteractifyPlayer
      ref={playerRef}
      media={{
        id: "video1",
        type: "video",
        url: "https://example.com/video.mp4",
      }}
      interactions={[]}
      options={{
        user_id: "user123",
        token: "your-token",
        scope: "short",
        space_slug: "space1",
        slug: "video1",
        session: "session123",
      }}
      onNewMessageReceived={(message) => {
        console.log("New message received:", message.text);
      }}
    />
  );
}

Sending Messages

You can send messages using the player ref:

const handleSendMessage = () => {
  if (playerRef.current) {
    playerRef.current.sendMessage({
      text: "Hello, world!",
      displayName: "User Name",
      avatar: "https://example.com/avatar.jpg",
      visible: true,
    });
  }
};

Publishing Events

You can publish events (like "like" actions):

const handleLike = () => {
  if (playerRef.current) {
    playerRef.current.publishEvent("like");
  }
};

Props

InteractifyPlayerProps

PropTypeRequiredDescription
mediaMediaObjectYesMedia configuration
interactionsany[]YesArray of interactive elements
optionsConnectionOptionsNoMQTT connection options
onStatusChange(status: string) => voidNoConnection status callback
onNewMessageReceived(message: any) => voidNoNew message received callback
autoPlaybooleanNoAuto-play media (default: false)
mutedbooleanNoMute media (default: false)
loopbooleanNoLoop media (default: false)
isDraggablebooleanNoEnable interaction dragging (default: true)

MediaObject

interface MediaObject {
  id: string;
  type: "video" | "image";
  url: string;
  thumbnail?: string;
  alt?: string;
}

ConnectionOptions

interface ConnectionOptions {
  user_id: string;
  token: string;
  scope: "short" | "live";
  space_slug: string;
  slug: string;
  session: string;
  display_name: string;
  brokerUrl?: string;
}

Methods

InteractifyPlayerHandle

MethodParametersReturnsDescription
play()-voidPlay the media
pause()-voidPause the media
mute()-voidMute the media
unmute()-voidUnmute the media
getCurrentTime()-numberGet current playback time
setCurrentTime(time)numbervoidSet playback time
isMuted()-booleanCheck if muted
isPlaying()-booleanCheck if playing
sendMessage(message)MessageObjectvoidSend a chat message
publishEvent(type)stringvoidPublish an event
subscribeToNewMessages(callback)(message: any) => void() => voidSubscribe to new messages

MessageObject

interface MessageObject {
  text: string;
  avatar?: string;
  displayName?: string;
  visible?: boolean;
  replyTo?: {
    text: string;
    userID: string;
    displayName: string;
  };
}

Message Structure

Messages received from the MQTT connection have the following structure:

interface ShortMessage {
  avatar: string;
  text: string;
  created_at: string;
  user_id: string;
  display_name: string;
  live_slug: string;
  space_slug: string;
  visible: boolean;
  slug: string;
  reply_to?: {
    text: string;
    user_id: string;
    display_name: string;
  };
}

Connection Status

The connection can have the following statuses:

  • "CONNECTING" - Attempting to connect
  • "CONNECTED" - Successfully connected
  • "RECONNECTING" - Attempting to reconnect
  • "OFFLINE" - Disconnected
  • "ERROR" - Connection error

License

ISC

FAQs

Package last updated on 13 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts