Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
shuidiapp
shuidiapp
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • 互联网应用开发
  • shuidiappshuidiapp
  • Wiki
  • im

Last edited by 王秋石 Nov 24, 2016
Page history

im

引入socket.io

   public static function get_static_js_list() {
		return array_merge(
			parent::get_static_js_list(), array(
			'js/socket.io-1.4.5.js',
		));
	}

获取uid , uid_sinature

var uid = RSF.getCookie('uid');
var uid_sinature = RSF.getCookie('uid_sinature');

连接服务器

        var socket = io('http://192.168.109.245:8181',{
            'transports':['websocket']
        });

登录服务器

        socket.on('connect', function(){
            
            socket.emit('login',{
                'uid':RSF.getCookie('uid'),
                'signature':RSF.getCookie('uid_sinature')
            })
        }.bind(this)); 

        socket.on('login-success',function(data) {
            console.log('登录成功!');
        });

发送消息

           
       socket.emit('send-private-message',{'to':uid,'message':'你给我滚'})
 

收到消息


        socket.on('recv-private-message',function(data) {
            console.log('我收到了别人给我的私信:');
            console.log(data.message);
        });

使用shuidiIm类

        var shuidiIm = new ShuidiIm();
        shuidiIm.onMessage = function(message){
            console.log(message);
        };
        shuidiIm.ready = function(data){
            console.log('聊天服务准备完毕');

            setInterval(function(){
                var msg = new ShuidiIm.Message();
                msg.fid = shuidiIm.uid;
                msg.toid = shuidiIm.uid;
                msg.message = '测试消息'+new Date().getTime();
                shuidiIm.sendMessage(msg);
            },1000);
        };

        shuidiIm.init();
Clone repository
  • add_application
  • agree_application
  • api_desc
  • api_list
  • autobiography
  • base_info
  • branch
  • cancel_follow
  • change
  • change_applicant_name
  • change_avatar
  • change_logo
  • change_nickname
  • change_password
  • change_position
View All Pages