[rtcweb] ROAP Example Application

Cullen Jennings <fluffy@cisco.com> Fri, 21 October 2011 02:08 UTC

Return-Path: <fluffy@cisco.com>
X-Original-To: rtcweb@ietfa.amsl.com
Delivered-To: rtcweb@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 711A411E8094 for <rtcweb@ietfa.amsl.com>; Thu, 20 Oct 2011 19:08:23 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -105.224
X-Spam-Level:
X-Spam-Status: No, score=-105.224 tagged_above=-999 required=5 tests=[AWL=-0.425, BAYES_00=-2.599, J_CHICKENPOX_34=0.6, J_CHICKENPOX_63=0.6, J_CHICKENPOX_64=0.6, RCVD_IN_DNSWL_MED=-4, USER_IN_WHITELIST=-100]
Received: from mail.ietf.org ([12.22.58.30]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uEc5DU2P-x6S for <rtcweb@ietfa.amsl.com>; Thu, 20 Oct 2011 19:08:22 -0700 (PDT)
Received: from mtv-iport-4.cisco.com (mtv-iport-4.cisco.com [173.36.130.15]) by ietfa.amsl.com (Postfix) with ESMTP id E9C2511E808F for <rtcweb@ietf.org>; Thu, 20 Oct 2011 19:08:22 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=fluffy@cisco.com; l=2966; q=dns/txt; s=iport; t=1319162903; x=1320372503; h=from:content-transfer-encoding:subject:date:message-id: to:mime-version; bh=vk5dCOOIy3ZbZH0yyStC4pkzJpQLCENBLrIvL0fH//o=; b=ZyQNrNe/CK0PDYftAJtmJqrEjUoViAOXMoS3dhaDLRTzqH9+n8gGc71O XE8JpSVOkfRuSFp9SQVtXWceSluw+Vl8nAI4Ho40hOCJWCL7Aeflv/BkG 5zf6hA4A/Krug2DM1rs8e129WcEXU6INL8riUm55IEaKAMm6QIaCYp4Sg A=;
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AmgHAOvToE6rRDoG/2dsb2JhbABDmh+OfYEFggcBJzuBd51qgSYBniWHSGEEiAOLfYUqjEw
X-IronPort-AV: E=Sophos;i="4.69,383,1315180800"; d="scan'208";a="9257131"
Received: from mtv-core-1.cisco.com ([171.68.58.6]) by mtv-iport-4.cisco.com with ESMTP; 21 Oct 2011 02:08:19 +0000
Received: from [192.168.4.100] (sjc-fluffy-8914.cisco.com [10.20.249.165]) by mtv-core-1.cisco.com (8.14.3/8.14.3) with ESMTP id p9L28I5T013344 for <rtcweb@ietf.org>; Fri, 21 Oct 2011 02:08:19 GMT
From: Cullen Jennings <fluffy@cisco.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
Date: Thu, 20 Oct 2011 20:08:18 -0600
Message-Id: <EED7DD83-EFDF-43B3-B9EE-7D28D057FA37@cisco.com>
To: rtcweb@ietf.org
Mime-Version: 1.0 (Apple Message framework v1084)
X-Mailer: Apple Mail (2.1084)
Subject: [rtcweb] ROAP Example Application
X-BeenThere: rtcweb@ietf.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id: Real-Time Communication in WEB-browsers working group list <rtcweb.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/rtcweb>, <mailto:rtcweb-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/rtcweb>
List-Post: <mailto:rtcweb@ietf.org>
List-Help: <mailto:rtcweb-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/rtcweb>, <mailto:rtcweb-request@ietf.org?subject=subscribe>
X-List-Received-Date: Fri, 21 Oct 2011 02:08:23 -0000

I liked Dan Yorks rant on what we need and it made me want to show some simple code using an interface like the current W3C PeerConnection API along with ROAP. Assuming the ROAP objects got passed in and out of the Peer Connection object, here is a short little example I copied that shows how simple it is to write a web application that sets up an audio / video connection between two browsers. It assumes a simple web server that that can pass messages from alice to bob and visa versa. Both alice and bob just short poll the web server to get messages from their mailbox and post messages to the others mailbox. The web server does not transform the messages in any way. Clearly this example is wrong in some ways, lacks authentication, and various error handling but I think it illustrates the basics of the interfaces. 



var ui_log = function(msg) {
    var t = document.createTextNode(msg);
    var d = document.createElement("div");
    $(d).append(t);

    $("#logwindow").append(d);
};


// simple wrapper around XHR. The cool kids use JQuery here, but
// we want a self-contained example
var ajax = function(params) {
    var xhr = new XMLHttpRequest();
    xhr.open(
	params.type || "GET",
	params.url,
	true);
    if(params.contentType){
	xhr.setRequestHeader("Content-Type",params.contentType)
    }
    if(params.data){
	xhr.send(params.data);
    }
    else{
	xhr.send();
    }
    xhr.onreadystatechange = function() {
	if(xhr.readyState === 4) {
	    if(xhr.status === 200) {
		if(params.success){
		    params.success(xhr.responseText);
		}
	    }
	    else {
		if (params.error) {
		    params.error(xhr.responseText);
		}
	    }
	}
    }
};


var ROAPClient = function(username, peer, start_call) {
    var poll_timeout = 1000; // ms
    
    var log = function(msg) {
	console.log("LOG (" + username + "): " + msg);
	ui_log("LOG (" + username + "): " + msg);
    };
    
    var signaling = function(msg) {
	msg.dest = peer;

	log("Sending: " + JSON.stringify(msg));

	ajax({
		 url : "/msg/",
		 type:"POST",
		 contentType:"application/json",
		 data: JSON.stringify(msg),
	     });
    };

    var poll_success = function(msg) {
	var js = JSON.parse(msg);
	log("Received message " + JSON.stringify(js));
	
	pc.processSignalingMessage(js);
    };
        
    var poll_error = function(msg) {
	setTimeout(poll, poll_timeout);
    };

    var poll = function() {
	ajax({
		 url: "/msg/" + username + "/",
		 success:poll_success,
		 error:poll_error
	     });
    };

    var pc = new PeerConnection({}, signaling);
    
    if (start_call) {
	pc.addStream();
    }

    // Start polling
    poll();
};



var ROAPTest = function() {
    var caller = new ROAPClient("alice", "bob", true);
    var callee = new ROAPClient("bob", "alice");
};