pushlet實現webQQ即時通信

後臺維護界面展現:



                                                                 後臺首頁

 

 

 



                                                      賬戶及其人員列表

 

人員的組織及其所在羣組的維護頁面就不在展現下面展現客戶端。

 



                     用戶登錄

 



               鼠標懸停

 

 



                  維護狀態

 

 



                   鼠標右鍵

 

 



                                               查看人員信息

 

 

 



                                            查看聊天記錄

 

 



                                          維護個人資料

 

 

 



                                           聊天窗口

 

 

 



                                         互相附件傳送

 

 



                 IM實現消息提醒

 



                                  實現羣組之間的聊天

 

以上是IM(即時通信)一些基本功能的簡介,好了就先到此爲止吧。。。。。

在Pushlet的應用方面希望可以與大家相互交流,互相學習。

 

 

 

 

JavaScript兩種發送消息的方式不用多說

1、Ajax保持心跳的即時通信

2、往前臺輸送HTML的即時通信

 

下面貼Java實現即時通信的代碼

package com.jlee.im;

import java.util.Map;

import nl.justobjects.pushlet.client.PushletClient;
import nl.justobjects.pushlet.client.PushletClientListener;
import nl.justobjects.pushlet.core.Event;
import nl.justobjects.pushlet.core.Protocol;


public class SystemChatEngine extends Thread implements PushletClientListener, Protocol {
//	private static SystemChatEngine  systemChatEngine = new SystemChatEngine("http://localhost:8888/im/pushlet.srv");

	private static SystemChatEngine engine = null ;
	private PushletClient pushletClient;
	private Map<String ,String> attributemap ;
	private String aHosturl=null;
	private String SUBJECT = "/pushlet/ping";
	private String imSubject = null;

	private SystemChatEngine(String aHosturl, String subject, String imSubject, Map<String ,String> map) {
		this.aHosturl = aHosturl;
		this.SUBJECT = subject ;
		this.attributemap = map ;
		this.imSubject = imSubject ;
	}
	
	public static SystemChatEngine getInstance(String aHosturl, String subject ,String imSubject ,Map<String ,String> map){
		if(engine==null){
			engine = new SystemChatEngine(aHosturl,subject,imSubject,map) ;
			engine.start() ;
		}
		return engine ;
	}
	
	public void run() {
		try {

			pushletClient = new PushletClient(aHosturl);
			pushletClient.setDebug(false);
			
			pushletClient.setUid(attributemap.get("uid")) ;
			
			pushletClient.join();
			pushletClient.listen(this, Protocol.MODE_PULL,SUBJECT);

			System.out.println("pushletClient started");
			
			pushletClient.publish(imSubject, attributemap);
			
		} catch (Exception e) {
			e.printStackTrace();
			return;
		}
	}

	/** Error occurred. */
	public void onError(String message) {
		System.out.println(message);
	}

	/** Abort event from server. */
	public void onAbort(Event theEvent) {
	}

	/** Data event from server. */
	public void onData(Event theEvent) {
		String meSessionID = theEvent.getField("uid");
	}

	/** Heartbeat event from server. */
	public void onHeartbeat(Event theEvent) {
	}

	public void onRefresh(Event theEvent) {
	}

	public void onJoinListenAck(Event theEvent) {
		String meSessionID = theEvent.getField("uid");
	}

	public void onListenAck(Event theEvent) {
		String meSessionID = theEvent.getField("uid");
	}

	/**
	 * @return pushletClient
	 */
//	public static  PushletClient getPushletClient() {
//		while(systemChatEngine.pushletClient==null){}
//		return systemChatEngine.pushletClient;
//	}

	/** Main program. */
//	public static void main(String args[]) {
//		systemChatEngine.start();
//	}

}

 

 

 

package com.jlee.im;

import java.util.HashMap;
import java.util.Map;

import sun.misc.BASE64Encoder;

public class WebIMClient {

	static SystemChatEngine engine = null ;
	
	public void sendTask()throws Exception{
		
		Map<String ,String> attributemap = new HashMap<String, String>() ;
		BASE64Encoder encoder = new BASE64Encoder();
		String fromName = encoder.encode("jlee".getBytes("utf-8")) ;
		String message = java.net.URLEncoder.encode(
				encoder.encode(
						"<a href='#' title='http://www.baidu.com' name='alabel'>baidu</a>去百度查IM".getBytes("utf-8"))) ;
		String remark = encoder.encode("備註".getBytes("utf-8")) ;
		
		String title = encoder.encode("主題1".getBytes("utf-8")) ;
		String msgType = encoder.encode("類型1".getBytes("utf-8")) ;
		String msgGroup = encoder.encode("self".getBytes("utf-8")) ;//self(表示消息來自系統OA)或者other(消息來自其他系統)
		
		attributemap.put("uid" ,"728852348a9f4c219f9666facef19356") ;//該字段不會進入數據庫,只是充當Pushlet所依賴的Id
		attributemap.put("fromId", "728852348a9f4c219f9666facef19356") ;
		attributemap.put("fromName", fromName) ;
		attributemap.put("toId", "86523b57993048a0b82bd06772e432dd") ;
		attributemap.put("toGroupId", null) ;
		attributemap.put("message", message) ;
		attributemap.put("remark", remark) ;

		attributemap.put("title", title) ;
		attributemap.put("msgType", msgType) ;
		attributemap.put("msgGroup", msgGroup) ;
		
		engine = SystemChatEngine.getInstance(
				"http://localhost:8888/im/pushlet.srv", "/pushlet/ping,/task/warn","/task/warn", attributemap) ;
		
	}
	
	public static void main(String[] args) {
		WebIMClient client = new WebIMClient() ;
		try {
			client.sendTask() ;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章