Hey,

You can juste use "pipe.send()" where pipe is an object returned on the event "multipipecreate" or by getPipe(pubid).

Le 12/04/2011 06:50, ramonezy a écrit :
Hi all,

I know this might be a simple problem, but I couldn't find what I was
looking for in the documentation. I'm trying to create a simple site
with two sections, a comment form and a comment stream. The comment
form will allow a user to enter a comment and the comment stream will
show the comments of all users sorted by time. I wanted to use ape to
be able to update the comment stream as soon as a user creates a
comment without a page refresh.

The site uses jQuery for a number of functions. I think the main
question i have is how to send a message to a multi pipe using a
javascript function. I'm not understanding how to get the reference to
a pipe if its not done in an event listener.

The flow is upon submit, the ajax form calls its handler, which is
postComment. The postComment function will receive a JSON object from
my server with the details of the message sent. The JSON object is
passed to structureComment, which formats the HTML to be inserted and
insertComment inserts the formatted HTML in the comment stream.

My code snippet is below.

Any help would be greatly appreciated


/
*-----------------------------------------------------------------------------------------
*/

$(document).ready(function() {

         client = new APE.Client();
         client.load();

         client.addEvent('load', function() {
             client.core.start();
         });

         client.addEvent('ready', function() {
             client.core.join('testChannel');

             client.onCmd('send', function(pipe, sessid, pubid, msg){
                 alert('message send');
             });

             client.onRaw('data', function(raw, pipe) {
                 var msgHTML = structureComment('msgJSON');
                 insertComment(msgHTML);
             });
         });

        /*-------------------------------------------------*/
                 other unrelated javascript code
       /*----------------------------------------------------*/

         var msgFormOptions = {
             resetForm:  true,
             //beforeSubmit: storeCommentDetails,
             success:    postComment
         };

         $('#commentForm').ajaxForm(msgFormOptions);

});

function postComment(responseText, statusText, xhr, $form){

     if(responseText){
         var msgObj = JSON.parse(responseText);
         var msgHTML = structureComment(msgObj);
         insertComment(msgHTML);

     }else{
         alert("Message failed, please try again ");
     }
}

function insertComment(newCommentHtml){
     $('#commentStream').prepend(newCommentHtml);
}

function structureComment(msgJSON){

     var nName = msgJSON[0].senderName;
     var nCountry = msgJSON[0].senderCountry;
     var nMsg = msgJSON[0].senderMsg;
     var nDate = 'Today';

     var msgHTML = '<li><div class="comment">' +
                   '<div class="commentHeader"><span
class="name">'+nName+'</span>  from<span class="country">'+nCountry+'</
span>  says:</div>'+
                   '<div class="commentBody">'+ nMsg +'</div>' +
                   '<div class="commentDate">Time Sent: '+ nDate +'</
div>'+
                   '<div class="clearDiv"></div></div></li>';

     return msgHTML;
}


--
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/

Reply via email to