Socket
Socket
Sign inDemoInstall

real-time-tv

Package Overview
Dependencies
52
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    real-time-tv

Real-time video player component built with react and socket.io


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
8.66 MB
Created
Weekly downloads
 

Readme

Source

RealTimeTV

Travis npm package Coveralls

RealTime-TV

built with Create React App redux and socket.io.

Check it out

Real-Time TV then open another tab to the same url and paste a youtube url in and watch the rtc magic happen.

Installing and using the component

npm i --save real-time-tv

Unfortunately The Component was ejected as such, to enable the css it has to be used with an ejected app using css modules plugin.

or clone the git repo and run in dev server port is set to 5000.

npm install
npm start 

your server will have to respond to the following events

`newVideo` event
`isReady` event
`stateChange` event
`placeChange` event

here is the example server responding to the events

io.on("connection", socket => {
    const userId = socket.id;
    connIds.push(userId);

    // newVideo event
    socket.on("newVideo", vidObj => {
        const objSend = {
            url: vidObj.url,
            id: vidObj.vidId,
            screenState: vidObj.screenState,
            controlId: vidObj.controlId
        };
        io.emit("updateVideo", objSend);
    });

    // isReady when all are ready emit allIsReady
    socket.on("isReady", socketId => {
        clientIds.push(socketId.ids);

        let objSend = {
            msg: null
        };
        const clients = Object.keys(io.sockets.sockets);

        promisePoller({
                taskFn: () => {
                    return new Promise((resolve, reject) => {
                        if (clients.length === clientIds.length) {
                            resolve(true);
                        } else {
                            reject(`${clients.length - clientIds.length}`);
                        }
                    });
                },
                interval: 500,
                retries: 5,
            })
            .then(poll => {
                if (poll === true) {
                    io.emit("allIsReady");
                }
            }).catch(err => {
                objSend.msg = `${err[err.length]} user(s) not connected.`;
                io.emit("allIsReady", objSend);
            });
    });

    // stateChange event
    socket.on("stateChange", stateObj => {

        const objSend = {
            state: stateObj.state
        };
        socket.broadcast.emit("updateState", objSend);
    });

    // placeChange event
    socket.on("placeChange", placeObj => {

        const objSend = {
            place: placeObj.ytPlace
        };
        io.emit("updatePlace", objSend);
    });

    socket.on("disconnect", () => {
        console.log(`user disconnected`);
        const id = socket.id;
        const newConnIdArr = filterIds(connIds, id);
        const newClientIdArr = filterIds(clientIds, id);
        connIds = newConnIdArr;
        clientIds = newClientIdArr;
    });
});

Keywords

FAQs

Last updated on 01 Aug 2018

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc