real-time-tv
Real-time video player component built with react and socket.io
Last updated a year ago by devin.ragotzy .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install real-time-tv 
SYNC missed versions from official npm registry.

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;
    });
});

Current Tags

  • 1.1.0                                ...           latest (a year ago)

10 Versions

  • 1.1.0                                ...           a year ago
  • 1.0.8                                ...           a year ago
  • 1.0.7                                ...           a year ago
  • 1.0.6                                ...           a year ago
  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 10
Dependencies (9)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |