Git Product home page Git Product logo

yunba-javascript-sdk's Introduction

Build Status Coverage Status

Yunba JavaScript SDK over Socket.IO

文档 http://yunba.io/docs2/Javascript_SDK/

依赖

socket.io-1.3.5.min.js

说明

推荐使用 connect_by_customid() :

为了保存 离线消息、已订阅的频道和别名 等信息,我们推荐使用 connect_by_customid() 进行连接,connect_by_customid() 使用特定的会话 ID 进行连接,连接后的会话状态会与上次连接保持一致。

connect_by_customid 官网文档链接

使用 connect() 连接:

在浏览器支持并开启 cookie 的情况下,会自动生成一个 uid 作为 customid 并保存到 cookie 中然后进行 connect_by_customid 连接,若不支持或没开启 cookie 则只会进行普通的 connect 连接。

普通 connect() 连接兼容旧版本接口,并无法保存会话状态。

connect 官网文档链接

connect() 中的 uid 构成方法:

uid_ + 当前时间的时间戳 + 10000以内随机数

publish 相关操作时 messageId 构成方法:

publish、publish2、publish_to_alias、publish2_to_alias 操作时若不指定 messageId 时则会自动生成 messageId。

messageId 是一个64位数字转化成的字符串

高41位当前时间的时间戳 + 低23位随机数

浏览器支持

IE Safari Chrome Opera Firefox
7+

IE 7以下版本支持

IE7 以下版本会报错对象不支持 "stringify" 属性或方法,在导入 socket.io.js 前导入 json2.js 即可解决。

https://github.com/douglascrockford/JSON-js

<!--[if lte IE 7]>
<script  type='text/javascript' src='/javascripts/json2.js'></script>
<![endif]-->

试用例子

examples/yunba_javascript_demo_customid.html 演示了如何使用 Yunba JavaScript SDK。试用前先确保 Appkey 正确:

	var yunba = new Yunba({appkey:'52fcc04c4dc903d66d6f8f92'});

** 替换为您的 Appkey **

然后用浏览器打开即可。

Test

npm install
npm run test

yunba-javascript-sdk's People

Contributors

covertness avatar tigerzhang avatar william17 avatar wuwenxian avatar

Watchers

 avatar  avatar  avatar

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.