From commits-return-17985-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Wed Feb 1 15:09:06 2012 Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 14D489906 for ; Wed, 1 Feb 2012 15:09:06 +0000 (UTC) Received: (qmail 66843 invoked by uid 500); 1 Feb 2012 15:09:05 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 66794 invoked by uid 500); 1 Feb 2012 15:09:05 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 66787 invoked by uid 99); 1 Feb 2012 15:09:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Feb 2012 15:09:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Feb 2012 15:09:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C340C2388AA9 for ; Wed, 1 Feb 2012 15:08:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1239163 [2/2] - in /activemq/activemq-apollo/trunk/apollo-distro/src/main/release: ./ examples/js-websocket/ examples/js-websocket/css/ examples/js-websocket/img/ examples/js-websocket/js/ Date: Wed, 01 Feb 2012 15:08:43 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120201150843.C340C2388AA9@eris.apache.org> Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/index.html URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/index.html?rev=1239163&view=auto ============================================================================== --- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/index.html (added) +++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/index.html Wed Feb 1 15:08:42 2012 @@ -0,0 +1,149 @@ + + + + + Chat Example Using STOMP Over WebSockets + + + + + + + + + + +
+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+
+
+ +
+
+ +

+        
+
+
+ + + + + + + + Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/js/stomp.js URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/js/stomp.js?rev=1239163&view=auto ============================================================================== --- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/js/stomp.js (added) +++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/js/stomp.js Wed Feb 1 15:08:42 2012 @@ -0,0 +1,205 @@ + +/* +Copyright (C) 2010 Jeff Mesnil -- http://jmesnil.net/ +Copyright (C) 2012 FuseSource, Inc. -- http://fusesource.com +*/ + +(function() { + var Client, Stomp, WebSocketStompMock, + __hasProp = Object.prototype.hasOwnProperty; + + Stomp = { + frame: function(command, headers, body) { + if (headers == null) headers = []; + if (body == null) body = ''; + return { + command: command, + headers: headers, + body: body, + id: headers.id, + receipt: headers.receipt, + transaction: headers.transaction, + destination: headers.destination, + subscription: headers.subscription, + error: null, + toString: function() { + var lines, name, value; + lines = [command]; + for (name in headers) { + if (!__hasProp.call(headers, name)) continue; + value = headers[name]; + lines.push("" + name + ":" + value); + } + lines.push('\n' + body); + return lines.join('\n'); + } + }; + }, + unmarshal: function(data) { + var body, chr, command, divider, headerLines, headers, i, idx, line, trim, _ref, _ref2, _ref3; + divider = data.search(/\n\n/); + headerLines = data.substring(0, divider).split('\n'); + command = headerLines.shift(); + headers = {}; + body = ''; + trim = function(str) { + return str.replace(/^\s+/g, '').replace(/\s+$/g, ''); + }; + line = idx = null; + for (i = 0, _ref = headerLines.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) { + line = headerLines[i]; + idx = line.indexOf(':'); + headers[trim(line.substring(0, idx))] = trim(line.substring(idx + 1)); + } + chr = null; + for (i = _ref2 = divider + 2, _ref3 = data.length; _ref2 <= _ref3 ? i < _ref3 : i > _ref3; _ref2 <= _ref3 ? i++ : i--) { + chr = data.charAt(i); + if (chr === '\0') break; + body += chr; + } + return Stomp.frame(command, headers, body); + }, + marshal: function(command, headers, body) { + return Stomp.frame(command, headers, body).toString() + '\0'; + }, + client: function(url) { + return new Client(url); + } + }; + + Client = (function() { + + function Client(url) { + this.url = url; + this.counter = 0; + this.connected = false; + this.subscriptions = {}; + } + + Client.prototype._transmit = function(command, headers, body) { + var out; + out = Stomp.marshal(command, headers, body); + if (typeof this.debug === "function") this.debug(">>> " + out); + return this.ws.send(out); + }; + + Client.prototype.connect = function(login_, passcode_, connectCallback, errorCallback) { + var klass, + _this = this; + if (typeof this.debug === "function") this.debug("Opening Web Socket..."); + klass = WebSocketStompMock || WebSocket; + this.ws = new klass(this.url); + this.ws.binaryType = "arraybuffer"; + this.ws.onmessage = function(evt) { + var data, frame, i, onreceive, view; + data = (function() { + var _i, _len; + if (evt.data instanceof ArrayBuffer) { + view = new Uint8Array(evt.data); + if (typeof this.debug === "function") { + this.debug('--- got data length: ' + view.length); + } + data = ""; + for (_i = 0, _len = view.length; _i < _len; _i++) { + i = view[_i]; + data += String.fromCharCode(i); + } + return data; + } else { + return evt.data; + } + }).call(_this); + if (typeof _this.debug === "function") _this.debug('<<< ' + data); + frame = Stomp.unmarshal(data); + if (frame.command === "CONNECTED" && connectCallback) { + _this.connected = true; + return connectCallback(frame); + } else if (frame.command === "MESSAGE") { + onreceive = _this.subscriptions[frame.headers.subscription]; + return typeof onreceive === "function" ? onreceive(frame) : void 0; + } + }; + this.ws.onclose = function() { + var msg; + msg = "Whoops! Lost connection to " + _this.url; + if (typeof _this.debug === "function") _this.debug(msg); + return typeof errorCallback === "function" ? errorCallback(msg) : void 0; + }; + this.ws.onopen = function() { + if (typeof _this.debug === "function") _this.debug('Web Socket Opened...'); + return _this._transmit("CONNECT", { + login: login_, + passcode: passcode_ + }); + }; + return this.connectCallback = connectCallback; + }; + + Client.prototype.disconnect = function(disconnectCallback) { + this._transmit("DISCONNECT"); + this.ws.close(); + this.connected = false; + return typeof disconnectCallback === "function" ? disconnectCallback() : void 0; + }; + + Client.prototype.send = function(destination, headers, body) { + if (headers == null) headers = {}; + if (body == null) body = ''; + headers.destination = destination; + return this._transmit("SEND", headers, body); + }; + + Client.prototype.subscribe = function(destination, callback, headers) { + var id; + if (headers == null) headers = {}; + id = "sub-" + this.counter++; + headers.destination = destination; + headers.id = id; + this.subscriptions[id] = callback; + this._transmit("SUBSCRIBE", headers); + return id; + }; + + Client.prototype.unsubscribe = function(id, headers) { + if (headers == null) headers = {}; + headers.id = id; + delete this.subscriptions[id]; + return this._transmit("UNSUBSCRIBE", headers); + }; + + Client.prototype.begin = function(transaction, headers) { + if (headers == null) headers = {}; + headers.transaction = transaction; + return this._transmit("BEGIN", headers); + }; + + Client.prototype.commit = function(transaction, headers) { + if (headers == null) headers = {}; + headers.transaction = transaction; + return this._transmit("COMMIT", headers); + }; + + Client.prototype.abort = function(transaction, headers) { + if (headers == null) headers = {}; + headers.transaction = transaction; + return this._transmit("ABORT", headers); + }; + + Client.prototype.ack = function(message_id, headers) { + if (headers == null) headers = {}; + headers["message-id"] = message_id; + return this._transmit("ACK", headers); + }; + + return Client; + + })(); + + if (typeof window !== "undefined" && window !== null) { + window.Stomp = Stomp; + } else { + exports.Stomp = Stomp; + WebSocketStompMock = require('./test/server.mock.js').StompServerMock; + } + +}).call(this); Added: activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/readme.md URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/readme.md?rev=1239163&view=auto ============================================================================== --- activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/readme.md (added) +++ activemq/activemq-apollo/trunk/apollo-distro/src/main/release/examples/js-websocket/readme.md Wed Feb 1 15:08:42 2012 @@ -0,0 +1,18 @@ +## Overview + +This is an example of how use the +['stomp-websocket'](https://github.com/jmesnil/stomp-websocket) +JavaScript APIs with the Apollo message broker. + +## Prereqs + +- Use a modern browser with WebSocket support like Chrome or WebKit + +## Running + +Run the Apollo sever locally and then open the `index.html` +in the current directory using a web browser. + +## Credits + +This example is a modified version of Jeff Mesnil's chat example. \ No newline at end of file