diff --git a/Im.html b/Im.html index 9bba2e2..d664942 100644 --- a/Im.html +++ b/Im.html @@ -1,1322 +1,39 @@ - IM演示 + Green Chat Example - - - + + - \ No newline at end of file diff --git a/image/component.png b/image/component.png new file mode 100644 index 0000000..7abb785 Binary files /dev/null and b/image/component.png differ diff --git a/rosters.php b/rosters.php index 21fc5cf..61c3250 100644 --- a/rosters.php +++ b/rosters.php @@ -1,18 +1,27 @@ array('id'=>1, 'image'=>'./image/user/1.jpg', 'name'=>'kink'), - 'rosters' => array( - array('id'=>2, 'image'=>'./image/user/2.jpg', 'name'=>'用户2'), - array('id'=>3, 'image'=>'./image/user/3.jpg', 'name'=>'用户3'), - array('id'=>4, 'image'=>'./image/user/4.jpg', 'name'=>'用户4'), - array('id'=>5, 'image'=>'./image/user/5.jpg', 'name'=>'用户5'), - array('id'=>6, 'image'=>'./image/user/6.jpg', 'name'=>'用户6'), - array('id'=>7, 'image'=>'./image/user/7.jpg', 'name'=>'用户7'), - array('id'=>8, 'image'=>'./image/user/8.jpg', 'name'=>'用户8'), - array('id'=>9, 'image'=>'./image/user/9.jpg', 'name'=>'用户9') - ) + $id = empty($_GET['id']) ? 1 : $_GET['id']; + + $rosters = array( + '1' => array('id'=>1, 'image'=>'./image/user/1.jpg', 'name'=>'艾伦', 'watch'=>'2,3,4,5,6,7,8,9'), + '2' => array('id'=>2, 'image'=>'./image/user/2.jpg', 'name'=>'毕维斯', 'watch'=>'1,4,7,8'), + '3' => array('id'=>3, 'image'=>'./image/user/3.jpg', 'name'=>'拜伦', 'watch'=>'1,2,6,5'), + '4' => array('id'=>4, 'image'=>'./image/user/4.jpg', 'name'=>'道格拉斯', 'watch'=>'7,8,9'), + '5' => array('id'=>5, 'image'=>'./image/user/5.jpg', 'name'=>'爱德华', 'watch'=>'4,6,8,9'), + '6' => array('id'=>6, 'image'=>'./image/user/6.jpg', 'name'=>'加布力尔', 'watch'=>'1,3,5,7,9'), + '7' => array('id'=>7, 'image'=>'./image/user/7.jpg', 'name'=>'雨果', 'watch'=>'2,4,5,8'), + '8' => array('id'=>8, 'image'=>'./image/user/8.jpg', 'name'=>'里斯特', 'watch'=>'1,4,6,7,9'), + '9' => array('id'=>9, 'image'=>'./image/user/9.jpg', 'name'=>'玛希', 'watch'=>'2,3,4,5,6,7,8') ); - echo json_encode($res); - \ No newline at end of file + $len = $id; + + $res = array(); + $res['me'] = $rosters[$id]; + + $ids = explode(',', $rosters[$id]['watch']); + foreach( $ids as $k=>$v ) { + $res['rosters'][] = $rosters[$v]; + } + + echo json_encode($res); \ No newline at end of file diff --git a/script/green.js b/script/green.js new file mode 100644 index 0000000..915c26d --- /dev/null +++ b/script/green.js @@ -0,0 +1,1320 @@ +/*! nanoScrollerJS - v0.8.0 - (c) 2014 James Florentino; Licensed MIT */ +!function(a,b,c){"use strict";var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F;x={paneClass:"nano-pane",sliderClass:"nano-slider",contentClass:"nano-content",iOSNativeScrolling:!1,preventPageScrolling:!1,disableResize:!1,alwaysVisible:!1,flashDelay:1500,sliderMinHeight:20,sliderMaxHeight:null,documentContext:null,windowContext:null},s="scrollbar",r="scroll",k="mousedown",l="mousemove",n="mousewheel",m="mouseup",q="resize",h="drag",u="up",p="panedown",f="DOMMouseScroll",g="down",v="wheel",i="keydown",j="keyup",t="touchmove",d="Microsoft Internet Explorer"===b.navigator.appName&&/msie 7./i.test(b.navigator.appVersion)&&b.ActiveXObject,e=null,B=b.requestAnimationFrame,w=b.cancelAnimationFrame,D=c.createElement("div").style,F=function(){var a,b,c,d,e,f;for(d=["t","webkitT","MozT","msT","OT"],a=e=0,f=d.length;f>e;a=++e)if(c=d[a],b=d[a]+"ransform",b in D)return d[a].substr(0,d[a].length-1);return!1}(),E=function(a){return F===!1?!1:""===F?a:F+a.charAt(0).toUpperCase()+a.substr(1)},C=E("transform"),z=C!==!1,y=function(){var a,b,d;return a=c.createElement("div"),b=a.style,b.position="absolute",b.width="100px",b.height="100px",b.overflow=r,b.top="-9999px",c.body.appendChild(a),d=a.offsetWidth-a.clientWidth,c.body.removeChild(a),d},A=function(){var a,c,d;return c=b.navigator.userAgent,(a=/(?=.+Mac OS X)(?=.+Firefox)/.test(c))?(d=/Firefox\/\d{2}\./.exec(c),d&&(d=d[0].replace(/\D+/g,"")),a&&+d>23):!1},o=function(){function i(d,f){this.el=d,this.options=f,e||(e=y()),this.$el=a(this.el),this.doc=a(this.options.documentContext||c),this.win=a(this.options.windowContext||b),this.$content=this.$el.children("."+f.contentClass),this.$content.attr("tabindex",this.options.tabIndex||0),this.content=this.$content[0],this.previousPosition=0,this.options.iOSNativeScrolling&&null!=this.el.style.WebkitOverflowScrolling?this.nativeScrolling():this.generate(),this.createEvents(),this.addEvents(),this.reset()}return i.prototype.preventScrolling=function(a,b){if(this.isActive)if(a.type===f)(b===g&&a.originalEvent.detail>0||b===u&&a.originalEvent.detail<0)&&a.preventDefault();else if(a.type===n){if(!a.originalEvent||!a.originalEvent.wheelDelta)return;(b===g&&a.originalEvent.wheelDelta<0||b===u&&a.originalEvent.wheelDelta>0)&&a.preventDefault()}},i.prototype.nativeScrolling=function(){this.$content.css({WebkitOverflowScrolling:"touch"}),this.iOSNativeScrolling=!0,this.isActive=!0},i.prototype.updateScrollValues=function(){var a,b;a=this.content,this.maxScrollTop=a.scrollHeight-a.clientHeight,this.prevScrollTop=this.contentScrollTop||0,this.contentScrollTop=a.scrollTop,b=this.contentScrollTop>this.previousPosition?"down":this.contentScrollTop=a.maxScrollTop&&a.prevScrollTop!==a.maxScrollTop?a.$el.trigger("scrollend"):0===a.contentScrollTop&&0!==a.prevScrollTop&&a.$el.trigger("scrolltop"),!1}}(this),up:function(a){return function(){return a.isBeingDragged=!1,a.pane.removeClass("active"),a.doc.unbind(l,a.events[h]).unbind(m,a.events[u]),!1}}(this),resize:function(a){return function(){a.reset()}}(this),panedown:function(a){return function(b){return a.sliderY=(b.offsetY||b.originalEvent.layerY)-.5*a.sliderHeight,a.scroll(),a.events.down(b),!1}}(this),scroll:function(a){return function(b){a.updateScrollValues(),a.isBeingDragged||(a.iOSNativeScrolling||(a.sliderY=a.sliderTop,a.setOnScrollStyles()),null!=b&&(a.contentScrollTop>=a.maxScrollTop?(a.options.preventPageScrolling&&a.preventScrolling(b,g),a.prevScrollTop!==a.maxScrollTop&&a.$el.trigger("scrollend")):0===a.contentScrollTop&&(a.options.preventPageScrolling&&a.preventScrolling(b,u),0!==a.prevScrollTop&&a.$el.trigger("scrolltop"))))}}(this),wheel:function(a){return function(b){var c;if(null!=b)return c=b.delta||b.wheelDelta||b.originalEvent&&b.originalEvent.wheelDelta||-b.detail||b.originalEvent&&-b.originalEvent.detail,c&&(a.sliderY+=-c/3),a.scroll(),!1}}(this)}},i.prototype.addEvents=function(){var a;this.removeEvents(),a=this.events,this.options.disableResize||this.win.bind(q,a[q]),this.iOSNativeScrolling||(this.slider.bind(k,a[g]),this.pane.bind(k,a[p]).bind(""+n+" "+f,a[v])),this.$content.bind(""+r+" "+n+" "+f+" "+t,a[r])},i.prototype.removeEvents=function(){var a;a=this.events,this.win.unbind(q,a[q]),this.iOSNativeScrolling||(this.slider.unbind(),this.pane.unbind()),this.$content.unbind(""+r+" "+n+" "+f+" "+t,a[r])},i.prototype.generate=function(){var a,c,d,f,g,h;return f=this.options,g=f.paneClass,h=f.sliderClass,a=f.contentClass,this.$el.find("."+g).length||this.$el.find("."+h).length||this.$el.append('
'),this.pane=this.$el.children("."+g),this.slider=this.pane.find("."+h),0===e&&A()?(d=b.getComputedStyle(this.content,null).getPropertyValue("padding-right").replace(/\D+/g,""),c={right:-14,paddingRight:+d+14}):e&&(c={right:-e},this.$el.addClass("has-scrollbar")),null!=c&&this.$content.css(c),this},i.prototype.restore=function(){this.stopped=!1,this.iOSNativeScrolling||this.pane.show(),this.addEvents()},i.prototype.reset=function(){var a,b,c,f,g,h,i,j,k,l,m,n;return this.iOSNativeScrolling?void(this.contentHeight=this.content.scrollHeight):(this.$el.find("."+this.options.paneClass).length||this.generate().stop(),this.stopped&&this.restore(),a=this.content,f=a.style,g=f.overflowY,d&&this.$content.css({height:this.$content.height()}),b=a.scrollHeight+e,l=parseInt(this.$el.css("max-height"),10),l>0&&(this.$el.height(""),this.$el.height(a.scrollHeight>l?l:a.scrollHeight)),i=this.pane.outerHeight(!1),k=parseInt(this.pane.css("top"),10),h=parseInt(this.pane.css("bottom"),10),j=i+k+h,n=Math.round(j/b*j),nthis.options.sliderMaxHeight&&(n=this.options.sliderMaxHeight),g===r&&f.overflowX!==r&&(n+=e),this.maxSliderTop=j-n,this.contentHeight=b,this.paneHeight=i,this.paneOuterHeight=j,this.sliderHeight=n,this.slider.height(n),this.events.scroll(),this.pane.show(),this.isActive=!0,a.scrollHeight===a.clientHeight||this.pane.outerHeight(!0)>=a.scrollHeight&&g!==r?(this.pane.hide(),this.isActive=!1):this.el.clientHeight===a.scrollHeight&&g===r?this.slider.hide():this.slider.show(),this.pane.css({opacity:this.options.alwaysVisible?1:"",visibility:this.options.alwaysVisible?"visible":""}),c=this.$content.css("position"),("static"===c||"relative"===c)&&(m=parseInt(this.$content.css("right"),10),m&&this.$content.css({right:"",marginRight:m})),this)},i.prototype.scroll=function(){return this.isActive?(this.sliderY=Math.max(0,this.sliderY),this.sliderY=Math.min(this.maxSliderTop,this.sliderY),this.$content.scrollTop((this.paneHeight-this.contentHeight+e)*this.sliderY/this.maxSliderTop*-1),this.iOSNativeScrolling||(this.updateScrollValues(),this.setOnScrollStyles()),this):void 0},i.prototype.scrollBottom=function(a){return this.isActive?(this.$content.scrollTop(this.contentHeight-this.$content.height()-a).trigger(n),this.stop().restore(),this):void 0},i.prototype.scrollTop=function(a){return this.isActive?(this.$content.scrollTop(+a).trigger(n),this.stop().restore(),this):void 0},i.prototype.scrollTo=function(a){return this.isActive?(this.scrollTop(this.$el.find(a).get(0).offsetTop),this):void 0},i.prototype.stop=function(){return w&&this.scrollRAF&&(w(this.scrollRAF),this.scrollRAF=null),this.stopped=!0,this.removeEvents(),this.iOSNativeScrolling||this.pane.hide(),this},i.prototype.destroy=function(){return this.stopped||this.stop(),!this.iOSNativeScrolling&&this.pane.length&&this.pane.remove(),d&&this.$content.height(""),this.$content.removeAttr("tabindex"),this.$el.hasClass("has-scrollbar")&&(this.$el.removeClass("has-scrollbar"),this.$content.css({right:""})),this},i.prototype.flash=function(){return!this.iOSNativeScrolling&&this.isActive?(this.reset(),this.pane.addClass("flashed"),setTimeout(function(a){return function(){a.pane.removeClass("flashed")}}(this),this.options.flashDelay),this):void 0},i}(),a.fn.nanoScroller=function(b){return this.each(function(){var c,d;if((d=this.nanoscroller)||(c=a.extend({},x,b),this.nanoscroller=d=new o(this,c)),b&&"object"==typeof b){if(a.extend(d.options,b),null!=b.scrollBottom)return d.scrollBottom(b.scrollBottom);if(null!=b.scrollTop)return d.scrollTop(b.scrollTop);if(b.scrollTo)return d.scrollTo(b.scrollTo);if("bottom"===b.scroll)return d.scrollBottom(0);if("top"===b.scroll)return d.scrollTop(0);if(b.scroll&&b.scroll instanceof a)return d.scrollTo(b.scroll);if(b.stop)return d.stop();if(b.destroy)return d.destroy();if(b.flash)return d.flash()}return d.reset()})},a.fn.nanoScroller.Constructor=o}(jQuery,window,document); + +// avchat.js +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.AVChatClient=e()}}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o0){clearTimeout(timers.shift()[1])}resolve(server)};ws.onclose=function(e){doClose();_emitter.emit("close",e)};ws.onmessage=function(message){var data=JSON.parse(message.data);var cmd=data.op?data.cmd+data.op:data.cmd;if(!cmd){cmd="{}"}if(_waitCommands.length>0&&_waitCommands[0][0]===cmd){_waitCommands.shift()[1](data)}if(timers.length>0&&timers[0][0]==cmd){clearTimeout(timers.shift()[1])}if(data.cmd=="session"){if(data.op=="opened"||data.op=="added"){_emitter.emit("online",data.onlineSessionPeerIds)}}else if(data.cmd=="presence"){if(data.status=="on"){_emitter.emit("online",data.sessionPeerIds)}else if(data.status=="off"){_emitter.emit("offline",data.sessionPeerIds)}}else if(data.cmd=="direct"){_emitter.emit("message",data);var msg={cmd:"ack",peerId:_settings.peerId,appId:_settings.appId,ids:[].concat(data.id)};var s=JSON.stringify(msg);ws.send(s)}else if(data.cmd=="room"){if(data.op=="members-joined"){_emitter.emit("membersJoined",data)}else if(data.op=="members-left"){_emitter.emit("membersLeft",data)}else if(data.op=="joined"){_emitter.emit("joined",data)}else if(data.op=="left"){_emitter.emit("left",data)}}}})}else{return _getServerInfo(_settings.appId,_settings.secure).then(function(result){server=result;server.expires=Date.now()+server.ttl*1e3;return _connect()})}}function _openSession(){return _settings.auth(_settings.peerId,_settings.watchingPeerIds,_settings.sp).then(function(data){_settings.watchingPeerIds=data.watchingPeerIds;return doCommand("session","open",{sessionPeerIds:data.watchingPeerIds,s:data.s,t:data.t,n:data.n,sp:data.sp})})}function _timeout(name,reject){timers.push([name,setTimeout(function(){if(reject){reject(name+"timeout")}doClose()},1e4)])}function _keepAlive(){clearTimeout(_keepAlive.handle);_keepAlive.handle=setTimeout(function(){if(ws.readyState==1){ws.send("{}");_timeout("{}");_keepAlive()}},keepAliveTimeout)}function doClose(){ws.close();clearTimeout(_keepAlive.handle);timers.forEach(function(v,i){clearTimeout(v[1])});_waitCommands.forEach(function(v){v[2]()});timers=[];_waitCommands=[]}function doCommand(cmd,op,props){_keepAlive();var msg={cmd:cmd,peerId:_settings.peerId,appId:_settings.appId};if(op){msg.op=op}if(props){for(k in props){msg[k]=props[k]}}if(!ws){return Promise.reject()}if(ws.readyState!=1){return Promise.reject(ws.readyState)}ws.send(JSON.stringify(msg));var c=typeof op=="undefined"?cmd:cmd+op;if(cmd=="direct"&&props.transient==true||["sessionremove","sessionclose"].indexOf(c)>-1){return Promise.resolve()}else{return new Promise(function(resolve,reject){_waitCommands.push([cmdMap[c]||c,resolve,reject]);_timeout(cmdMap[c]||c,reject)})}}this.open=function(){if(ws&&ws.readyState==0){return Promise.reject(0)}if(ws&&ws.readyState==1){return Promise.resolve()}timers.forEach(function(v,i){clearTimeout(v[1])});timers=[];return _connect().then(function(){return _openSession()})};this.close=function(){doCommand("session","close");doClose();return Promise.resolve()};this.send=function(msg,to,transient){var obj={msg:msg,toPeerIds:[].concat(to)};if(typeof transient!="undefined"&&transient==true){obj.transient=transient}return doCommand("direct",undefined,obj)};this.on=function(name,func){_emitter.on(name,func)};this.watch=function(peers){return _settings.auth(_settings.peerId,[].concat(peers)).then(function(data){var watch=[].concat(data.watchingPeerIds);watch.forEach(function(v,k){if(_settings.watchingPeerIds.indexOf(v)==-1){_settings.watchingPeerIds.push(v)}});return doCommand("session","add",{sessionPeerIds:[].concat(data.watchingPeerIds),s:data.s,t:data.t,n:data.n})})};this.unwatch=function(peers){peers.forEach(function(v,k){if(_settings.watchingPeerIds.indexOf(v)>-1){_settings.watchingPeerIds.splice(_settings.watchingPeerIds.indexOf(v),1)}});return doCommand("session","remove",{sessionPeerIds:[].concat(peers)})};this.getStatus=function(peers){return doCommand("session","query",{sessionPeerIds:[].concat(peers)})};this.joinGroup=function(groupId){return _settings.groupAuth(_settings.peerId,groupId,"join",[]).then(function(data){return doCommand("room","join",{roomId:groupId,s:data.s,t:data.t,n:data.n})})};this.sendToGroup=function(msg,groupId,transient){var obj={msg:msg,roomId:groupId};if(typeof transient!="undefined"&&transient==true){obj.transient=transient}return doCommand("direct",undefined,obj)};this.inviteToGroup=function(groupId,groupPeerIds){return _settings.groupAuth(_settings.peerId,groupId,"invite",[].concat(groupPeerIds)).then(function(data){return doCommand("room","invite",{roomId:groupId,roomPeerIds:[].concat(data.groupPeerIds),s:data.s,t:data.t,n:data.n})})};this.kickFromGroup=function(groupId,groupPeerIds){return _settings.groupAuth(_settings.peerId,groupId,"kick",[].concat(groupPeerIds)).then(function(data){return doCommand("room","kick",{roomId:groupId,roomPeerIds:[].concat(groupPeerIds),s:data.s,t:data.t,n:data.n})})};this.leaveGroup=function(groupId){return doCommand("room","leave",{roomId:groupId})}}function get(url){if(typeof jQuery!=="undefined"){return Promise.resolve(jQuery.getJSON.call(jQuery,url+="&cb=?"))}else{return new Promise(function(resolve,reject){var req=new XMLHttpRequest;req.open("GET",url);req.onload=function(){if(req.status==200){resolve(JSON.parse(req.responseText))}else{reject(Error(req.statusText))}};req.onerror=function(){reject(Error("Network Error"))};req.send()})}}},{"es6-promise":2,events:12,ws:undefined,xmlhttprequest:undefined}],2:[function(require,module,exports){"use strict";var Promise=require("./promise/promise").Promise;var polyfill=require("./promise/polyfill").polyfill;exports.Promise=Promise;exports.polyfill=polyfill},{"./promise/polyfill":6,"./promise/promise":7}],3:[function(require,module,exports){"use strict";var isArray=require("./utils").isArray;var isFunction=require("./utils").isFunction;function all(promises){var Promise=this;if(!isArray(promises)){throw new TypeError("You must pass an array to all.")}return new Promise(function(resolve,reject){var results=[],remaining=promises.length,promise;if(remaining===0){resolve([])}function resolver(index){return function(value){resolveAll(index,value)}}function resolveAll(index,value){results[index]=value;if(--remaining===0){resolve(results)}}for(var i=0;i0&&this._events[type].length>m){this._events[type].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[type].length);if(typeof console.trace==="function"){console.trace()}}}return this};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.once=function(type,listener){if(!isFunction(listener))throw TypeError("listener must be a function");var fired=false;function g(){this.removeListener(type,g);if(!fired){fired=true;listener.apply(this,arguments)}}g.listener=listener;this.on(type,g);return this};EventEmitter.prototype.removeListener=function(type,listener){var list,position,length,i;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events||!this._events[type])return this;list=this._events[type];length=list.length;position=-1;if(list===listener||isFunction(list.listener)&&list.listener===listener){delete this._events[type];if(this._events.removeListener)this.emit("removeListener",type,listener)}else if(isObject(list)){for(i=length;i-->0;){if(list[i]===listener||list[i].listener&&list[i].listener===listener){position=i;break}}if(position<0)return this;if(list.length===1){list.length=0;delete this._events[type]}else{list.splice(position,1)}if(this._events.removeListener)this.emit("removeListener",type,listener)}return this};EventEmitter.prototype.removeAllListeners=function(type){var key,listeners;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[type])delete this._events[type];return this}if(arguments.length===0){for(key in this._events){if(key==="removeListener")continue;this.removeAllListeners(key)}this.removeAllListeners("removeListener");this._events={};return this}listeners=this._events[type];if(isFunction(listeners)){this.removeListener(type,listeners)}else{while(listeners.length)this.removeListener(type,listeners[listeners.length-1])}delete this._events[type];return this};EventEmitter.prototype.listeners=function(type){var ret;if(!this._events||!this._events[type])ret=[];else if(isFunction(this._events[type]))ret=[this._events[type]];else ret=this._events[type].slice();return ret};EventEmitter.listenerCount=function(emitter,type){var ret;if(!emitter._events||!emitter._events[type])ret=0;else if(isFunction(emitter._events[type]))ret=1;else ret=emitter._events[type].length;return ret};function isFunction(arg){return typeof arg==="function"}function isNumber(arg){return typeof arg==="number"}function isObject(arg){return typeof arg==="object"&&arg!==null}function isUndefined(arg){return arg===void 0}},{}],13:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}]},{},[1])(1)}); + +// EventEmitter.js +(function(){"use strict";function t(){}function i(t,n){for(var e=t.length;e--;)if(t[e].listener===n)return e;return-1}function n(e){return function(){return this[e].apply(this,arguments)}}var e=t.prototype,r=this,s=r.EventEmitter;e.getListeners=function(n){var r,e,t=this._getEvents();if(n instanceof RegExp){r={};for(e in t)t.hasOwnProperty(e)&&n.test(e)&&(r[e]=t[e])}else r=t[n]||(t[n]=[]);return r},e.flattenListeners=function(t){var e,n=[];for(e=0;e]+)?%>/g, + reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, + code = 'var r=[];\n', + cursor = 0; + + var add = function(line, js) { + js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : + (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : ''); + return add; + } + + while(match = re.exec(html)) { + add(html.slice(cursor, match.index))(match[1], true); + cursor = match.index + match[0].length; + } + + add(html.substr(cursor, html.length - cursor)); + + code += 'return r.join("");'; + + return new Function(code.replace(/[\r\t\n]/g, '')).apply(options); + }; + + function freeTextarea($dom, maxHeight) { + var ta = $dom, + maxHeight = maxHeight || 70, + css = (function() { + var css = {}, i = 8, + z = 'width fontSize fontFamily lineHeight wordWrap wordBreak whiteSpace letterSpacing'.split(' '); + + while(i--) css[z[i]] = ta.css(z[i]); + return $.extend(css, {position : 'absolute', left : -9999, top : 0}); + })(), + + _ta=ta.clone().css(css).attr({id : '', name : '', tabIndex : -1}), + stCur, valCur, defHeight = ta.height(), + both=$([ta[0], _ta[0]]), + + autoHeight = function() { + valCur = ta.val(); + _ta.val(valCur).height(1).scrollTop(9999); + + stCur = Math.min(Math.max(defHeight, _ta.scrollTop()), maxHeight); + + both.height(stCur); + }; + + ta.after(_ta).bind("focus input change propertychange", autoHeight); + }; + + function log(msg) { + if(!Green.debug) return; + + $('.log').append('

'+this.tranTime(new Date())+':'+msg+'

'); + }; + + return { + isDifferentDay : isDifferentDay, + tranTime : tranTime, + template : template, + freeTextarea : freeTextarea, + log : log + }; + +}(window, document, Green); + + +// 状态提示组件 +Green._StatusView = function(window, document, Green, Utils) { + var StatusView = {}; + + StatusView.commit = function() { + var render = '
'; + + this.dom = $(render); + + return this.dom; + }; + + StatusView.msg = function(log) { + this.dom.html(log).show(); + }; + + StatusView.hide = function() { + this.dom.hide(); + }; + + return StatusView; + +}(window, document, Green, EventEmitter); + + +// 联系人组件 +Green._RosterView = function (window, document, Green, Utils, EventHandler) { + function RosterView(roster) { + this.roster = roster; + } + + RosterView.prototype.commit = function render() { + var render = '
' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '
' + + '
' + + '
'+this.roster.name+'
' + + '
' + + '
' + + '
'; + + this.dom = $(render); + + this.dom.click($.proxy(function() { + EventHandler.trigger('rosterClick', [this]); + }, this)); + + return this.dom; + }; + + RosterView.prototype.updateUnread = function(num) { + var unreadDom = this.dom.find(".unread-dot"); + + this.roster.unreadCount = num; + + if(num == 0) { + unreadDom.hide(); + } + else { + unreadDom.html(num).show(); + } + }; + + RosterView.prototype.updateOnlineStatus = function(status) { + this.roster.onlineStatus = status; + + this.dom.find(".chat-status").removeClass().addClass( 'chat-status ' + status); + }; + + return RosterView; + +}(window, document, Green, Green._Utils, Green._EventHandler); + + +// 联系人列表组件 +Green._RosterListView = function(window, document, Green, Utils, EventHandler, RosterView) { + var RosterListView = {}; + + RosterListView.commit = function(rosters) { + var render = '
'+ + '
 聊天联系人
'+ + '
'+ + '
在线
 
 收缩
'+ + '
'; + + this.dom = $(render); + + this.rosterViews = {}; + + $.each(rosters, function(id, roster) { + var rosterView = new RosterView( roster ); + + RosterListView.rosterViews[id] = rosterView; + + RosterListView.dom.find('.active').append( rosterView.commit() ); + }); + + // 精简模式 详细模式转换 + this.dom.find('.title, .toggle-btn').click(function() { + EventHandler.trigger('rosterListViewToggle', [!RosterListView.dom.hasClass('contacts-minus')]); + }); + + return this.dom; + }; + + RosterListView.init = function() { + var titHeight = 40; + var botHeight = 30; + var offset = 62; + + var listHeight = $(window).height() - offset; + var innerHeight = $(window).height() - offset - titHeight - botHeight; + + var domNano = RosterListView.dom.find('.nano'); + domNano.css('height', innerHeight + 'px'); + domNano.nanoScroller(); + + this.height = listHeight; + this.innerHeight = innerHeight; + }; + + RosterListView.get = function(id) { + return this.rosterViews[id]; + }; + + RosterListView.toggle = function(status) { + if( status ) { + this.dom.addClass('contacts-minus'); + } + else { + this.dom.removeClass('contacts-minus'); + } + }; + + RosterListView.prepend = function(id) { + this.get(id).dom.prependTo( this.dom.find('.active') ); + }; + + RosterListView.hide = function() { + this.dom.hide(); + }; + + RosterListView.show = function() { + this.dom.show(); + }; + + return RosterListView; + +}(window, document, Green, Green._Utils, Green._EventHandler, Green._RosterView); + + +// 会话窗口组件 +Green._ConverseView = function(window, document, Green, Utils, EventHandler) { + function ConverseView(roster) { + this.roster = roster; + } + + ConverseView.prototype.commit = function() { + var render = '
'+ + '
'+ + '
无更多历史消息
'+ + '
更多历史消息
历史消息加载中...
'+ + '
'+ + '
'; + + this.dom = $(render); + + _init.call(this); + + return this.dom; + }; + + function _init() { + var domLoadmore = this.dom.find('.loadmore'); + domLoadmore.click($.proxy(function() { + if( domLoadmore.hasClass('loadmore-loading') ) { + return false; + } + + domLoadmore.addClass('loadmore-loading'); + + // AVHistoryMessageQuery + var data = { + convid : [Green.me.id, this.roster.id], + timestamp : this.lastMessage.timestamp, + limit : 30 + }; + + EventHandler.trigger('getHistory', [data, this]); + }, this)); + + + + this.lastMessage = {}; + + // 是否有未读的消息 + var unreadMessages = this.roster.unreadMessages; + + if( unreadMessages.length == 0 ) { + this.lastMessage['timestamp'] = new Date().getTime(); + + domLoadmore.trigger('click');// think think!!!! + } + else { + this.lastMessage = unreadMessages[0]; + + this.renderMessage(unreadMessages, 'receive') + + this.roster.unreadMessages = []; + } + }; + + ConverseView.prototype.renderMessage = function( messages, mode ) { + if( !(messages instanceof Array) ) messages = [messages]; + + var renderStr = ''; + var date; + var message; + var sendStatus; + for(var i=0, len=messages.length; i' + + '
'+message.name+':'+message.date+'
' + + '
' + + ''+message.name+'' + + '
' + + '
' + + '
' + + '
'+ + '
'+message.message+'
'+ + '
' + + '
' + + '
' + + '
' + + '
' + sendStatus + + '
' + + '
'; + } + + var domMessage = $(renderStr) + + if( mode == 'history' ) { + var nowPosition = this.getPosition(); + + this.dom.find('.loadmore').after(domMessage); + + this.scroll(); + this.adjustPosition(nowPosition); + } + + if( mode == 'receive' || mode == 'send' ) { + this.dom.find('.messages').append(domMessage); + + this.scroll(); + this.scrollDown(); + } + + if( mode == 'notCurrent' ) { + this.dom.find('.messages').append(domMessage); + + this.scroll(); + } + + return domMessage; + }; + + ConverseView.prototype.showLoadmore = function() { + this.dom.find('.loadmore').removeClass('loadmore-loading').show().find('b').html('更多历史消息'); + }; + + ConverseView.prototype.showHistoryFailed = function() { + this.dom.find('.loadmore').removeClass('loadmore-loading').show().find('b').html('加载历史信息失败 点击重试'); + }; + + ConverseView.prototype.showNoHistory = function() { + this.dom.find('.loadmore').hide(); + + this.dom.find('.no-more-history').show(); + } + + ConverseView.prototype.scrollDown = function() { + // this.dom.nanoScroller({ scroll: 'bottom' }); + // 貌似视觉效果好些 + var domMessage = this.dom.find('.messages'); + domMessage.stop().animate( {scrollTop : domMessage[0].scrollHeight} ); + }; + + ConverseView.prototype.adjustPosition = function(pre) { + this.dom.nanoScroller({ scrollTop: this.getPosition()-pre }); + }; + + ConverseView.prototype.getPosition = function() { + return this.dom.find('.messages')[0].scrollHeight; + }; + + ConverseView.prototype.scroll = function() { + this.dom.nanoScroller({ preventPageScrolling: true, alwaysVisible: true }); + }; + + ConverseView.prototype.destroy = function() { + this.dom.nanoScroller({ destroy: true }); + this.dom.remove(); + + delete this; + }; + + return ConverseView; + +}(window, document, Green, Green._Utils, Green._EventHandler); + +// 会话窗口列表管理组件 +Green._ConverseListView = function(window, document, Green, Utils, EventHandler, ConverseView) { + var ConverseListView = {}; + + ConverseListView.commit = function() { + var render = '
'; + + this.dom = $(render); + + this.converseListViews = {}; + + return this.dom; + }; + + // 添加一个会话窗口 + ConverseListView.add = function(roster) { + var view = this.get(roster.id); + if( view ) return view; + + var converseView = new ConverseView( roster ); + + this.converseListViews[roster.id] = converseView; + + this.dom.append( converseView.commit() ); + + this.currentView = converseView; + + return converseView; + }; + + ConverseListView.get = function(id) { + return this.converseListViews[id]; + }; + + ConverseListView.front = function(id) { + this.get(id).dom.css('zIndex', 100).siblings().css('zIndex', 99); + }; + + ConverseListView.show = function() { + this.dom.show(); + }; + + ConverseListView.hide = function() { + this.dom.hide(); + }; + + ConverseListView.remove = function(id) { + this.get(id).destroy(); + + delete this.converseListViews[id]; + }; + + ConverseListView.removeAll = function() { + $.each(this.converseListViews, function(k, v) { + v.destroy(); + }); + + this.converseListViews = {}; + + this.currentView = null; + }; + + return ConverseListView; + +}(window, document, Green, Green._Utils, Green._EventHandler, Green._ConverseView); + + +// 会话联系人组件 +Green._ChatWithView = function(window, document, Green, Utils, EventHandler) { + function ChatWithView(roster) { + this.roster = roster; + } + + ChatWithView.prototype.commit = function render() { + var render = '
' + + '
' + + '
'+this.roster.name+'
' + + '' + + '' + + '
'; + + this.dom = $(render); + + _init.call(this); + + return this.dom; + }; + + function _init() { + this.dom.click($.proxy(function() { + EventHandler.trigger('chatWithClick', [this]); + }, this)); + + this.dom.find('.icon-remove').click($.proxy(function() { + EventHandler.trigger('chatWithRemove', [this]); + }, this)); + }; + + ChatWithView.prototype.updateUnread = function(num) { + var unreadDom = this.dom.find(".msg-unread"); + + this.roster.unreadCount = num; + + if(num == 0) { + unreadDom.hide(); + } + else { + unreadDom.show(); + } + }; + + ChatWithView.prototype.updateOnlineStatus = function(status) { + this.roster.onlineStatus = status; + + this.dom.find(".chat-status").removeClass().addClass( 'chat-status ' + status); + }; + + ChatWithView.prototype.active = function() { + this.dom.addClass('active').siblings().removeClass('active'); + }; + + ChatWithView.prototype.destroy = function() { + this.dom.remove(); + + delete this; + }; + + return ChatWithView; + +}(window, document, Green, Green._Utils, Green._EventHandler); + + +// 会话联系人列表组件 +Green._ChatWithListView = function(window, document, Green, Utils, ChatWithView, EventHandler) { + var ChatWithListView = {}; + + ChatWithListView.commit = function() { + var render = '
'+ + '
洽谈列表
'+ + '
'+ + '
'; + + this.dom = $(render); + + this.chatWithViews = []; + + return this.dom; + }; + + ChatWithListView.add = function(roster) { + var view = this.get(roster.id); + if( view ) return view; + + var chatWithView = new ChatWithView( roster ); + + this.chatWithViews.push(chatWithView); + + this.dom.find('.nano-content').append( chatWithView.commit() ); + + this.dom.find('.nano').nanoScroller(); + + return chatWithView; + }; + + ChatWithListView.get = function(id) { + var views = this.chatWithViews; + + for( var i=0, len=views.length; i
  
'+ + '
'+ + ''; + + this.dom = $(render); + + this.dom.prepend( ChatWithListView.commit() ); + + this.dom.find('.chatbox').append( ConverseListView.commit() ); + + this.dom.find('.chatbox').append( InputView.commit() ); + + _init.call(this); + + return this.dom; + }; + + function _init() { + this.dom.find('.icon-minus').click(function() { + ChatboxView.minifiy(); + return false; + }); + + this.dom.find('.minus-pannel').click(function() { + EventHandler.trigger('chatboxMaxfiy'); + + return false; + }); + + this.dom.find('.icon-remove').click(function() { + ChatboxView.remove(); + return false; + }); + }; + + ChatboxView.get = function(id) { + return this.rosterViews[id]; + }; + + ChatboxView.toggle = function(status) { + if( status ) { + this.dom.addClass('chatbox-wrap-contacts-minus'); + } + else { + this.dom.removeClass('chatbox-wrap-contacts-minus'); + } + }; + + ChatboxView.isMinus = function() { + return this.dom.hasClass('chatbox-minus'); + }; + + ChatboxView.maxfiy = function() { + this.dom.removeClass('chatbox-minus'); + + if( this.dom.hasClass('chat-new-message') ) { + this.dom.removeClass('chat-new-message'); + } + }; + + ChatboxView.minifiy = function() { + return this.dom.addClass('chatbox-minus'); + }; + + ChatboxView.beMulti = function() { + this.dom.addClass('multi-chatbox'); + }; + + ChatboxView.cleanMulti = function() { + this.dom.removeClass('multi-chatbox'); + }; + + ChatboxView.hide = function() { + return this.dom.hide(); + }; + + ChatboxView.show = function() { + return this.dom.show(); + }; + + ChatboxView.remove = function() { + ChatWithListView.removeAll(); + ConverseListView.removeAll(); + + this.hide(); + }; + + return ChatboxView; + +}(window, document, Green, Green._Utils, Green._EventHandler, Green._ChatWithListView, Green._ConverseListView, Green._InputView); + + +// 聊天服务器组件 +Green._Server = function(window, document, Green, Utils, EventHandler) { + var Server = {}; + + var reconnectTimes = 0; + var reconnectLimit = 0; + + var appId = '0s66p2ntvx0q56pk5mh8wxa7cuegr57w5abvb7nwv5dqymyo'; + + var handler; + + Server.isOpen = false; + + Server.init = function() { + handler = new AVChatClient({ + appId: appId, + peerId: Green.me.id, + auth: _auth, // 需要身份验证的时候加上 + // groupAuth: groupAuth, + watchingPeerIds: Green.watch + }); + + handler.on('close', function(event) { + _onClose(event); + }); + + handler.on('message', function(data) { + _onMessage(data); + }); + + handler.on('online', function(rosters) { + _onOnline(rosters); + }); + + handler.on('offline', function(rosters) { + _onOffline(rosters); + }); + + _connect(); + } + + function _connect() { + if( !Server.isOpen && reconnectTimes==0 ) EventHandler.trigger('onConnectStart'); + + handler.open().then(function() { + Server.isOpen = true; + + reconnectTimes = 0; + + EventHandler.trigger('onConnectSuccess'); + + }, function(err) { + EventHandler.trigger('onConnectError'); + }); + } + + function _onMessage(data) { + // console.log(data);//--------------------- + + var message = {'from' : data.fromPeerId, 'to' : data.peerId, 'data' : data.msg, 'timestamp' : data.timestamp}; + + if( data.toPeerIds ) { + message.to = data.toPeerIds[0]; + } + + EventHandler.trigger('messageReceived', [message]); + } + + function _onClose(event) { + Server.isOpen = false; + + if(reconnectTimes < reconnectLimit) { + reconnectTimes++; + + EventHandler.trigger('onReconnect', [reconnectTimes]); + + Server.init(); + } + else { + EventHandler.trigger('onConnectClose'); + } + } + + function _onOnline(ids) { + for(var i=0, len=ids.length; i'+Green.me.name+''); + + Green.watch = []; + + var rosters = {}; + for(var i = 0, len = data.rosters.length; i < len; i++) { + data.rosters[i]['id'] = data.rosters[i]['id'].toString(); + + Green.watch.push(data.rosters[i]['id']); + + rosters[data.rosters[i]['id']] = { + id : data.rosters[i]['id'] , + name : data.rosters[i]['name'] , + image : data.rosters[i]['image'] , + unreadCount : 0 , + onlineStatus : 'offline' , + unreadMessages : [] + }; + } + + Green.rosters = rosters; + + EventHandler.trigger('getRostersSuccess'); + }, + error : function() { + + } + }); + }; + + Server.getHistory = function(param, converse) { + if( !this.conversationUrl ) return false; + + //请求聊天列表 + $.ajax({ + type : "POST", + url : this.conversationUrl, + data : param, + success : function(msg) { + try { + var data = $.parseJSON(msg); + var messages = []; + + for(var i=0, len=data.length; i 1 ) { + ChatboxView.beMulti(); + } + + ConverseListView.add(rosterView.roster); + + EventHandler.trigger('chatWithClick', [chatWithView]); + }); + + EventHandler.on('chatWithClick', function(chatWithView) { + var roster = chatWithView.roster; + + RosterListView.get(roster.id).updateUnread(0); + + chatWithView.updateUnread(0); + chatWithView.active(); + + ConverseListView.front(roster.id); + ConverseListView.currentView = ConverseListView.get(roster.id); + ConverseListView.currentView.scroll(); + + if( ChatboxView.isMinus ) ChatboxView.maxfiy(); + + ChatboxView.dom.find('.chat-with img').attr('src', roster.image); + ChatboxView.dom.find('.chat-with .chat-name').html(roster.name); + ChatboxView.dom.find('.cur-chat-name').html(roster.name); + }); + + + EventHandler.on('chatWithRemove', function(chatWithView) { + ChatWithListView.remove(chatWithView); + + ConverseListView.remove(chatWithView.roster.id); + + if( ChatWithListView.chatWithViews.length == 1 ) { + ChatboxView.cleanMulti(); + } + }); + + + EventHandler.on('chatboxMaxfiy', function() { + var curId = ConverseListView.currentView.roster.id; + + RosterListView.get(curId).updateUnread(0); + + ChatboxView.maxfiy(); + }); + + + EventHandler.on('sendMessageEnter', function(text) { + if( !Server.isOpen ) alert('连接已断开,刷新重试'); + + InputView.reset(); + + var converseView = ConverseListView.currentView; + + var message = { + from : Green.me.id, + to : converseView.roster.id, + data : text, + timestamp : new Date().getTime() + }; + var domMessage = converseView.renderMessage(message, 'send'); + + Server.sendMessage(message, domMessage); + }); + + EventHandler.on('sendMessageSuccess', function(message, domMessage) { + domMessage.addClass('send-success'); + }); + + EventHandler.on('sendMessageFailed', function(message, domMessage) { + domMessage.addClass('send-failed'); + }); + + + + EventHandler.on('getHistory', function(param, converse) { + Server.getHistory(param, converse); + }); + + EventHandler.on('getHistorySuccess', function(param, converseView, data) { + if( data === false ) { + converseView.showHistoryFailed(); + return false; + } + + if( !data || data.length == 0 ) { + converseView.showNoHistory(); + return false; + } + + data.reverse(); + + converseView.lastMessage = data[0]; + + converseView.renderMessage(data, 'history'); + + if( data.length < 30 ) { + converseView.showNoHistory(); + } + else { + converseView.showLoadmore(); + } + }); + + EventHandler.on('getHistoryFailed', function(param, converseView) { + converseView.showHistoryFailed(); + }); + + + + EventHandler.on('messageReceived', function(message) { + // 多窗口信息同步 + if( message.from == Green.me.id ) { + if( ConverseListView.get(message.to) ) { + var chatWithView = ChatWithListView.get(message.to); + + EventHandler.trigger('chatWithClick', [chatWithView]); + + ConverseListView.get(message.to).renderMessage(message, 'receive'); + + ChatWithListView.prepend(message.to); + } else { + var rosterView = RosterListView.get(message.to); + + rosterView.roster.unreadMessages.push(message); + + EventHandler.trigger('rosterClick', [rosterView]); + } + + RosterListView.prepend(message.to); + + return false; + } + + var rosterView = RosterListView.get(message.from); + if( !rosterView ) return false; + + var unreadCount = rosterView.roster.unreadCount; + unreadCount++; + + RosterListView.prepend(message.from); + + if( ConverseListView.get(message.from) ) {// 聊天窗口存在 + var chatWithView = ChatWithListView.get(message.from); + var converseView = ConverseListView.get(message.from); + var isCur = ConverseListView.currentView.roster.id == message.from; + + ChatWithListView.prepend(message.from); + + if( ChatboxView.isMinus() ) { + ChatboxView.dom.addClass('chat-new-message'); + + chatWithView.updateUnread( unreadCount ); + rosterView.updateUnread( unreadCount ); + + converseView.renderMessage(message, 'notCurrent'); + } else { + if( !isCur ) { + chatWithView.updateUnread( unreadCount ); + rosterView.updateUnread( unreadCount ); + + converseView.renderMessage(message, 'notCurrent'); + } else { + converseView.renderMessage(message, 'receive'); + } + } + + } else { + rosterView.updateUnread(unreadCount); + + rosterView.roster.unreadMessages.push(message); + } + }); + + return init; + +}(window, document, Green, Green._Utils, Green._EventHandler, Green._ChatboxView, Green._RosterListView, Green._ChatWithListView, Green._ConverseListView, Green._InputView, Green._StatusView, Green._Server); + diff --git a/script/green.min.js b/script/green.min.js new file mode 100644 index 0000000..a56f1f4 --- /dev/null +++ b/script/green.min.js @@ -0,0 +1,11 @@ +/*! nanoScrollerJS - v0.8.0 - (c) 2014 James Florentino; Licensed MIT */ +!function(a,b,c){"use strict";var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F;x={paneClass:"nano-pane",sliderClass:"nano-slider",contentClass:"nano-content",iOSNativeScrolling:!1,preventPageScrolling:!1,disableResize:!1,alwaysVisible:!1,flashDelay:1500,sliderMinHeight:20,sliderMaxHeight:null,documentContext:null,windowContext:null},s="scrollbar",r="scroll",k="mousedown",l="mousemove",n="mousewheel",m="mouseup",q="resize",h="drag",u="up",p="panedown",f="DOMMouseScroll",g="down",v="wheel",i="keydown",j="keyup",t="touchmove",d="Microsoft Internet Explorer"===b.navigator.appName&&/msie 7./i.test(b.navigator.appVersion)&&b.ActiveXObject,e=null,B=b.requestAnimationFrame,w=b.cancelAnimationFrame,D=c.createElement("div").style,F=function(){var a,b,c,d,e,f;for(d=["t","webkitT","MozT","msT","OT"],a=e=0,f=d.length;f>e;a=++e)if(c=d[a],b=d[a]+"ransform",b in D)return d[a].substr(0,d[a].length-1);return!1}(),E=function(a){return F===!1?!1:""===F?a:F+a.charAt(0).toUpperCase()+a.substr(1)},C=E("transform"),z=C!==!1,y=function(){var a,b,d;return a=c.createElement("div"),b=a.style,b.position="absolute",b.width="100px",b.height="100px",b.overflow=r,b.top="-9999px",c.body.appendChild(a),d=a.offsetWidth-a.clientWidth,c.body.removeChild(a),d},A=function(){var a,c,d;return c=b.navigator.userAgent,(a=/(?=.+Mac OS X)(?=.+Firefox)/.test(c))?(d=/Firefox\/\d{2}\./.exec(c),d&&(d=d[0].replace(/\D+/g,"")),a&&+d>23):!1},o=function(){function i(d,f){this.el=d,this.options=f,e||(e=y()),this.$el=a(this.el),this.doc=a(this.options.documentContext||c),this.win=a(this.options.windowContext||b),this.$content=this.$el.children("."+f.contentClass),this.$content.attr("tabindex",this.options.tabIndex||0),this.content=this.$content[0],this.previousPosition=0,this.options.iOSNativeScrolling&&null!=this.el.style.WebkitOverflowScrolling?this.nativeScrolling():this.generate(),this.createEvents(),this.addEvents(),this.reset()}return i.prototype.preventScrolling=function(a,b){if(this.isActive)if(a.type===f)(b===g&&a.originalEvent.detail>0||b===u&&a.originalEvent.detail<0)&&a.preventDefault();else if(a.type===n){if(!a.originalEvent||!a.originalEvent.wheelDelta)return;(b===g&&a.originalEvent.wheelDelta<0||b===u&&a.originalEvent.wheelDelta>0)&&a.preventDefault()}},i.prototype.nativeScrolling=function(){this.$content.css({WebkitOverflowScrolling:"touch"}),this.iOSNativeScrolling=!0,this.isActive=!0},i.prototype.updateScrollValues=function(){var a,b;a=this.content,this.maxScrollTop=a.scrollHeight-a.clientHeight,this.prevScrollTop=this.contentScrollTop||0,this.contentScrollTop=a.scrollTop,b=this.contentScrollTop>this.previousPosition?"down":this.contentScrollTop=a.maxScrollTop&&a.prevScrollTop!==a.maxScrollTop?a.$el.trigger("scrollend"):0===a.contentScrollTop&&0!==a.prevScrollTop&&a.$el.trigger("scrolltop"),!1}}(this),up:function(a){return function(){return a.isBeingDragged=!1,a.pane.removeClass("active"),a.doc.unbind(l,a.events[h]).unbind(m,a.events[u]),!1}}(this),resize:function(a){return function(){a.reset()}}(this),panedown:function(a){return function(b){return a.sliderY=(b.offsetY||b.originalEvent.layerY)-.5*a.sliderHeight,a.scroll(),a.events.down(b),!1}}(this),scroll:function(a){return function(b){a.updateScrollValues(),a.isBeingDragged||(a.iOSNativeScrolling||(a.sliderY=a.sliderTop,a.setOnScrollStyles()),null!=b&&(a.contentScrollTop>=a.maxScrollTop?(a.options.preventPageScrolling&&a.preventScrolling(b,g),a.prevScrollTop!==a.maxScrollTop&&a.$el.trigger("scrollend")):0===a.contentScrollTop&&(a.options.preventPageScrolling&&a.preventScrolling(b,u),0!==a.prevScrollTop&&a.$el.trigger("scrolltop"))))}}(this),wheel:function(a){return function(b){var c;if(null!=b)return c=b.delta||b.wheelDelta||b.originalEvent&&b.originalEvent.wheelDelta||-b.detail||b.originalEvent&&-b.originalEvent.detail,c&&(a.sliderY+=-c/3),a.scroll(),!1}}(this)}},i.prototype.addEvents=function(){var a;this.removeEvents(),a=this.events,this.options.disableResize||this.win.bind(q,a[q]),this.iOSNativeScrolling||(this.slider.bind(k,a[g]),this.pane.bind(k,a[p]).bind(""+n+" "+f,a[v])),this.$content.bind(""+r+" "+n+" "+f+" "+t,a[r])},i.prototype.removeEvents=function(){var a;a=this.events,this.win.unbind(q,a[q]),this.iOSNativeScrolling||(this.slider.unbind(),this.pane.unbind()),this.$content.unbind(""+r+" "+n+" "+f+" "+t,a[r])},i.prototype.generate=function(){var a,c,d,f,g,h;return f=this.options,g=f.paneClass,h=f.sliderClass,a=f.contentClass,this.$el.find("."+g).length||this.$el.find("."+h).length||this.$el.append('
'),this.pane=this.$el.children("."+g),this.slider=this.pane.find("."+h),0===e&&A()?(d=b.getComputedStyle(this.content,null).getPropertyValue("padding-right").replace(/\D+/g,""),c={right:-14,paddingRight:+d+14}):e&&(c={right:-e},this.$el.addClass("has-scrollbar")),null!=c&&this.$content.css(c),this},i.prototype.restore=function(){this.stopped=!1,this.iOSNativeScrolling||this.pane.show(),this.addEvents()},i.prototype.reset=function(){var a,b,c,f,g,h,i,j,k,l,m,n;return this.iOSNativeScrolling?void(this.contentHeight=this.content.scrollHeight):(this.$el.find("."+this.options.paneClass).length||this.generate().stop(),this.stopped&&this.restore(),a=this.content,f=a.style,g=f.overflowY,d&&this.$content.css({height:this.$content.height()}),b=a.scrollHeight+e,l=parseInt(this.$el.css("max-height"),10),l>0&&(this.$el.height(""),this.$el.height(a.scrollHeight>l?l:a.scrollHeight)),i=this.pane.outerHeight(!1),k=parseInt(this.pane.css("top"),10),h=parseInt(this.pane.css("bottom"),10),j=i+k+h,n=Math.round(j/b*j),nthis.options.sliderMaxHeight&&(n=this.options.sliderMaxHeight),g===r&&f.overflowX!==r&&(n+=e),this.maxSliderTop=j-n,this.contentHeight=b,this.paneHeight=i,this.paneOuterHeight=j,this.sliderHeight=n,this.slider.height(n),this.events.scroll(),this.pane.show(),this.isActive=!0,a.scrollHeight===a.clientHeight||this.pane.outerHeight(!0)>=a.scrollHeight&&g!==r?(this.pane.hide(),this.isActive=!1):this.el.clientHeight===a.scrollHeight&&g===r?this.slider.hide():this.slider.show(),this.pane.css({opacity:this.options.alwaysVisible?1:"",visibility:this.options.alwaysVisible?"visible":""}),c=this.$content.css("position"),("static"===c||"relative"===c)&&(m=parseInt(this.$content.css("right"),10),m&&this.$content.css({right:"",marginRight:m})),this)},i.prototype.scroll=function(){return this.isActive?(this.sliderY=Math.max(0,this.sliderY),this.sliderY=Math.min(this.maxSliderTop,this.sliderY),this.$content.scrollTop((this.paneHeight-this.contentHeight+e)*this.sliderY/this.maxSliderTop*-1),this.iOSNativeScrolling||(this.updateScrollValues(),this.setOnScrollStyles()),this):void 0},i.prototype.scrollBottom=function(a){return this.isActive?(this.$content.scrollTop(this.contentHeight-this.$content.height()-a).trigger(n),this.stop().restore(),this):void 0},i.prototype.scrollTop=function(a){return this.isActive?(this.$content.scrollTop(+a).trigger(n),this.stop().restore(),this):void 0},i.prototype.scrollTo=function(a){return this.isActive?(this.scrollTop(this.$el.find(a).get(0).offsetTop),this):void 0},i.prototype.stop=function(){return w&&this.scrollRAF&&(w(this.scrollRAF),this.scrollRAF=null),this.stopped=!0,this.removeEvents(),this.iOSNativeScrolling||this.pane.hide(),this},i.prototype.destroy=function(){return this.stopped||this.stop(),!this.iOSNativeScrolling&&this.pane.length&&this.pane.remove(),d&&this.$content.height(""),this.$content.removeAttr("tabindex"),this.$el.hasClass("has-scrollbar")&&(this.$el.removeClass("has-scrollbar"),this.$content.css({right:""})),this},i.prototype.flash=function(){return!this.iOSNativeScrolling&&this.isActive?(this.reset(),this.pane.addClass("flashed"),setTimeout(function(a){return function(){a.pane.removeClass("flashed")}}(this),this.options.flashDelay),this):void 0},i}(),a.fn.nanoScroller=function(b){return this.each(function(){var c,d;if((d=this.nanoscroller)||(c=a.extend({},x,b),this.nanoscroller=d=new o(this,c)),b&&"object"==typeof b){if(a.extend(d.options,b),null!=b.scrollBottom)return d.scrollBottom(b.scrollBottom);if(null!=b.scrollTop)return d.scrollTop(b.scrollTop);if(b.scrollTo)return d.scrollTo(b.scrollTo);if("bottom"===b.scroll)return d.scrollBottom(0);if("top"===b.scroll)return d.scrollTop(0);if(b.scroll&&b.scroll instanceof a)return d.scrollTo(b.scroll);if(b.stop)return d.stop();if(b.destroy)return d.destroy();if(b.flash)return d.flash()}return d.reset()})},a.fn.nanoScroller.Constructor=o}(jQuery,window,document); + +// avchat.js +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.AVChatClient=e()}}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o0){clearTimeout(timers.shift()[1])}resolve(server)};ws.onclose=function(e){doClose();_emitter.emit("close",e)};ws.onmessage=function(message){var data=JSON.parse(message.data);var cmd=data.op?data.cmd+data.op:data.cmd;if(!cmd){cmd="{}"}if(_waitCommands.length>0&&_waitCommands[0][0]===cmd){_waitCommands.shift()[1](data)}if(timers.length>0&&timers[0][0]==cmd){clearTimeout(timers.shift()[1])}if(data.cmd=="session"){if(data.op=="opened"||data.op=="added"){_emitter.emit("online",data.onlineSessionPeerIds)}}else if(data.cmd=="presence"){if(data.status=="on"){_emitter.emit("online",data.sessionPeerIds)}else if(data.status=="off"){_emitter.emit("offline",data.sessionPeerIds)}}else if(data.cmd=="direct"){_emitter.emit("message",data);var msg={cmd:"ack",peerId:_settings.peerId,appId:_settings.appId,ids:[].concat(data.id)};var s=JSON.stringify(msg);ws.send(s)}else if(data.cmd=="room"){if(data.op=="members-joined"){_emitter.emit("membersJoined",data)}else if(data.op=="members-left"){_emitter.emit("membersLeft",data)}else if(data.op=="joined"){_emitter.emit("joined",data)}else if(data.op=="left"){_emitter.emit("left",data)}}}})}else{return _getServerInfo(_settings.appId,_settings.secure).then(function(result){server=result;server.expires=Date.now()+server.ttl*1e3;return _connect()})}}function _openSession(){return _settings.auth(_settings.peerId,_settings.watchingPeerIds,_settings.sp).then(function(data){_settings.watchingPeerIds=data.watchingPeerIds;return doCommand("session","open",{sessionPeerIds:data.watchingPeerIds,s:data.s,t:data.t,n:data.n,sp:data.sp})})}function _timeout(name,reject){timers.push([name,setTimeout(function(){if(reject){reject(name+"timeout")}doClose()},1e4)])}function _keepAlive(){clearTimeout(_keepAlive.handle);_keepAlive.handle=setTimeout(function(){if(ws.readyState==1){ws.send("{}");_timeout("{}");_keepAlive()}},keepAliveTimeout)}function doClose(){ws.close();clearTimeout(_keepAlive.handle);timers.forEach(function(v,i){clearTimeout(v[1])});_waitCommands.forEach(function(v){v[2]()});timers=[];_waitCommands=[]}function doCommand(cmd,op,props){_keepAlive();var msg={cmd:cmd,peerId:_settings.peerId,appId:_settings.appId};if(op){msg.op=op}if(props){for(k in props){msg[k]=props[k]}}if(!ws){return Promise.reject()}if(ws.readyState!=1){return Promise.reject(ws.readyState)}ws.send(JSON.stringify(msg));var c=typeof op=="undefined"?cmd:cmd+op;if(cmd=="direct"&&props.transient==true||["sessionremove","sessionclose"].indexOf(c)>-1){return Promise.resolve()}else{return new Promise(function(resolve,reject){_waitCommands.push([cmdMap[c]||c,resolve,reject]);_timeout(cmdMap[c]||c,reject)})}}this.open=function(){if(ws&&ws.readyState==0){return Promise.reject(0)}if(ws&&ws.readyState==1){return Promise.resolve()}timers.forEach(function(v,i){clearTimeout(v[1])});timers=[];return _connect().then(function(){return _openSession()})};this.close=function(){doCommand("session","close");doClose();return Promise.resolve()};this.send=function(msg,to,transient){var obj={msg:msg,toPeerIds:[].concat(to)};if(typeof transient!="undefined"&&transient==true){obj.transient=transient}return doCommand("direct",undefined,obj)};this.on=function(name,func){_emitter.on(name,func)};this.watch=function(peers){return _settings.auth(_settings.peerId,[].concat(peers)).then(function(data){var watch=[].concat(data.watchingPeerIds);watch.forEach(function(v,k){if(_settings.watchingPeerIds.indexOf(v)==-1){_settings.watchingPeerIds.push(v)}});return doCommand("session","add",{sessionPeerIds:[].concat(data.watchingPeerIds),s:data.s,t:data.t,n:data.n})})};this.unwatch=function(peers){peers.forEach(function(v,k){if(_settings.watchingPeerIds.indexOf(v)>-1){_settings.watchingPeerIds.splice(_settings.watchingPeerIds.indexOf(v),1)}});return doCommand("session","remove",{sessionPeerIds:[].concat(peers)})};this.getStatus=function(peers){return doCommand("session","query",{sessionPeerIds:[].concat(peers)})};this.joinGroup=function(groupId){return _settings.groupAuth(_settings.peerId,groupId,"join",[]).then(function(data){return doCommand("room","join",{roomId:groupId,s:data.s,t:data.t,n:data.n})})};this.sendToGroup=function(msg,groupId,transient){var obj={msg:msg,roomId:groupId};if(typeof transient!="undefined"&&transient==true){obj.transient=transient}return doCommand("direct",undefined,obj)};this.inviteToGroup=function(groupId,groupPeerIds){return _settings.groupAuth(_settings.peerId,groupId,"invite",[].concat(groupPeerIds)).then(function(data){return doCommand("room","invite",{roomId:groupId,roomPeerIds:[].concat(data.groupPeerIds),s:data.s,t:data.t,n:data.n})})};this.kickFromGroup=function(groupId,groupPeerIds){return _settings.groupAuth(_settings.peerId,groupId,"kick",[].concat(groupPeerIds)).then(function(data){return doCommand("room","kick",{roomId:groupId,roomPeerIds:[].concat(groupPeerIds),s:data.s,t:data.t,n:data.n})})};this.leaveGroup=function(groupId){return doCommand("room","leave",{roomId:groupId})}}function get(url){if(typeof jQuery!=="undefined"){return Promise.resolve(jQuery.getJSON.call(jQuery,url+="&cb=?"))}else{return new Promise(function(resolve,reject){var req=new XMLHttpRequest;req.open("GET",url);req.onload=function(){if(req.status==200){resolve(JSON.parse(req.responseText))}else{reject(Error(req.statusText))}};req.onerror=function(){reject(Error("Network Error"))};req.send()})}}},{"es6-promise":2,events:12,ws:undefined,xmlhttprequest:undefined}],2:[function(require,module,exports){"use strict";var Promise=require("./promise/promise").Promise;var polyfill=require("./promise/polyfill").polyfill;exports.Promise=Promise;exports.polyfill=polyfill},{"./promise/polyfill":6,"./promise/promise":7}],3:[function(require,module,exports){"use strict";var isArray=require("./utils").isArray;var isFunction=require("./utils").isFunction;function all(promises){var Promise=this;if(!isArray(promises)){throw new TypeError("You must pass an array to all.")}return new Promise(function(resolve,reject){var results=[],remaining=promises.length,promise;if(remaining===0){resolve([])}function resolver(index){return function(value){resolveAll(index,value)}}function resolveAll(index,value){results[index]=value;if(--remaining===0){resolve(results)}}for(var i=0;i0&&this._events[type].length>m){this._events[type].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[type].length);if(typeof console.trace==="function"){console.trace()}}}return this};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.once=function(type,listener){if(!isFunction(listener))throw TypeError("listener must be a function");var fired=false;function g(){this.removeListener(type,g);if(!fired){fired=true;listener.apply(this,arguments)}}g.listener=listener;this.on(type,g);return this};EventEmitter.prototype.removeListener=function(type,listener){var list,position,length,i;if(!isFunction(listener))throw TypeError("listener must be a function");if(!this._events||!this._events[type])return this;list=this._events[type];length=list.length;position=-1;if(list===listener||isFunction(list.listener)&&list.listener===listener){delete this._events[type];if(this._events.removeListener)this.emit("removeListener",type,listener)}else if(isObject(list)){for(i=length;i-->0;){if(list[i]===listener||list[i].listener&&list[i].listener===listener){position=i;break}}if(position<0)return this;if(list.length===1){list.length=0;delete this._events[type]}else{list.splice(position,1)}if(this._events.removeListener)this.emit("removeListener",type,listener)}return this};EventEmitter.prototype.removeAllListeners=function(type){var key,listeners;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[type])delete this._events[type];return this}if(arguments.length===0){for(key in this._events){if(key==="removeListener")continue;this.removeAllListeners(key)}this.removeAllListeners("removeListener");this._events={};return this}listeners=this._events[type];if(isFunction(listeners)){this.removeListener(type,listeners)}else{while(listeners.length)this.removeListener(type,listeners[listeners.length-1])}delete this._events[type];return this};EventEmitter.prototype.listeners=function(type){var ret;if(!this._events||!this._events[type])ret=[];else if(isFunction(this._events[type]))ret=[this._events[type]];else ret=this._events[type].slice();return ret};EventEmitter.listenerCount=function(emitter,type){var ret;if(!emitter._events||!emitter._events[type])ret=0;else if(isFunction(emitter._events[type]))ret=1;else ret=emitter._events[type].length;return ret};function isFunction(arg){return typeof arg==="function"}function isNumber(arg){return typeof arg==="number"}function isObject(arg){return typeof arg==="object"&&arg!==null}function isUndefined(arg){return arg===void 0}},{}],13:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canMutationObserver=typeof window!=="undefined"&&window.MutationObserver;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}var queue=[];if(canMutationObserver){var hiddenDiv=document.createElement("div");var observer=new MutationObserver(function(){var queueList=queue.slice();queue.length=0;queueList.forEach(function(fn){fn()})});observer.observe(hiddenDiv,{attributes:true});return function nextTick(fn){if(!queue.length){hiddenDiv.setAttribute("yes","no")}queue.push(fn)}}if(canPost){window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}]},{},[1])(1)}); + +// EventEmitter.js +(function(){"use strict";function t(){}function i(t,n){for(var e=t.length;e--;)if(t[e].listener===n)return e;return-1}function n(e){return function(){return this[e].apply(this,arguments)}}var e=t.prototype,r=this,s=r.EventEmitter;e.getListeners=function(n){var r,e,t=this._getEvents();if(n instanceof RegExp){r={};for(e in t)t.hasOwnProperty(e)&&n.test(e)&&(r[e]=t[e])}else r=t[n]||(t[n]=[]);return r},e.flattenListeners=function(t){var e,n=[];for(e=0;e]+)?%>/g,i=/(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g,l="var r=[];\n",o=0;var n=function(p,q){q?(l+=p.match(i)?p+"\n":"r.push("+p+");\n"):(l+=p!=""?'r.push("'+p.replace(/"/g,'\\"')+'");\n':"");return n};while(match=k.exec(html)){n(html.slice(o,match.index))(match[1],true);o=match.index+match[0].length}n(html.substr(o,html.length-o));l+='return r.join("");';return new Function(l.replace(/[\r\t\n]/g,"")).apply(options)}function c(r,q){var k=r,q=q||70,m=(function(){var t={},s=8,u="width fontSize fontFamily lineHeight wordWrap wordBreak whiteSpace letterSpacing".split(" ");while(s--){t[u[s]]=k.css(u[s])}return $.extend(t,{position:"absolute",left:-9999,top:0})})(),i=k.clone().css(m).attr({id:"",name:"",tabIndex:-1}),n,l,j=k.height(),o=$([k[0],i[0]]),p=function(){l=k.val();i.val(l).height(1).scrollTop(9999);n=Math.min(Math.max(j,i.scrollTop()),q);o.height(n)};k.after(i).bind("focus input change propertychange",p)}function f(i){if(!d.debug){return}$(".log").append("

"+this.tranTime(new Date())+":"+i+"

")}return{isDifferentDay:e,tranTime:b,template:g,freeTextarea:c,log:f}}(window,document,Green);Green._StatusView=function(c,a,b,e){var d={};d.commit=function(){var f='
';this.dom=$(f);return this.dom};d.msg=function(f){this.dom.html(f).show()};d.hide=function(){this.dom.hide()};return d}(window,document,Green,EventEmitter);Green._RosterView=function(f,b,c,g,d){function a(h){this.roster=h}a.prototype.commit=function e(){var h='
'+''+''+''+'
'+''+"
"+'
'+'
'+'
'+this.roster.name+"
"+"
"+"
"+"
";this.dom=$(h);this.dom.click($.proxy(function(){d.trigger("rosterClick",[this])},this));return this.dom};a.prototype.updateUnread=function(h){var i=this.dom.find(".unread-dot");this.roster.unreadCount=h;if(h==0){i.hide()}else{i.html(h).show()}};a.prototype.updateOnlineStatus=function(h){this.roster.onlineStatus=h;this.dom.find(".chat-status").removeClass().addClass("chat-status "+h)};return a}(window,document,Green,Green._Utils,Green._EventHandler);Green._RosterListView=function(f,b,d,g,e,a){var c={};c.commit=function(i){var h='
'+'
 聊天联系人
'+'
'+'
在线
 
 收缩
'+"
";this.dom=$(h);this.rosterViews={};$.each(i,function(l,k){var j=new a(k);c.rosterViews[l]=j;c.dom.find(".active").append(j.commit())});this.dom.find(".title, .toggle-btn").click(function(){e.trigger("rosterListViewToggle",[!c.dom.hasClass("contacts-minus")])});return this.dom};c.init=function(){var m=40;var k=30;var l=62;var h=$(f).height()-l;var j=$(f).height()-l-m-k;var i=c.dom.find(".nano");i.css("height",j+"px");i.nanoScroller();this.height=h;this.innerHeight=j};c.get=function(h){return this.rosterViews[h]};c.toggle=function(h){if(h){this.dom.addClass("contacts-minus")}else{this.dom.removeClass("contacts-minus")}};c.prepend=function(h){this.get(h).dom.prependTo(this.dom.find(".active"))};c.hide=function(){this.dom.hide()};c.show=function(){this.dom.show()};return c}(window,document,Green,Green._Utils,Green._EventHandler,Green._RosterView);Green._ConverseView=function(e,b,c,g,d){function a(h){this.roster=h}a.prototype.commit=function(){var h='
'+'
'+'
无更多历史消息
'+'
更多历史消息
历史消息加载中...
'+"
"+"
";this.dom=$(h);f.call(this);return this.dom};function f(){var i=this.dom.find(".loadmore");i.click($.proxy(function(){if(i.hasClass("loadmore-loading")){return false}i.addClass("loadmore-loading");var j={convid:[c.me.id,this.roster.id],timestamp:this.lastMessage.timestamp,limit:30};d.trigger("getHistory",[j,this])},this));this.lastMessage={};var h=this.roster.unreadMessages;if(h.length==0){this.lastMessage["timestamp"]=new Date().getTime();i.trigger("click")}else{this.lastMessage=h[0];this.renderMessage(h,"receive");this.roster.unreadMessages=[]}}a.prototype.renderMessage=function(l,n){if(!(l instanceof Array)){l=[l]}var q="";var k;var r;var h;for(var m=0,o=l.length;m发送失败
'}q+='
'+'
'+r.name+":"+r.date+"
"+'
'+''+r.name+''+'
'+'
'+'
'+'
'+'
'+r.message+"
"+"
"+"
"+'
'+"
"+"
"+h+"
"+"
"}var j=$(q);if(n=="history"){var p=this.getPosition();this.dom.find(".loadmore").after(j);this.scroll();this.adjustPosition(p)}if(n=="receive"||n=="send"){this.dom.find(".messages").append(j);this.scroll();this.scrollDown()}if(n=="notCurrent"){this.dom.find(".messages").append(j);this.scroll()}return j};a.prototype.showLoadmore=function(){this.dom.find(".loadmore").removeClass("loadmore-loading").show().find("b").html("更多历史消息")};a.prototype.showHistoryFailed=function(){this.dom.find(".loadmore").removeClass("loadmore-loading").show().find("b").html("加载历史信息失败 点击重试")};a.prototype.showNoHistory=function(){this.dom.find(".loadmore").hide();this.dom.find(".no-more-history").show()};a.prototype.scrollDown=function(){var h=this.dom.find(".messages");h.stop().animate({scrollTop:h[0].scrollHeight})};a.prototype.adjustPosition=function(h){this.dom.nanoScroller({scrollTop:this.getPosition()-h})};a.prototype.getPosition=function(){return this.dom.find(".messages")[0].scrollHeight};a.prototype.scroll=function(){this.dom.nanoScroller({preventPageScrolling:true,alwaysVisible:true})};a.prototype.destroy=function(){this.dom.nanoScroller({destroy:true});this.dom.remove();delete this};return a}(window,document,Green,Green._Utils,Green._EventHandler);Green._ConverseListView=function(e,b,c,f,d,a){var g={};g.commit=function(){var h='
';this.dom=$(h);this.converseListViews={};return this.dom};g.add=function(j){var i=this.get(j.id);if(i){return i}var h=new a(j);this.converseListViews[j.id]=h;this.dom.append(h.commit());this.currentView=h;return h};g.get=function(h){return this.converseListViews[h]};g.front=function(h){this.get(h).dom.css("zIndex",100).siblings().css("zIndex",99)};g.show=function(){this.dom.show()};g.hide=function(){this.dom.hide()};g.remove=function(h){this.get(h).destroy();delete this.converseListViews[h]};g.removeAll=function(){$.each(this.converseListViews,function(i,h){h.destroy()});this.converseListViews={};this.currentView=null};return g}(window,document,Green,Green._Utils,Green._EventHandler,Green._ConverseView);Green._ChatWithView=function(e,a,b,g,c){function h(i){this.roster=i}h.prototype.commit=function d(){var i='
'+'
'+'
'+this.roster.name+"
"+''+''+"
";this.dom=$(i);f.call(this);return this.dom};function f(){this.dom.click($.proxy(function(){c.trigger("chatWithClick",[this])},this));this.dom.find(".icon-remove").click($.proxy(function(){c.trigger("chatWithRemove",[this])},this))}h.prototype.updateUnread=function(i){var j=this.dom.find(".msg-unread");this.roster.unreadCount=i;if(i==0){j.hide()}else{j.show()}};h.prototype.updateOnlineStatus=function(i){this.roster.onlineStatus=i;this.dom.find(".chat-status").removeClass().addClass("chat-status "+i)};h.prototype.active=function(){this.dom.addClass("active").siblings().removeClass("active")};h.prototype.destroy=function(){this.dom.remove();delete this};return h}(window,document,Green,Green._Utils,Green._EventHandler);Green._ChatWithListView=function(e,a,b,f,g,c){var d={};d.commit=function(){var h='
'+'
洽谈列表
'+'
'+"
";this.dom=$(h);this.chatWithViews=[];return this.dom};d.add=function(i){var h=this.get(i.id);if(h){return h}var j=new g(i);this.chatWithViews.push(j);this.dom.find(".nano-content").append(j.commit());this.dom.find(".nano").nanoScroller();return j};d.get=function(l){var j=this.chatWithViews;for(var k=0,h=j.length;k
  
'+'
'+"";this.dom=$(k);this.dom.prepend(i.commit());this.dom.find(".chatbox").append(h.commit());this.dom.find(".chatbox").append(c.commit());f.call(this);return this.dom};function f(){this.dom.find(".icon-minus").click(function(){a.minifiy();return false});this.dom.find(".minus-pannel").click(function(){j.trigger("chatboxMaxfiy");return false});this.dom.find(".icon-remove").click(function(){a.remove();return false})}a.get=function(k){return this.rosterViews[k]};a.toggle=function(k){if(k){this.dom.addClass("chatbox-wrap-contacts-minus")}else{this.dom.removeClass("chatbox-wrap-contacts-minus")}};a.isMinus=function(){return this.dom.hasClass("chatbox-minus")};a.maxfiy=function(){this.dom.removeClass("chatbox-minus");if(this.dom.hasClass("chat-new-message")){this.dom.removeClass("chat-new-message")}};a.minifiy=function(){return this.dom.addClass("chatbox-minus")};a.beMulti=function(){this.dom.addClass("multi-chatbox")};a.cleanMulti=function(){this.dom.removeClass("multi-chatbox")};a.hide=function(){return this.dom.hide()};a.show=function(){return this.dom.show()};a.remove=function(){i.removeAll();h.removeAll();this.hide()};return a}(window,document,Green,Green._Utils,Green._EventHandler,Green._ChatWithListView,Green._ConverseListView,Green._InputView);Green._Server=function(f,j,a,e,l){var d={};var b=0;var i=0;var o="0s66p2ntvx0q56pk5mh8wxa7cuegr57w5abvb7nwv5dqymyo";var n;d.isOpen=false;d.init=function(){n=new AVChatClient({appId:o,peerId:a.me.id,auth:p,watchingPeerIds:a.watch});n.on("close",function(q){h(q)});n.on("message",function(q){m(q)});n.on("online",function(q){c(q)});n.on("offline",function(q){g(q)});k()};function k(){if(!d.isOpen&&b==0){l.trigger("onConnectStart")}n.open().then(function(){d.isOpen=true;b=0;l.trigger("onConnectSuccess")},function(q){l.trigger("onConnectError")})}function m(r){var q={"from":r.fromPeerId,"to":r.peerId,"data":r.msg,"timestamp":r.timestamp};if(r.toPeerIds){q.to=r.toPeerIds[0]}l.trigger("messageReceived",[q])}function h(q){d.isOpen=false;if(b'+a.me.name+"");a.watch=[];var v={};for(var s=0,r=t.rosters.length;s1){b.beMulti()}j.add(p.roster);n.trigger("chatWithClick",[q])});n.on("chatWithClick",function(q){var p=q.roster;a.get(p.id).updateUnread(0);q.updateUnread(0);q.active();j.front(p.id);j.currentView=j.get(p.id);j.currentView.scroll();if(b.isMinus){b.maxfiy()}b.dom.find(".chat-with img").attr("src",p.image);b.dom.find(".chat-with .chat-name").html(p.name);b.dom.find(".cur-chat-name").html(p.name)});n.on("chatWithRemove",function(p){k.remove(p);j.remove(p.roster.id);if(k.chatWithViews.length==1){b.cleanMulti()}});n.on("chatboxMaxfiy",function(){var p=j.currentView.roster.id;a.get(p).updateUnread(0);b.maxfiy()});n.on("sendMessageEnter",function(s){if(!e.isOpen){alert("连接已断开,刷新重试")}d.reset();var p=j.currentView;var r={from:c.me.id,to:p.roster.id,data:s,timestamp:new Date().getTime()};var q=p.renderMessage(r,"send");e.sendMessage(r,q)});n.on("sendMessageSuccess",function(q,p){p.addClass("send-success")});n.on("sendMessageFailed",function(q,p){p.addClass("send-failed")});n.on("getHistory",function(q,p){e.getHistory(q,p)});n.on("getHistorySuccess",function(r,p,q){if(q===false){p.showHistoryFailed();return false}if(!q||q.length==0){p.showNoHistory();return false}q.reverse();p.lastMessage=q[0];p.renderMessage(q,"history");if(q.length<30){p.showNoHistory()}else{p.showLoadmore()}});n.on("getHistoryFailed",function(q,p){p.showHistoryFailed()});n.on("messageReceived",function(t){if(t.from==c.me.id){if(j.get(t.to)){var u=k.get(t.to);n.trigger("chatWithClick",[u]);j.get(t.to).renderMessage(t,"receive");k.prepend(t.to)}else{var s=a.get(t.to);s.roster.unreadMessages.push(t);n.trigger("rosterClick",[s])}a.prepend(t.to);return false}var s=a.get(t.from);if(!s){return false}var q=s.roster.unreadCount;q++;a.prepend(t.from);if(j.get(t.from)){var u=k.get(t.from);var p=j.get(t.from);var r=j.currentView.roster.id==t.from;k.prepend(t.from);if(b.isMinus()){b.dom.addClass("chat-new-message");u.updateUnread(q);s.updateUnread(q);p.renderMessage(t,"notCurrent")}else{if(!r){u.updateUnread(q);s.updateUnread(q);p.renderMessage(t,"notCurrent")}else{p.renderMessage(t,"receive")}}}else{s.updateUnread(q);s.roster.unreadMessages.push(t)}});return o}(window,document,Green,Green._Utils,Green._EventHandler,Green._ChatboxView,Green._RosterListView,Green._ChatWithListView,Green._ConverseListView,Green._InputView,Green._StatusView,Green._Server); \ No newline at end of file diff --git a/signature.php b/signature.php index 8b635f8..b972e4a 100644 --- a/signature.php +++ b/signature.php @@ -9,7 +9,7 @@ $watchs = explode(":", $watchIds); sort($watchs, SORT_STRING); - $watchIds = $watchs;//explode(':', '2:20:25:28:4:5:7:8'); + $watchIds = $watchs; $ts = time(); $nonce = randomString();