Q:

Replacing Socket io with Pubnub (WebRTC)

I am looking into using Pubnub's service to set up WebRTC connections between peers for video.
With this I am hoping to avoid using socket io which is what I am currently using, although I just cannot find any good examples that demonstrate how to do this. 
Right now socket io is handling the events emitted from the client and the server. From what I understand, the current node js server would no longer need to handle any of the emitted events since socket io would not be used but this is what I am having problems with. I am not sure how to set up the clients to signal each other the information that they require (who to connect to, etc)
Are there any simple examples or implementations of pubnub being used instead of socket io for a project or perhaps someone can shed some light on something I may not be seeing, thanks!
edit: Also with anyone experienced in Pubnub, is what I am trying to do even possible haha

A:

WebRTC Signaling Exchanging ICE Candidates via PubNub
The goal is to exchange ICE candidate packets between two peers. ICE candidate packets are structured payloads which contain possible path recommendations between two peers.  You can use a lib which will take care of the nitty gritty such as http://www.sinch.com/ and below is the general direction you want to take:
Signaling Example Code Follows
<script src="http://cdn.pubnub.com/pubnub-3.6.3.min.js"></script>
<script>(function(){

    // INIT P2P Packet Exchanger
    var pubnub = PUBNUB({
        publish_key   : 'demo',
        subscribe_key : 'demo'
    })

    // You need to specify the exchange channel for the peers to
    // exchange ICE Candidates.
    var exchange_channel = "p2p-exchange";

    // LISTEN FOR ICE CANDIDATES
    pubnub.subscribe({
        channel : exchange_channel,
        message : receive_ice_candidates
    })

    // ICE CANDIDATES RECEIVER PROCESSOR FUNCTION
    function receive_ice_candidates(ice_candidate) {
        // Attempt peer connection or upgrade route if better route...
        console.log(ice_candidate);
        // ... RTC Peer Connection upgrade/attempt ...
    }

    // SEND ICE CANDIDATE
    function send_ice_candidate(ice) {
        pubnub.publish({
            channel : exchange_channel,
            message : ice
        })
    }

Generate ICE Candidates Example Code Follows:
    // CREATE ICE CANDIDATES
    var pc = new RTCPeerConnection();
    navigator.getUserMedia( {video: true}, function(stream) {
        pc.onaddstream({stream:stream});
        pc.addStream(stream);
        pc.createOffer( function(offer) {
            pc.setLocalDescription(
                new RTCSessionDescription(offer),
                send_ice_candidate, // - SEND ICE CANDIDATE via PUBNUB
                error
            );
        }, error );
    } );

    // ERROR CALLBACK
    function error(e) {
        console.log(e);
    }
})();</script>

More fun details await - https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection

