Code Monkey home page Code Monkey logo

js-realtime-sdk's Issues

Invite or Join?

Hi, 我想请问一下目前roomObj.join的语义,究竟是invite还是join

以我目前的实验来看,sign请求发出时action写的是invite,请求中members有且只有一个id,就是用户自己。

单纯从这个roomObj.join的角度来说,这应该是一个join语义,但发出的却是invite请求。

这个奇怪的现象将直接影响后端sign的内部实现。

我认为这很可能是一个BUG。

rt 的 "message" 事件的疑问?

文档中提到 “...收到的消息是当前客户端(clientId)存在的 Room 中的信息....” 这是不是意味着当初始化完成后,我必须为我所有的好友都建立room,不然,我是不是不能提收到他发来信息。

Review

记录 review 中一些问题

  • 命名空间
  • 创建 conv 是 id 是空字符串而非 null 的考虑是?
  • log 里的 setTimeout 可以去掉
  • 194行是否可能有数组越界
  • update callback 没有使用
  • 处理router返回404和403 的情况
  • startConv /remove 等函数的签名参数被注释掉了
  • tool.getId 返回一个自增整数即可,不要用字符串,未来可能会改成强类型

还没看完,明天可能会继续添加一些

进入同一Room后的两个Peer,互相接收不到消息

            var onLogin = function (session) {

                rtObject = lc.realtime({
                    appId: '我的appId',
                    clientId: session.userId
                }, function () {
                    console.log('open');
                    rtObject.on('message', function (data) {
                        console.log(data);
                    });
                });

                rtObject.on('close', function () {
                    console.log('close');
                    console.log('reconnecting...');
                    rtObject.open();
                });
            };
            var enterRoom = function (roomId, receive) {

                    console.log('Entering room ' + roomId);

                    var r = rtObject.room(roomId);
                    r.receive(receive);

                    return {
                        send: function(msg) {
                            var deferred = $q.defer();
                            r.send(msg, function() {
                                deferred.resolve();
                            });
                            return deferred.promise;
                        }
                    };
                }

当调用send时,可以正常发出消息,inspect websocket frames也可以看到'ack',但是同一room内的其他peer却无法收到任何消息。上周末时还能正常收到消息,大约从前两天开始就不行了。请问这是什么原因?还是现在sdk不能正常工作?

README.md

var rtObject = lc.realtime({
   // appId 需要换成你自己的 appId
   appId: '9p6hyhh60av3ukkni3i9z53q1l8yy3cijj6sie3cewft18vm',
   // clientId 是自定义的名字,当前客户端可以理解的名字
   clientId: 'abc123'
   // auth 是权限校验的服务器地址,具体请看文档
   // auth: 'http://signature-example.avosapps.com/sign'
});
var room = rt.room('sasfalklkjdlfs123');

rt 是什么?

room 的一些疑惑?

当前用户想和另一人对话时需要创建一个room,把自己和那个人一起加入, 聊了些内容后,过一段时间后,用户再次点开这个好友时,为了获取原来聊的内容,就必须要知道之间的room id,不然,又是新建room 了,那不是我还要想办法记录这个roomid?

调用RealtimeObject.close()导致ReferenceError

stack如下:

ReferenceError: options is not defined
    at Object.engine.closeSession (http://localhost:8888/assets/bower_components/leancloud-realtime/src/lc.realtime.js:485:20)
    at Object.newRealtimeObject.close (http://localhost:8888/assets/bower_components/leancloud-realtime/src/lc.realtime.js:944:24)
    at Object.$get.onLogin (http://localhost:8888/scripts/services/chatService.js:150:42)
    at http://localhost:8888/scripts/controllers/app/front/login.js:14:40
    at processQueue (http://localhost:8888/assets/bower_components/angular/angular.js:13248:27)
    at http://localhost:8888/assets/bower_components/angular/angular.js:13264:27
    at Scope.$get.Scope.$eval (http://localhost:8888/assets/bower_components/angular/angular.js:14466:28)
    at Scope.$get.Scope.$digest (http://localhost:8888/assets/bower_components/angular/angular.js:14282:31)
    at Scope.$get.Scope.$apply (http://localhost:8888/assets/bower_components/angular/angular.js:14571:24)
    at done (http://localhost:8888/assets/bower_components/angular/angular.js:9698:47)

RealtimeObject.close()之后好像heartbeat依然在运行

close之后过一段时间会重复出现以下错误:

WebSocket is already in CLOSING or CLOSED state.      
wsSend                               AV.realtime.js:348
(anonymous function)                 AV.realtime.js:368 

感觉像是因为heartbeat还持续在运行。

另外目前有哪个函数可以获取RealtimeObject当前的状态吗(open,closed等)?

考虑 SDK 是否需要默认防止 XSS

@killme2008 @sunng87 @jwfing
实时聊天 SDK 使用过程中发现很多用户试了 XSS,如果是一般的小白用户可能就会忽略这个问题。
所以,是否 SDK 层面直接把 XSS 过滤默认做了?
如果用户有不做的需求,那我们有个配置,可以不做 XSS 转义,但是默认 SDK 层面是做 XSS 防御的。

应当始终抛出 Error 实例,而非字符串

SDK 对用户抛出的异常应当尽可能清晰地传达出发生的错误信息,现在有两点问题。

抛出的是字符串

抛出具体的 Error 实例会显示具体的 Error 类型,并附上调用堆栈,可以帮助用户更快地理解到底发什么了什么。两者区别如下图:

{
    ping: function() {
        // ...
        throw('Must call after open() has successed.');
    },
    room: function() {
        // ...
        throw new Error('Must call after open() has successed.');
    }
}

参考浏览器内建的几个 Error 类:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types

Error 信息太随意

Error 信息应该包含「发什么了什么错误」,可以给出「可能的原因及解决方案」。比如上面的 case 的错误文案可以更具体:「RealtimeObject.ping() called before the RealtimeObject.open() succeeded. RealtimeObject.ping() should be called in the callback of AV.realtime() or in a handler of 'open' event of RealtimeObject, see https://github.com/leancloud/js-realtime-sdk/blob/master/demo/demo1/test.js .」,这样可能对用户更有价值。

有时一条消息会被收到多次

经测试,当某些情况发生(如网络状况不良等,无法100%复现)时,会发生同时有多个websocket链接in progress的情况。这个时候,当其它peer发来一条消息,本地的message事件会被调用多次。感觉像是connection被错误的判断为close,所以重新链接了?

send message 回调中的data 不应该是ack 命令

现在的是 ack:

image

    room.send({
        text: val
    }, {
        type: 'text'
    }, function (data) {

        // 发送成功之后的回调
        inputSend.value = '';
        showMsg(data);
        printWall.scrollTop = printWall.scrollHeight;
    });

上面 data 回调是 message 较好,这样可以统一处理,android 和 iOS 都是回调的 message。

@wangxiao

增加内部 RoomObject 缓存

每次创建实例化一个 RoomObject 就存储在 cache 中,
用户如果获取相同的 RoomObject 直接返回 cache 中的,防止重复创建。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.