mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 10:21:37 +08:00
add rollout strategy
This commit is contained in:
@@ -14,7 +14,7 @@ export const PushyModule =
|
|||||||
: NativeModules.Pushy;
|
: NativeModules.Pushy;
|
||||||
|
|
||||||
if (!PushyModule) {
|
if (!PushyModule) {
|
||||||
throw new Error('react-native-update模块无法加载,请对照安装文档检查配置。');
|
throw new Error('react-native-update 模块无法加载,请对照安装文档检查配置。');
|
||||||
}
|
}
|
||||||
|
|
||||||
const PushyConstants = isTurboModuleEnabled
|
const PushyConstants = isTurboModuleEnabled
|
||||||
@@ -33,7 +33,7 @@ let uuid = PushyConstants.uuid;
|
|||||||
|
|
||||||
if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {
|
if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'react-native-update模块无法加载,请对照文档检查Bundle URL的配置',
|
'react-native-update 模块无法加载,请对照文档检查 Bundle URL 的配置',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
77
src/isInRollout.ts
Normal file
77
src/isInRollout.ts
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/* eslint-disable no-fallthrough */
|
||||||
|
|
||||||
|
import { cInfo } from './core';
|
||||||
|
|
||||||
|
/* eslint-disable no-bitwise */
|
||||||
|
function murmurhash3_32_gc(key: string, seed = 0) {
|
||||||
|
let remainder, bytes, h1, h1b, c1, c2, k1, i;
|
||||||
|
|
||||||
|
remainder = key.length & 3; // key.length % 4
|
||||||
|
bytes = key.length - remainder;
|
||||||
|
h1 = seed;
|
||||||
|
c1 = 0xcc9e2d51;
|
||||||
|
c2 = 0x1b873593;
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
while (i < bytes) {
|
||||||
|
k1 =
|
||||||
|
(key.charCodeAt(i) & 0xff) |
|
||||||
|
((key.charCodeAt(++i) & 0xff) << 8) |
|
||||||
|
((key.charCodeAt(++i) & 0xff) << 16) |
|
||||||
|
((key.charCodeAt(++i) & 0xff) << 24);
|
||||||
|
++i;
|
||||||
|
|
||||||
|
((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
|
||||||
|
k1 = (k1 << 15) | (k1 >>> 17);
|
||||||
|
k1 =
|
||||||
|
((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;
|
||||||
|
|
||||||
|
h1 ^= k1;
|
||||||
|
h1 = (h1 << 13) | (h1 >>> 19);
|
||||||
|
h1b =
|
||||||
|
((h1 & 0xffff) * 5 + ((((h1 >>> 16) * 5) & 0xffff) << 16)) & 0xffffffff;
|
||||||
|
h1 = (h1b & 0xffff) + 0x6b64 + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
k1 = 0;
|
||||||
|
|
||||||
|
switch (remainder) {
|
||||||
|
case 3:
|
||||||
|
k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
|
||||||
|
case 2:
|
||||||
|
k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
|
||||||
|
case 1:
|
||||||
|
k1 ^= key.charCodeAt(i) & 0xff;
|
||||||
|
|
||||||
|
k1 =
|
||||||
|
((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
|
||||||
|
0xffffffff;
|
||||||
|
k1 = (k1 << 15) | (k1 >>> 17);
|
||||||
|
k1 =
|
||||||
|
((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
|
||||||
|
0xffffffff;
|
||||||
|
h1 ^= k1;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 ^= key.length;
|
||||||
|
|
||||||
|
h1 ^= h1 >>> 16;
|
||||||
|
h1 =
|
||||||
|
((h1 & 0xffff) * 0x85ebca6b +
|
||||||
|
((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) &
|
||||||
|
0xffffffff;
|
||||||
|
h1 ^= h1 >>> 13;
|
||||||
|
h1 =
|
||||||
|
((h1 & 0xffff) * 0xc2b2ae35 +
|
||||||
|
((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16)) &
|
||||||
|
0xffffffff;
|
||||||
|
h1 ^= h1 >>> 16;
|
||||||
|
|
||||||
|
return h1 >>> 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const intForUUID = murmurhash3_32_gc(cInfo.uuid);
|
||||||
|
|
||||||
|
export function isInRollout(rollout: number) {
|
||||||
|
return intForUUID % 100 < rollout;
|
||||||
|
}
|
@@ -22,6 +22,8 @@ import {
|
|||||||
import { CheckResult, ProgressData, PushyTestPayload } from './type';
|
import { CheckResult, ProgressData, PushyTestPayload } from './type';
|
||||||
import { PushyContext } from './context';
|
import { PushyContext } from './context';
|
||||||
import { URL } from 'react-native-url-polyfill';
|
import { URL } from 'react-native-url-polyfill';
|
||||||
|
import { isInRollout } from './isInRollout';
|
||||||
|
import { log } from './utils';
|
||||||
|
|
||||||
export const PushyProvider = ({
|
export const PushyProvider = ({
|
||||||
client,
|
client,
|
||||||
@@ -165,6 +167,14 @@ export const PushyProvider = ({
|
|||||||
if (!info) {
|
if (!info) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const rollout = info.config?.rollout;
|
||||||
|
if (rollout) {
|
||||||
|
if (!isInRollout(rollout)) {
|
||||||
|
log(`not in ${rollout}% rollout, ignored`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log(`in ${rollout}% rollout, continue`);
|
||||||
|
}
|
||||||
info.description = info.description ?? '';
|
info.description = info.description ?? '';
|
||||||
updateInfoRef.current = info;
|
updateInfoRef.current = info;
|
||||||
setUpdateInfo(info);
|
setUpdateInfo(info);
|
||||||
|
@@ -7,6 +7,10 @@ export interface CheckResult {
|
|||||||
hash?: string;
|
hash?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
metaInfo?: string;
|
metaInfo?: string;
|
||||||
|
config?: {
|
||||||
|
rollout?: number;
|
||||||
|
[key: string]: any;
|
||||||
|
};
|
||||||
pdiff?: string;
|
pdiff?: string;
|
||||||
diff?: string;
|
diff?: string;
|
||||||
full?: string;
|
full?: string;
|
||||||
|
Reference in New Issue
Block a user