基于pushlet 的开发代码,现正在使用的。

      http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      http://www.w3.org/1999/xhtml">


      指路网 IM







         


             

             

             

                 
                     
                   

             

         

         


             

             

                     

                       

                  

             

             
             
         


         

             

             
        
         


         

            

           
      按 <Shift>+<Enter>,按<Enter>换行.

         


       

       

      im.js里的文件,专门用来监听

       

      if(currentAccountID && currentAccountID!=null)
      {   
          enterChat(currentAccountID);   
      }

      var senders=new Array();
      var chatwindow=null;
      var msgtiped=false;//提示消息框是否显示了,显示了就不用再显示了。
      var interval=null;
      function openwin()
      {
              if(senders&&senders.length>0){
                  chatwindow=window.open ("im.html?senders="+senders.join(",")+"&user="+currentAccountID+"&en="+unicode(senders+'_'+currentAccountID), "chatwin");   
                  if(interval!=null){
                      clearInterval(interval);       
                  }
              }
              chatwindow.focus();
              $("#floatdiv").hide();
      }

      function enterChat(currentAccountID){         
                     p_join_listen(currentAccountID);              
                  //p_publish(currentAccountID, 'action', 'enter', 'sender', currentAccountID);
      }

      function onJoinAck(event) {}

      function onData(event) {         
      var action = event.get('action');
      var receiver=event.get('receiver');

      if (action == 'send'&&receiver==currentAccountID)
      {
          var msg=event.get('msg');
          var sender=event.get('sender');
          if(msg!=null && msg!="" && sender!=null && sender!="")   
          {
              //添加到一会要发起聊天的对象中。
              if(get_index(sender)==-1)
              senders[senders.length]=sender;
              //显示DIV 有消息到达。
              if(!msgtiped)
              showmsgtip();
          }
          //保存未读消息
          var msgobj=new Object();
          msgobj.content=msg;
          msgobj.receiver=currentAccountID;
          msgobj.sender=sender;
          msgobj.fromID=1;
          msgobj.seller=sender;
          saveunreadmsg(msgobj);
      }
        function leaveChat(){
             // p_publish(currentAccountID, 'action', 'exit', 'sender', currentAccountID);
              p_leave();
           }

      }
      function onNack(event) {
      // alert('negative response from server: ' + event.getEvent() + ' reason: ' + event.get('p_reason'));
      }
      //显示消息提示
      function showmsgtip()
      {
          msgtiped=true;
          var floatdiv="


      ";
          $(document.body).append($(floatdiv));
          interval=window.setInterval("heartBeat()",100);
      }
      function heartBeat()
      {
      document.getElementById("floatdiv").style.top=document.documentElement.clientHeight+document.documentElement.scrollTop-30+"px";
      }

      function saveunreadmsg(obj)
      {
          var url="msg?type=put&key="+obj.sender+"&content="+obj.content+"&sender="+obj.sender+"&receiver="+obj.receiver+"&fromID="+obj.fromID;
          $.get(encodeURI(url),function(data){
                            // alert(data);
                             });

      }

      function unicode(s){
         var len=s.length;
         var rs="";
         for(var i=0;i           var k=s.substring(i,i+1);
                rs+= (i==0?"":",")+s.charCodeAt(i);
         }
         return rs;
      }
      // unicode decode
      function runicode(s){
         var k=s.split(",");
         var rs="";
         for(i=0;i       rs+=String.fromCharCode(k[i]);
         }
         return rs;
      }
      function get_index(sender)
      {
          for(var i=0;i     {
              if(senders[i]!=null && senders[i]==sender)
              return i;
          }
          return -1;
      }

      你可能感兴趣的:(基于pushlet 的开发代码,现正在使用的。)