Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

2.0.3 相关问题修复。 #30

Merged
merged 9 commits into from
Jun 4, 2015
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.0.3
* 修正 where 参数无法发送的 bug
* 支持美国节点
* 暴露 installationId

# 2.0.2
* 修正 event center 中的 bug
* 修正 ajax 对于 2xx 的返回码都应该认为正确
Expand Down
16 changes: 15 additions & 1 deletion demo/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
padding: 0px;
}

body {
padding-top: 20px;
text-align: center;
font-size: 13px;
}

h1 {
font-size: 22px;
}

#result {
text-align: left;
margin-top: 30px;
padding-left: 20%;
}

#result p {
font-size: 20px;
font-size: 15px;
margin: 2px;
}

45 changes: 35 additions & 10 deletions src/AV.push.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @author wangxiao
* @date 2015-03-30
* @date 2015-06-02
*
* 每位工程师都有保持代码优雅的义务
* Each engineer has a duty to keep the code elegant
Expand All @@ -9,7 +9,7 @@
void function(win) {

// 当前版本
var VERSION = '2.0.2';
var VERSION = '2.0.3';

// 获取命名空间
var AV = win.AV || {};
Expand Down Expand Up @@ -140,7 +140,7 @@ void function(win) {

engine.sendId = function(options, callback) {
tool.ajax({
url: 'https://leancloud.cn/1.1/installations',
url: 'https://' + cache.options.host + '/1.1/installations',
method: 'post',
appId: options.appId,
appKey: options.appKey,
Expand All @@ -166,7 +166,7 @@ void function(win) {

engine.sendPush = function(options, callback) {
tool.ajax({
url: 'https://leancloud.cn/1.1/push',
url: 'https://' + cache.options.host + '/1.1/push',
method: 'post',
appId: options.appId,
appKey: options.appKey,
Expand Down Expand Up @@ -208,7 +208,7 @@ void function(win) {
data.channels = channels;
}
tool.ajax({
url: 'https://leancloud.cn/1.1/installations',
url: 'https://' + cache.options.host + '/1.1/installations',
method: 'post',
appId: cache.options.appId,
appKey: cache.options.appKey,
Expand Down Expand Up @@ -285,13 +285,22 @@ void function(win) {
engine.getServer = function(options, callback) {
var appId = options.appId;
// 是否获取 wss 的安全链接
var secure = options.secure || true;
var secure = options.secure;
var url = '';
var protocol = 'http://';
if (win && win.location.protocol === 'https:') {
protocol = 'https://';
}
url = protocol + 'router-g0-push.avoscloud.com/v1/route?appId=' + appId ;
var node = '';
switch (options.region) {
case 'cn':
node = 'g0';
break;
case 'us':
node = 'a0';
break;
}
url = protocol + 'router-' + node + '-push.avoscloud.com/v1/route?appId=' + appId ;
if (secure) {
url += '&secure=1';
}
Expand All @@ -314,6 +323,7 @@ void function(win) {
};

return {
installationId: '',
cache: cache,
open: function(callback) {
var me = this;
Expand Down Expand Up @@ -375,8 +385,9 @@ void function(win) {
engine.sendPush(obj, callback);
}
else {
obj.data = argument.data;
obj.channels = argument.channels;
for (var k in argument) {
obj[k] = argument[k];
}
engine.sendPush(obj, callback);
}
return this;
Expand Down Expand Up @@ -420,9 +431,23 @@ void function(win) {
options.channels = options.channels || [];
var pushObject = newPushObject();
options.deviceType = 'web';
// 服务器地区选项,默认为中国大陆
options.region = options.region || 'cn';
switch(options.region) {
case 'cn':
options.host = 'leancloud.cn';
break;
case 'us':
options.host = 'avoscloud.us';
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以加个 default 扔个异常出来

}
pushObject.cache.options = options;
// 这个 id 是针对设备的抽象
options.id = engine.getId(options);
pushObject.cache.options = options;
// 暴露 installationId
pushObject.installationId = options.id;
// 设置安全连接,默认为安全连接
options.secure = typeof(options.secure) === 'undefined' ? true : options.secure;
pushObject.cache.ec = tool.eventCenter();
return pushObject;
}
Expand Down