Giter Site home page Giter Site logo

ajb413 / pubnub-js-webrtc Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 11.0 242 KB

Home Page: https://adambavosa.com/pubnub-js-webrtc/example/

License: MIT License

JavaScript 78.60% HTML 8.01% CSS 13.39%
webrtc javascript webrtc-javascript-library webrtc-phone video-chat xirsys pubnub pubnub-webrtc signaling-service video-calls

pubnub-js-webrtc's Introduction

JavaScript WebRTC Video Chat Package with PubNub

Adds the ability to do 1-to-1 WebRTC audio/video calls with PubNub. The PubNub key set must have PubNub Presence enabled. The example folder app uses Xirsys to get TURN server access via a PubNub Function.

WebRTC with PubNub Chat in JavaScript Screenshot

For education on WebRTC, and also a how-to for making your own app with this repository see these blog posts:

Initialization of the WebRTC Phone

let pubnub = new PubNub({
    publishKey: 'your-publish-api-key-here',
    subscribeKey: 'your-subscribe-api-key-here'
});

// set up all event handlers ...

// WebRTC phone object configuration.
let config = {
    rtcConfig,
    ignoreNonTurn: false,
    myStream: myAudioVideoStream,
    onPeerStream,   // is required
    onIncomingCall, // is required
    onCallResponse, // is required
    onDisconnect,   // is required
    pubnub          // is required
};

webRtcPhone = new WebRtcPhone(config);

Items that are provided to the WebRtcPhone constructor via the config object

// Standard WebRTC constructor config parameter (this data is for example purposes and will not work)
let rtcConfig = {
    iceServers: [
        {
            urls: "stun:stun.example.com",
            username: "[email protected]", 
            credential: "webrtcdemo"
        }, {
            urls: ["stun:stun.example.com", "stun:stun-1.example.com"]
        }
    ]
};

// WebRTC phone object event for when the remote peer's video becomes available.
const onPeerStream = (webRTCTrackEvent) => {
    console.log('Peer audio/video stream now available');
    const peerStream = webRTCTrackEvent.streams[0];
    window.peerStream = peerStream;
    remoteVideo.srcObject = peerStream; // HTML <video> element
};

// WebRTC phone object event for when a remote peer attempts to call you.
const onIncomingCall = (fromUuid, callResponseCallback) => {
    let username = 'Bob';
    incomingCall(username).then((acceptedCall) => {
        if (acceptedCall) {
            // End an already open call before opening a new one
            webRtcPhone.disconnect();
            // Update your UI for showing peer video feed
        }

        callResponseCallback({ acceptedCall });
    });
};

// WebRTC phone object event for when the remote peer responds to your call request.
const onCallResponse = (acceptedCall) => {
    console.log('Call response: ', acceptedCall ? 'accepted' : 'rejected');
    if (acceptedCall) {
        // Update your UI for showing peer video feed
    }
};

// WebRTC phone object event for when a call disconnects or timeouts.
const onDisconnect = () => {
    console.log('Call disconnected');
    // Update your UI for hiding peer video feed
};

Send a call request to another user

webRtcPhone.callUser("Alice", {
    myStream: myAudioVideoStream // Get this stream with `navigator.mediaDevices.getUserMedia()`
});

Frequently Asked Questions (FAQ) about the PubNub JS WebRTC Package

What is WebRTC?

WebRTC is a free and open source project that enables web browsers and mobile devices to provide a simple real-time communication API. Please read this PubNub blog to learn more about WebRTC and how to implement the code in this repository.

What is PubNub? Why is PubNub relevant to WebRTC?

PubNub is a global Data Stream Network (DSN) and realtime network-as-a-service. PubNub's primary product is a realtime publish/subscribe messaging API built on a global data stream network which is made up of a replicated network with multiple points of presence around the world.

PubNub is a low cost, easy to use, infrastructure API that can be implemented rapidly as a WebRTC signaling service. The signaling service is responsible for delivering messages to WebRTC peer clients. See the next question for the specific signals that PubNub's publish/subscribe API handles.

Does PubNub stream audio or video data?

No. PubNub pairs very well with WebRTC as a signaling service. This means that PubNub signals events from client to client using the Pub/Sub messaging over TCP. These events include:

  • I, User A, would like to call you, User B
  • User A is currently trying to call you, User B
  • I, User B, accept your call User A
  • I, User B, reject your call User A
  • I, User B, would like to end our call User A
  • I, User A, would like to end our call User B
  • Text instant messaging like in Slack, Google Hangouts, Skype, Facebook Messenger, etc.

Is this package officially part of PubNub?

No. It is an open source project that is community supported. If you want to report a bug, do so on the GitHub Issues page.

Can I make a group call with more than 2 participants?

Group calling is possible to develop with WebRTC and PubNub, however, the current PubNub WebRTC package can connect only 2 users in a private call. The community may develop this feature in the future but there are no plans for development to date.

I found a bug in the package. Where do I report it?

The PubNub WebRTC package is an open source, community supported project. This means that the best place to report bugs is on the GitHub Issues page in for the code repository. The community will tackle the bug fix at will, so there is no guarantee that a fix will be made. If you wish to provide a code fix, fork the GitHub repository to your GitHub account, push fixes, and make a pull request (process documented on GitHub).

pubnub-js-webrtc's People

Contributors

ajb413 avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pubnub-js-webrtc's Issues

Error processing ICE candidate

I get an error.

WebRTC [peerIceCandidate] error. DOMException: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': Error processing ICE candidate

VM279 pubnub-js-webrtc.js:422 

I've copied and pasted the few files in your example and published them live.
I have not tested between two computers as this test is just between two browsers on the same pc.

As a result on my two browsers the video/audio and chat all work, I just get this console error.

any help.
thanks.

Save the old messages.

Hello.
I know pubnub can store up to 100 old messages for each user. How can I make this script save the old messages?
Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.