js/im.js
/**
 * @param  {WebSocket}
 * @param  {TeamTalkWebClient}
 * @description listen some thing for websocket and bind to client
 */
@param  {WebSocket}
@param  {TeamTalkWebClient}
@description listen some thing for websocket and bind to client
@param { WebSocket } @param { TeamTalkWebClient } @description listen some thing for websocket and bind to client
function bindWebsocketForClinet(wsSocket, client) {
	wsSocket.binaryType = "arraybuffer";
	wsSocket.onopen = function(event) {
		client.clientState =  UserStatType.USER_STATUS_ONLINE;
		if(client.logined && !!client.loginInfo) {
			client.relogin(function(res,error){
				if(res){
					console.log('relogin success');
				}
			});
		}
	}
	wsSocket.onmessage = function(event) {
		var pdu = event.data.slice(0,16);
		var dv = new DataView(pdu,0);
		var data = {};
		data.commandId = dv.getUint16(10);
		data.seqNum = dv.getUint16(12);
		data.serviceId = dv.getUint16(8);
		data.content = event.data.slice(16);
		client.handleEventData(data);
	}
	wsSocket.onclose = function(event) {
		console.log("websocket onclose");
		if(!window.navigator.onLine)
		{
			client.clientState = UserStatType.USER_STATUS_OFFLINE;
			client.connect();
		}else if(client.logined) {
			client.connect();
		}
	}
}
function bindWebsocketForClinet ( wsSocket , client ) { wsSocket . binaryType = "arraybuffer" ; wsSocket . onopen = function ( event ) { client . clientState = UserStatType . USER_STATUS_ONLINE ; if ( client . logined && ! ! client . loginInfo ) { client . relogin ( function ( res , error ) { if ( res ) { console . log ( 'relogin success' ) ; } } ) ; } } wsSocket . onmessage = function ( event ) { var pdu = event . data . slice ( 0 , 16 ) ; var dv = new DataView ( pdu , 0 ) ; var data = { } ; data . commandId = dv . getUint16 ( 10 ) ; data . seqNum = dv . getUint16 ( 12 ) ; data . serviceId = dv . getUint16 ( 8 ) ; data . content = event . data . slice ( 16 ) ; client . handleEventData ( data ) ; } wsSocket . onclose = function ( event ) { console . log ( "websocket onclose" ) ; if ( ! window . navigator . onLine ) { client . clientState = UserStatType . USER_STATUS_OFFLINE ; client . connect ( ) ; } else if ( client . logined ) { client . connect ( ) ; } } }
@param  {WebSocket}
 @param  {TeamTalkWebClient}
 @description listen some thing for websocket and bind to client
@param { WebSocket } @param { TeamTalkWebClient } @description listen some thing for websocket and bind to client