plex-websocket

1.0.3 • Public • Published

Read Github README, in case of unpublished changes

Plex-Websocket

A tool to allow JavaScript and Typescript users to aquire the full power of plex-api with Websockets
YOU DO NOT NEED TO INSTALL plex-api IT COMES WITH THE MODULE
Please note that plex-api has no type declarations so installing it might be better

npm install plex-websocket

Features

Quickly connect to a remote Plex Media Server by using a well known JavaScript Plex API tool plex-api

This will work with the plex-api authenticator tool. The websocket just needs the authToken which is provided either by you or by the authenticator module

const LOGININFO = {
    hostname: "255.255.255.255",
    username: "example@gmail.com",
    token: "app.plex.tv/desktop => Inspect => Application => Local Storage => myPlexAccessToken"
}; // Login information of the Plex Media User
const PlexAPI = require("plex-api");
const PlexLogin = new PlexAPI(LOGININFO); // Login with plex-api

function onPacket(type, data) {
    if (type === PlexWebsocket.WebsocketClient.PACKETTYPES.PLAYING) {
        console.log("\nPlaying State Change");
        console.log("Session IDs: ", data.PlaySessionStateNotification.map(session => session.sessionKey).join(", "));
        console.log("Rating Keys: ", data.PlaySessionStateNotification.map(session => session.ratingKey).join(", "));
        console.log("States: ", data.PlaySessionStateNotification.map(session => session.state).join(", "));
    }
} // Create a function for receiving packets

// Create a WebsocketClient with the create plex-api login and onPacket function
const WSClient = new PlexWebsocket.WebsocketClient(PlexLogin, onPacket);
WSClient.websocket.on("connect", () => console.log("Connected")); // When a successful connection is made
WSClient.websocket.on("error", err => console.log("Error\n", err)); // When an error occurs (Will terminate program)
WSClient.websocket.on("debug", message => console.log("Debug\n", message)); // Debug event for errors

Test Script

npm test

Script Location
Ensure that LOGININFO has been filled in with your information

const LOGININFO = {
    hostname: "255.255.255.255",
    username: "example@gmail.com",
    token: "app.plex.tv/desktop => Inspect => Application => Local Storage => myPlexAccessToken"
};

Package Sidebar

Install

npm i plex-websocket

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

18.7 kB

Total Files

10

Last publish

Collaborators

  • forbidden_duck