2017-10-12 10:00:28 +08:00
|
|
|
import WhiteboardMultiUser from '/imports/api/whiteboard-multi-user/';
|
2018-04-25 02:42:59 +08:00
|
|
|
import Users from '/imports/api/users';
|
2016-05-13 01:43:59 +08:00
|
|
|
|
2018-04-12 21:41:32 +08:00
|
|
|
const MSG_DIRECT_TYPE = 'DIRECT';
|
|
|
|
const NODE_USER = 'nodeJSapp';
|
2016-05-13 01:43:59 +08:00
|
|
|
|
2016-05-05 01:00:57 +08:00
|
|
|
export const indexOf = [].indexOf || function (item) {
|
2017-08-10 11:59:53 +08:00
|
|
|
for (let i = 0, l = this.length; i < l; i += 1) {
|
2017-06-03 03:25:02 +08:00
|
|
|
if (i in this && this[i] === item) {
|
|
|
|
return i;
|
2016-06-28 02:24:37 +08:00
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|
2016-06-28 02:24:37 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
return -1;
|
|
|
|
};
|
2016-05-05 04:25:34 +08:00
|
|
|
|
2018-04-14 03:26:58 +08:00
|
|
|
export const processForHTML5ServerOnly = fn => (message, ...args) => {
|
2018-04-12 21:41:32 +08:00
|
|
|
const { envelope } = message;
|
|
|
|
const { routing } = envelope;
|
2018-04-25 22:29:55 +08:00
|
|
|
const { msgType, meetingId, userId } = routing;
|
2018-04-12 21:41:32 +08:00
|
|
|
|
2018-04-25 02:42:59 +08:00
|
|
|
const selector = {
|
2018-04-25 22:29:55 +08:00
|
|
|
userId,
|
|
|
|
meetingId,
|
2018-04-25 02:42:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const user = Users.findOne(selector);
|
|
|
|
|
2018-04-25 22:29:55 +08:00
|
|
|
const shouldSkip = user && msgType === MSG_DIRECT_TYPE && userId !== NODE_USER && user.clientType !== 'HTML5';
|
2018-04-12 21:41:32 +08:00
|
|
|
if (shouldSkip) return () => { };
|
2018-04-23 20:30:14 +08:00
|
|
|
return fn(message, ...args);
|
2018-04-12 21:41:32 +08:00
|
|
|
};
|
|
|
|
|
2017-08-10 11:59:53 +08:00
|
|
|
|
2018-04-10 07:18:49 +08:00
|
|
|
export const getMultiUserStatus = (meetingId, whiteboardId) => {
|
|
|
|
const data = WhiteboardMultiUser.findOne({ meetingId, whiteboardId });
|
2017-08-10 11:59:53 +08:00
|
|
|
|
|
|
|
if (data) {
|
|
|
|
return data.multiUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
2019-05-17 04:11:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate a 32 bit FNV-1a hash
|
|
|
|
* Found here: https://gist.github.com/vaiorabbit/5657561
|
|
|
|
* Ref.: http://isthe.com/chongo/tech/comp/fnv/
|
|
|
|
*
|
|
|
|
* @param {string} str the input value
|
|
|
|
* @param {boolean} [asString=false] set to true to return the hash value as
|
|
|
|
* 8-digit hex string instead of an integer
|
|
|
|
* @param {integer} [seed] optionally pass the hash of the previous chunk
|
|
|
|
* @returns {integer | string}
|
|
|
|
*/
|
|
|
|
export const hashFNV32a = (str, asString, seed) => {
|
|
|
|
let hval = (seed === undefined) ? 0x811c9dc5 : seed;
|
|
|
|
|
|
|
|
for (let i = 0, l = str.length; i < l; i++) {
|
|
|
|
hval ^= str.charCodeAt(i);
|
|
|
|
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
|
|
}
|
|
|
|
if (asString) {
|
|
|
|
return (`0000000${(hval >>> 0).toString(16)}`).substr(-8);
|
|
|
|
}
|
|
|
|
return hval >>> 0;
|
|
|
|
};
|