leancloud-realtime
Advanced tools
Comparing version 3.0.2 to 3.1.0
{ | ||
"opts": { | ||
"template": "node_modules/docdash" | ||
"template": "node_modules/docdash", | ||
"recurse": true | ||
}, | ||
"source": { | ||
"exclude": ["plugins/webrtc/src/signalings"] | ||
}, | ||
"plugins": ["node_modules/jsdoc-ignore-future"], | ||
@@ -6,0 +10,0 @@ "ignoreFuture": { |
{ | ||
"name": "leancloud-realtime", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"homepage": "https://github.com/leancloud/js-realtime-sdk/", | ||
@@ -11,2 +11,3 @@ "description": "LeanCloud JavaScript Realtime SDK", | ||
"demo", | ||
"docs", | ||
"test", | ||
@@ -13,0 +14,0 @@ "Gruntfile.js" |
@@ -0,1 +1,37 @@ | ||
<a name="3.1.0"></a> | ||
# 3.1.0 (2016-07-18) | ||
同时发布 | ||
- leancloud-realtime-plugin-typed-messages 1.0.0 | ||
- leancloud-realtime-plugin-webrtc 1.0.0-beta.1 | ||
### Features | ||
* **Plugin:** 支持通过插件来对功能进行扩展,详细说明请参考 [《JavaScript 实时通信开发指南 - 插件》](https://leancloud.cn/docs/realtime_guide-js.html#插件)。 | ||
* **Plugin/TypedMessage:** leancloud-realtime-typed-messages 包改名为 leancloud-realtime-plugin-typed-messages,新增 export `TypedMessagesPlugin`: | ||
```javascript | ||
const { Realtime } = require('leancloud-realtime'); | ||
// before (use package leancloud-realtime-typed-messages) | ||
const { AudioMessage, FileMessage, ImageMessage, LocationMessage, VideoMessage } = require('leancloud-realtime-typed-messages'); | ||
const realtime = new Realtime({ | ||
appId: 'APP_ID', | ||
}); | ||
realtime.register([AudioMessage, FileMessage, ImageMessage, LocationMessage, VideoMessage]); | ||
// after (use package leancloud-realtime-plugin-typed-messages) | ||
const { TypedMessagesPlugin } = require('leancloud-realtime-plugin-typed-messages'); | ||
const realtime = new Realtime({ | ||
appId: 'APP_ID', | ||
plugins: [TypedMessagesPlugin], | ||
}); | ||
``` | ||
详细的安装与初始化说明请参考 [《JavaScript 实时通信开发指南 - 富媒体消息插件》](https://leancloud.cn/docs/realtime_guide-js.html#富媒体消息插件)。 | ||
* **Plugin/WebRTC:** 发布了 WebRTC 插件的 beta 版本。该插件能帮助你实现 Web 端点对点实时音视频通话功能。详细的文档请参考 [《JavaScript 实时通讯 WebRTC 插件使用指南》](https://leancloud.cn/docs/webrtc-js.html)。 | ||
<a name="3.0.2"></a> | ||
@@ -2,0 +38,0 @@ ## 3.0.2 (2016-06-30) |
@@ -129,6 +129,7 @@ /* eslint-disable */ | ||
'typed-messages': { | ||
dest: 'typed-messages/dist/typed-messages.js', | ||
src: 'typed-messages/src/index.js', | ||
dest: 'plugins/typed-messages/dist/typed-messages.js', | ||
src: 'plugins/typed-messages/src/index.js', | ||
options: { | ||
plugins: [ | ||
json(), | ||
babel(Object.assign({}, babelConfigs, { | ||
@@ -153,3 +154,28 @@ exclude: 'node_modules/**', | ||
} | ||
} | ||
}, | ||
'webrtc': { | ||
dest: 'plugins/webrtc/dist/webrtc.js', | ||
src: 'plugins/webrtc/src/index.js', | ||
options: { | ||
plugins: [ | ||
json(), | ||
babel(Object.assign({}, babelConfigs, { | ||
exclude: 'node_modules/**', | ||
})), | ||
nodeResolve({ | ||
main: true, | ||
}), | ||
commonjs({ | ||
include: ['node_modules/**'], | ||
}), | ||
], | ||
format: 'umd', | ||
moduleName: 'AV', | ||
moduleId: 'webrtc', | ||
external: ['leancloud-realtime'], | ||
globals: { | ||
'leancloud-realtime': 'AV', | ||
}, | ||
} | ||
}, | ||
}, | ||
@@ -176,8 +202,17 @@ envify: { | ||
sourceMap: true, | ||
sourceMapIn: 'typed-messages/dist/typed-messages.js.map' | ||
sourceMapIn: 'plugins/typed-messages/dist/typed-messages.js.map' | ||
}, | ||
files: { | ||
'typed-messages/dist/typed-messages.min.js': ['typed-messages/dist/typed-messages.js'] | ||
'plugins/typed-messages/dist/typed-messages.min.js': ['plugins/typed-messages/dist/typed-messages.js'] | ||
} | ||
} | ||
}, | ||
webrtc: { | ||
options: { | ||
sourceMap: true, | ||
sourceMapIn: 'plugins/webrtc/dist/webrtc.js.map' | ||
}, | ||
files: { | ||
'plugins/webrtc/dist/webrtc.min.js': ['plugins/webrtc/dist/webrtc.js'] | ||
} | ||
}, | ||
}, | ||
@@ -219,3 +254,12 @@ connect: { | ||
}); | ||
grunt.registerTask('build', ['rollup:dist-browser', 'rollup:dist', 'uglify:browser', 'rollup:typed-messages', 'uglify:typed-messages', 'validate-es5']); | ||
grunt.registerTask('build', [ | ||
'rollup:dist-browser', | ||
'rollup:dist', | ||
'uglify:browser', | ||
'rollup:typed-messages', | ||
'uglify:typed-messages', | ||
'rollup:webrtc', | ||
'uglify:webrtc', | ||
'validate-es5' | ||
]); | ||
grunt.registerTask('cdn', 'Upload dist to CDN.', function() { | ||
@@ -259,3 +303,4 @@ | ||
[ | ||
'./typed-messages/dist/typed-messages.js', | ||
'./plugins/typed-messages/dist/typed-messages.js', | ||
'./plugins/webrtc/dist/webrtc.js', | ||
'./dist/realtime.browser.js' | ||
@@ -262,0 +307,0 @@ ].forEach(file => { |
{ | ||
"name": "leancloud-realtime", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "LeanCloud Realtime Message JavaScript SDK", | ||
@@ -11,7 +11,7 @@ "main": "dist/realtime.js", | ||
"scripts": { | ||
"lint": "eslint --ignore-path .gitignore src test typed-messages", | ||
"lint": "eslint --ignore-path .gitignore src test plugins", | ||
"test": "npm run lint && npm run build && npm run doc && npm run test:node && npm run test:browser", | ||
"test:node": "babel-node ./node_modules/isparta/bin/isparta cover --include 'src/**' --include 'typed-messages/src/**' --report text ./node_modules/mocha/bin/_mocha -- test/index.js typed-messages/test/index.js --timeout 30000", | ||
"test:node": "babel-node ./node_modules/isparta/bin/isparta cover --include 'src/**' --include 'plugins/typed-messages/src/**' --report text ./node_modules/mocha/bin/_mocha -- test/index.js plugins/typed-messages/test/index.js --timeout 30000", | ||
"test:browser": "grunt test-browser --stack", | ||
"doc": "jsdoc src typed-messages/src README.md -r -d docs -c .jsdocrc.json", | ||
"doc": "jsdoc src README.md -d docs -c .jsdocrc.json && jsdoc plugins/typed-messages/src -d plugins/typed-messages/docs src/messages/**message.js -c .jsdocrc.json && jsdoc plugins/webrtc/src -d plugins/webrtc/docs -c .jsdocrc.json ", | ||
"build": "grunt build --stack", | ||
@@ -45,3 +45,3 @@ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"docdash": "^0.4.0", | ||
"eslint": "^2.10.0", | ||
"eslint": "^3.0.0", | ||
"eslint-config-airbnb-base": "^3.0.1", | ||
@@ -56,3 +56,3 @@ "eslint-plugin-import": "^1.5.0", | ||
"grunt-rollup": "^0.7.0", | ||
"grunt-saucelabs": "^8.6.1", | ||
"grunt-saucelabs": "^9.0.0", | ||
"inherit": "^2.2.3", | ||
@@ -66,3 +66,3 @@ "isparta": "^4.0.0", | ||
"qiniu": "^6.1.9", | ||
"rollup": "^0.33.0", | ||
"rollup": "^0.34.0", | ||
"rollup-plugin-babel": "^2.4.0", | ||
@@ -78,3 +78,3 @@ "rollup-plugin-commonjs": "^3.0.0", | ||
"dependencies": { | ||
"axios": "^0.12.0", | ||
"axios": "^0.13.0", | ||
"babel-runtime": "^6.6.1", | ||
@@ -87,3 +87,3 @@ "debug": "^2.2.0", | ||
"uuid": "^2.0.1", | ||
"ws": "^1.1.0" | ||
"ws": "^1.1.1" | ||
}, | ||
@@ -90,0 +90,0 @@ "browser": { |
@@ -46,4 +46,12 @@ LeanCloud JavaScript Realtime SDK | ||
- [使用文档](https://leancloud.cn/docs/realtime_guide-js.html) | ||
- [API 文档](https://leancloud.github.io/js-realtime-sdk/docs/) | ||
- API 文档 | ||
- [leancloud-realtime](https://leancloud.github.io/js-realtime-sdk/docs/) | ||
- [leancloud-realtime-plugin-typed-messages](https://leancloud.github.io/js-realtime-sdk/plugins/typed-messages/docs/) | ||
- [leancloud-realtime-plugin-webrtc](https://leancloud.github.io/js-realtime-sdk/plugins/webrtc/docs/) | ||
Demo | ||
---- | ||
- [Simple Chatroom](https://leancloud.github.io/js-realtime-sdk/demo/simple-chatroom/) ([src](https://github.com/leancloud/js-realtime-sdk/tree/master/demo/simple-chatroom)) | ||
- [WebRTC 视频通话](https://leancloud.github.io/js-realtime-sdk/demo/video-calling/) ([src](https://github.com/leancloud/js-realtime-sdk/tree/master/demo/video-calling)) | ||
支持 | ||
@@ -73,4 +81,5 @@ ---- | ||
├── demo | ||
├── deploy.sh // 部署 gh-pages 分支 | ||
├── dist // 打包产出 | ||
├── deploy.sh // 部署 gh-pages 分支 | ||
├── release.sh // 部署 dist 分支 | ||
├── dist // 打包产出 | ||
│ ├── realtime.browser.js // 浏览器用 | ||
@@ -83,3 +92,2 @@ │ ├── realtime.browser.min.js // 浏览器用(uglified) | ||
│ └── message.proto // proto 原始文件 | ||
├── release.sh // 部署 dist 分支 | ||
├── src // 源码 | ||
@@ -90,3 +98,5 @@ │ └── index.js // 打包入口 | ||
│ └── index.js // 测试入口 | ||
└── typed-messages // leancloud-realtime-typed-messages package | ||
└── plugins | ||
├── typed-messages // leancloud-realtime-plugin-typed-messages package | ||
└── webrtc // leancloud-realtime-plugin-webrtc package | ||
``` | ||
@@ -168,3 +178,2 @@ | ||
0. npm publish(`npm publish`,需 npm 协作者身份),如果是 pre-release 版本需要带 next tag | ||
0. `grunt upload` 上传到 CDN | ||
0. 发布 leancloud-realtime-typed-messages(`cd typed-messages && npm publish`) | ||
0. 如有更新,在 npm 上发布各个 plugin |
import EventEmitter from 'eventemitter3'; | ||
import { decodeDate, keyRemap, union, difference } from './utils'; | ||
import { applyDecorators } from './plugin'; | ||
import IMClient from './im-client'; | ||
@@ -107,2 +108,4 @@ import { | ||
)); | ||
// onConversationCreate hook | ||
applyDecorators(this._client._plugins.onConversationCreate, this); | ||
} | ||
@@ -515,13 +518,14 @@ | ||
})).then(resCommand => | ||
resCommand.logsMessage.logs.map(log => { | ||
const messageProps = { | ||
id: log.msgId, | ||
cid: this.id, | ||
timestamp: new Date(log.timestamp.toNumber()), | ||
from: log.from, | ||
}; | ||
const message = this._client._messageParser.parse(log.data); | ||
Object.assign(message, messageProps); | ||
return message; | ||
}) | ||
Promise.all(resCommand.logsMessage.logs.map(log => | ||
this._client._messageParser.parse(log.data).then(message => { | ||
const messageProps = { | ||
id: log.msgId, | ||
cid: this.id, | ||
timestamp: new Date(log.timestamp.toNumber()), | ||
from: log.from, | ||
}; | ||
Object.assign(message, messageProps); | ||
return message; | ||
}) | ||
)) | ||
); | ||
@@ -528,0 +532,0 @@ } |
@@ -18,2 +18,3 @@ import Client from './client'; | ||
import { tap, Cache, keyRemap, union, difference, trim } from './utils'; | ||
import { applyDecorators } from './plugin'; | ||
import { run as runSignatureFactory } from './signature-factory-runner'; | ||
@@ -59,2 +60,4 @@ import { default as d } from 'debug'; | ||
)); | ||
// onIMClientCreate hook | ||
applyDecorators(this._plugins.onIMClientCreate, this); | ||
} | ||
@@ -281,3 +284,6 @@ | ||
} = originalMessage; | ||
return this.getConversation(directMessage.cid).then(conversation => { | ||
return Promise.all([ | ||
this.getConversation(directMessage.cid), | ||
this._messageParser.parse(directMessage.msg), | ||
]).then(([conversation, message]) => { | ||
const messageProps = { | ||
@@ -290,3 +296,2 @@ id, | ||
}; | ||
const message = this._messageParser.parse(directMessage.msg); | ||
Object.assign(message, messageProps); | ||
@@ -494,3 +499,5 @@ conversation.lastMessage = message; // eslint-disable-line no-param-reassign | ||
}) | ||
.then(conversations => conversations.map(this._parseConversationFromRawData.bind(this))) | ||
.then(conversations => Promise.all(conversations.map( | ||
this._parseConversationFromRawData.bind(this) | ||
))) | ||
.then(conversations => conversations.map(fetchedConversation => { | ||
@@ -541,12 +548,18 @@ let conversation = this._conversationCache.get(fetchedConversation.id); | ||
}, rawData); | ||
if (data.lastMessage) { | ||
data.lastMessage = this._messageParser.parse(data.lastMessage); | ||
data.lastMessage.from = data.lastMessageFrom; | ||
data.lastMessage.id = data.lastMessageId; | ||
data.lastMessage.timestamp = new Date(data.lastMessageTimestamp); | ||
delete data.lastMessageFrom; | ||
delete data.lastMessageId; | ||
delete data.lastMessageTimestamp; | ||
} | ||
return new Conversation(data, this); | ||
return Promise.resolve().then(() => { | ||
if (data.lastMessage) { | ||
return this._messageParser.parse(data.lastMessage).then( | ||
message => { | ||
data.lastMessage = message; | ||
data.lastMessage.from = data.lastMessageFrom; | ||
data.lastMessage.id = data.lastMessageId; | ||
data.lastMessage.timestamp = new Date(data.lastMessageTimestamp); | ||
delete data.lastMessageFrom; | ||
delete data.lastMessageId; | ||
delete data.lastMessageTimestamp; | ||
} | ||
); | ||
} | ||
return Promise.resolve(); | ||
}).then(() => new Conversation(data, this)); | ||
} | ||
@@ -553,0 +566,0 @@ |
@@ -1,5 +0,67 @@ | ||
export { default as Realtime } from './realtime'; | ||
export { default as Message } from './messages/message'; | ||
export { default as TypedMessage } from './messages/typed-message'; | ||
export { default as TextMessage } from './messages/text-message'; | ||
export * from './messages/helpers'; | ||
/** @module leancloud-realtime */ | ||
import { default as Realtime } from './realtime'; | ||
import { default as Message } from './messages/message'; | ||
import { default as TypedMessage } from './messages/typed-message'; | ||
import { default as TextMessage } from './messages/text-message'; | ||
import { | ||
messageType, | ||
messageField, | ||
IE10Compatible, | ||
} from './messages/helpers'; | ||
export { | ||
/** | ||
* @see Realtime | ||
*/ | ||
Realtime, | ||
/** | ||
* @see Message | ||
*/ | ||
Message, | ||
/** | ||
* @see TypedMessage | ||
*/ | ||
TypedMessage, | ||
/** | ||
* @see TextMessage | ||
*/ | ||
TextMessage, | ||
/** | ||
* decorator,定义消息类的类型常量 | ||
* @function | ||
* @param {Number} type 自定义类型请使用正整数 | ||
* @example @messageType(1) | ||
* class CustomMessage extends TypedMessage {} | ||
* | ||
* // 不支持 decorator 的情况下可以这样使用 | ||
* class CustomMessage extends TypedMessage { | ||
* //... | ||
* } | ||
* messageType(1)(CustomMessage); | ||
*/ | ||
messageType, | ||
/** | ||
* decorator,定义消息类的自定义字段 | ||
* @function | ||
* @param {String[]} fields 自定义字段 | ||
* @example @messageField(['foo']) | ||
* class CustomMessage extends TypedMessage { | ||
* constructor(foo) { | ||
* super(); | ||
* this.foo = foo; | ||
* } | ||
* } | ||
* | ||
* // 不支持 decorator 的情况下可以这样使用 | ||
* class CustomMessage extends TypedMessage { | ||
* constructor(foo) { | ||
* super(); | ||
* this.foo = foo; | ||
* } | ||
* //... | ||
* } | ||
* messageField(['foo'])(CustomMessage); | ||
*/ | ||
messageField, | ||
IE10Compatible, | ||
}; |
import { default as d } from 'debug'; | ||
import isPlainObject from 'lodash/isPlainObject'; | ||
import { applyMiddlewares } from './plugin'; | ||
const debug = d('LC:MessageParser'); | ||
const tryParseJson = (target, key, descriptor) => { | ||
const fn = descriptor.value; | ||
// eslint-disable-next-line no-param-reassign | ||
descriptor.value = function wrapper(param) { | ||
let content; | ||
if (typeof param !== 'string') { | ||
content = param; | ||
} else { | ||
try { | ||
content = JSON.parse(param); | ||
} catch (error) { | ||
content = param; | ||
} | ||
} | ||
return fn.call(this, content); | ||
}; | ||
}; | ||
const applyPlugins = (target, key, descriptor) => { | ||
const fn = descriptor.value; | ||
// eslint-disable-next-line no-param-reassign | ||
descriptor.value = function wrapper(json) { | ||
return Promise.resolve(json) | ||
.then(applyMiddlewares(this._plugins.beforeMessageParse)) | ||
.then(decoratedJson => fn.call(this, decoratedJson)) | ||
.then(applyMiddlewares(this._plugins.afterMessageParse)); | ||
}; | ||
}; | ||
export default class MessageParser { | ||
constructor() { | ||
constructor(plugins = {}) { | ||
this._plugins = plugins; | ||
this._messageClasses = []; | ||
@@ -24,10 +55,8 @@ } | ||
parse(text) { | ||
debug('parsing message:', text); | ||
let content; | ||
try { | ||
content = JSON.parse(text); | ||
} catch (error) { | ||
content = text; | ||
} | ||
// jsdoc-ignore-start | ||
@tryParseJson | ||
@applyPlugins | ||
// jsdoc-ignore-end | ||
parse(content) { | ||
debug('parsing message:', content); | ||
for (const Klass of this._messageClasses) { | ||
@@ -34,0 +63,0 @@ const contentCopy = isPlainObject(content) ? Object.assign({}, content) : content; |
@@ -19,8 +19,8 @@ /** | ||
* 解析处理消息内容 (JSON -> AVMessage) | ||
* <pre> | ||
* 如果子类没有提供 message,直接使用该 message | ||
* 如果没有提供,实例化一个当前类型的 message | ||
* 将 JSON 格式的消息内容中相关的信息设置给该消息 | ||
* <p> | ||
* 如果子类没有提供 message,直接使用该 message, | ||
* 如果没有提供,实例化一个当前类型的 message, | ||
* 将 JSON 格式的消息内容中相关的信息设置给该消息, | ||
* 然后将其传递给父类的 parse 方法 | ||
* (当然,你也可以不管父类直接返回 message) | ||
* (当然,你也可以不管父类直接返回 message)。 | ||
* | ||
@@ -37,6 +37,6 @@ * @function | ||
* 将当前消息序列化为 JSON 对象 (AVMessage -> JSON) | ||
* <pre> | ||
* 在这个方法中,应该先调用父类的 toJSON 方法,得到 json 对象 | ||
* 然后,将当前消息实例的信息修改 json 对象后返回 | ||
* (当然,你也可以不管父类返回的 json) | ||
* <p> | ||
* 在这个方法中,应该先调用父类的 toJSON 方法,得到 JSON 对象, | ||
* 然后,将当前消息实例的信息修改 JSON 对象后返回 | ||
* (当然,你也可以不管父类返回的 JSON)。 | ||
* | ||
@@ -43,0 +43,0 @@ * @function |
/* eslint-disable no-param-reassign */ | ||
import { getStaticProperty, isIE10 } from '../utils'; | ||
/** | ||
* @namespace MessageHelper | ||
* @example | ||
* // 这是一个虚拟的 namespace,以下所有 members 请直接 import from 'leancloud-realtime' | ||
import { messageType } from 'leancloud-realtime'; | ||
*/ | ||
/** | ||
* decorator,定义消息类的类型常量 | ||
* @function | ||
* @memberof MessageHelper | ||
* @param {Number} type 自定义类型请使用正整数 | ||
* @example @messageType(1) | ||
* class CustomMessage extends TypedMessage {} | ||
* | ||
* // 不支持 decorator 的情况下可以这样使用 | ||
* class CustomMessage extends TypedMessage { | ||
* //... | ||
* } | ||
* messageType(1)(CustomMessage); | ||
*/ | ||
// documented in ../index.js | ||
export const messageType = type => { | ||
@@ -36,25 +16,3 @@ if (typeof type !== 'number') { | ||
/** | ||
* decorator,定义消息类的自定义字段 | ||
* @function | ||
* @memberof MessageHelper | ||
* @param {String[]} fields 自定义字段 | ||
* @example @messageField(['foo']) | ||
* class CustomMessage extends TypedMessage { | ||
* constructor(foo) { | ||
* super(); | ||
* this.foo = foo; | ||
* } | ||
* } | ||
* | ||
* // 不支持 decorator 的情况下可以这样使用 | ||
* class CustomMessage extends TypedMessage { | ||
* constructor(foo) { | ||
* super(); | ||
* this.foo = foo; | ||
* } | ||
* //... | ||
* } | ||
* messageField(['foo'])(CustomMessage); | ||
*/ | ||
// documented in ../index.js | ||
export const messageField = fields => { | ||
@@ -61,0 +19,0 @@ if (typeof fields !== 'string') { |
@@ -7,3 +7,4 @@ import Connection from './connection'; | ||
import uuid from 'uuid'; | ||
import { tap, Cache, trim, internal } from './utils'; | ||
import { tap, Cache, trim, internal, ensureArray } from './utils'; | ||
import { applyDecorators } from './plugin'; | ||
import Client from './client'; | ||
@@ -28,2 +29,3 @@ import IMClient from './im-client'; | ||
* @param {Boolean} [options.ssl=true] 使用 wss 进行连接 | ||
* @param {Plugin[]} [options.plugins] 加载插件(since 3.1.0) | ||
*/ | ||
@@ -45,3 +47,22 @@ constructor(options) { | ||
this._clients = {}; | ||
this._messageParser = new MessageParser(); | ||
this._plugins = ensureArray(options.plugins).reduce( | ||
(result, plugin) => { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const hook in plugin) { | ||
if (plugin.hasOwnProperty(hook) && hook !== 'name') { | ||
if (plugin.name) { | ||
ensureArray(plugin[hook]).forEach(value => { | ||
// eslint-disable-next-line no-param-reassign | ||
value._pluginName = plugin.name; | ||
}); | ||
} | ||
// eslint-disable-next-line no-param-reassign | ||
result[hook] = ensureArray(result[hook]).concat(plugin[hook]); | ||
} | ||
} | ||
return result; | ||
}, | ||
{} | ||
); | ||
this._messageParser = new MessageParser(this._plugins); | ||
this.register([ | ||
@@ -51,2 +72,6 @@ Message, | ||
]); | ||
// onRealtimeCreate hook | ||
applyDecorators(this._plugins.onRealtimeCreate, this); | ||
// messageClasses alias | ||
this.register(ensureArray(this._plugins.messageClasses)); | ||
} | ||
@@ -289,2 +314,3 @@ | ||
_messageParser: this._messageParser, | ||
_plugins: this._plugins, | ||
}); | ||
@@ -305,6 +331,2 @@ connection.on('reconnect', () => client._open(this._options.appId, tag, this._id, true)); | ||
createPushClient() { | ||
return this._open(); | ||
} | ||
/** | ||
@@ -320,5 +342,4 @@ * 注册消息类 | ||
register(messageClass) { | ||
const messageClasses = [].concat(messageClass); | ||
return messageClasses.map(this._messageParser.register.bind(this._messageParser)); | ||
return ensureArray(messageClass).map(this._messageParser.register.bind(this._messageParser)); | ||
} | ||
} |
@@ -110,1 +110,11 @@ import isPlainObject from 'lodash/isPlainObject'; | ||
export const trim = message => removeNull(JSON.parse(JSON.stringify(message))); | ||
export const ensureArray = target => { | ||
if (Array.isArray(target)) { | ||
return target; | ||
} | ||
if (target === undefined || target === null) { | ||
return []; | ||
} | ||
return [target]; | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2921119
40
27483
175
+ Addedaxios@0.13.1(transitive)
- Removedaxios@0.12.0(transitive)
Updatedaxios@^0.13.0
Updatedws@^1.1.1