Compare commits
3 commits
ec7ca22811
...
a3c8015b4b
Author | SHA1 | Date | |
---|---|---|---|
flash | a3c8015b4b | ||
flash | 49f00b00d8 | ||
flash | 5b5ca888a4 |
|
@ -1,8 +1,8 @@
|
|||
const MamiColour = (() => {
|
||||
const readThres = 168,
|
||||
lumiRed = .299,
|
||||
lumiGreen = .587,
|
||||
lumiBlue = .114;
|
||||
const readThres = 168;
|
||||
const lumiRed = .299;
|
||||
const lumiGreen = .587;
|
||||
const lumiBlue = .114;
|
||||
|
||||
const pub = {};
|
||||
|
||||
|
@ -25,8 +25,8 @@ const MamiColour = (() => {
|
|||
};
|
||||
|
||||
const weighted = (raw1, raw2, weight) => {
|
||||
const rgb1 = extractRGB(raw1),
|
||||
rgb2 = extractRGB(raw2);
|
||||
const rgb1 = extractRGB(raw1);
|
||||
const rgb2 = extractRGB(raw2);
|
||||
return (weightedNumber(rgb1[0], rgb2[0], weight) << 16)
|
||||
| (weightedNumber(rgb1[1], rgb2[1], weight) << 8)
|
||||
| weightedNumber(rgb1[2], rgb2[2], weight);
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
||||
|
||||
#include animate.js
|
||||
#include channel.js
|
||||
#include channels.js
|
||||
#include common.js
|
||||
#include context.js
|
||||
#include emotes.js
|
||||
#include message.js
|
||||
#include messages.js
|
||||
#include mszauth.js
|
||||
#include parsing.js
|
||||
#include server.js
|
||||
#include txtrigs.js
|
||||
#include user.js
|
||||
#include users.js
|
||||
#include utility.js
|
||||
#include weeb.js
|
||||
#include audio/autoplay.js
|
||||
|
@ -21,10 +27,12 @@ window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
|||
#include sound/umisound.js
|
||||
#include ui/chat-layout.js
|
||||
#include ui/hooks.js
|
||||
#include ui/emotes.js
|
||||
#include ui/input-menus.js
|
||||
#include ui/loading-overlay.jsx
|
||||
#include ui/markup.js
|
||||
#include ui/menus.js
|
||||
#include ui/messages.jsx
|
||||
#include ui/view.js
|
||||
#include ui/settings.jsx
|
||||
#include ui/toggles.js
|
||||
|
@ -109,6 +117,7 @@ window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
|||
settings.define('osuKeysV2', ['no', 'yes', 'rng'], 'no');
|
||||
settings.define('explosionRadius', 'number', 20);
|
||||
settings.define('dumpPackets', 'boolean', FUTAMI_DEBUG);
|
||||
settings.define('dumpEvents', 'boolean', FUTAMI_DEBUG);
|
||||
settings.define('neverUseWorker', 'boolean', false, false, true);
|
||||
settings.define('forceUseWorker', 'boolean', false, false, true);
|
||||
settings.define('marqueeAllNames', 'boolean', false);
|
||||
|
@ -244,7 +253,7 @@ window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
|||
return 'minecraft:door:open';
|
||||
if(v === 'old')
|
||||
return 'minecraft:door:open-old';
|
||||
return mami.sound.pack.getEventSound('join');
|
||||
return soundCtx.pack.getEventSound('join');
|
||||
})());
|
||||
});
|
||||
|
||||
|
@ -445,7 +454,7 @@ window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
|||
insertText = `[video]${fileInfo.url}[/video]`;
|
||||
uploadEntry.setThumbnail(fileInfo.thumb);
|
||||
} else
|
||||
insertText = location.protocol + fileInfo.url;
|
||||
insertText = location.Umi.Servercol + fileInfo.url;
|
||||
|
||||
if(settings.get('eepromAutoInsert'))
|
||||
Umi.UI.Markup.InsertRaw(insertText, '');
|
||||
|
@ -521,8 +530,386 @@ window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
|||
});
|
||||
|
||||
|
||||
// really not sure about all the watchers for the protocol just kinda being Listed here but we'll see i guess
|
||||
loadingOverlay.setMessage('Connecting...');
|
||||
Umi.Server.open(views, settings);
|
||||
|
||||
const getLoadingOverlay = async (icon, header, message) => {
|
||||
const currentView = views.current();
|
||||
|
||||
if('setIcon' in currentView) {
|
||||
currentView.setIcon(icon);
|
||||
currentView.setHeader(header);
|
||||
currentView.setMessage(message);
|
||||
return currentView;
|
||||
}
|
||||
|
||||
const loading = new Umi.UI.LoadingOverlay(icon, header, message);
|
||||
await views.push(loading);
|
||||
|
||||
return loading;
|
||||
};
|
||||
|
||||
const wsCloseReasons = {
|
||||
'_1000': 'The connection has been ended.',
|
||||
'_1001': 'Something went wrong on the server side.',
|
||||
'_1002': 'Your client sent broken data to the server.',
|
||||
'_1003': 'Your client sent data to the server that it does not understand.',
|
||||
'_1005': 'No additional information was provided.',
|
||||
'_1006': 'You lost connection unexpectedly!',
|
||||
'_1007': 'Your client sent broken data to the server.',
|
||||
'_1008': 'Your client did something the server did not agree with.',
|
||||
'_1009': 'Your client sent too much data to the server at once.',
|
||||
'_1011': 'Something went wrong on the server side.',
|
||||
'_1012': 'The server is restarting, reconnecting soon...',
|
||||
'_1013': 'You cannot connect to the server right now, try again later.',
|
||||
'_1015': 'Your client and the server could not establish a secure connection.',
|
||||
};
|
||||
|
||||
let dumpEvents = false;
|
||||
settings.watch('dumpEvents', value => dumpEvents = value);
|
||||
settings.watch('dumpPackets', value => Umi.Server.setDumpPackets(value));
|
||||
|
||||
Umi.Server.watch('conn:init', init => {
|
||||
if(dumpEvents) console.log('conn:init', init);
|
||||
|
||||
let message = 'Connecting to server...';
|
||||
if(init.attempt > 2)
|
||||
message += ` (Attempt ${connectAttempts})`;
|
||||
|
||||
getLoadingOverlay('spinner', 'Loading...', message);
|
||||
});
|
||||
Umi.Server.watch('conn:ready', ready => {
|
||||
if(dumpEvents) console.log('conn:ready', ready);
|
||||
|
||||
getLoadingOverlay('spinner', 'Loading...', 'Authenticating...');
|
||||
});
|
||||
Umi.Server.watch('conn:lost', lost => {
|
||||
if(dumpEvents) console.log('conn:lost', lost);
|
||||
|
||||
getLoadingOverlay(
|
||||
'unlink', 'Disconnected!',
|
||||
wsCloseReasons[`_${lost.code}`] ?? `Something caused an unexpected connection loss. (${lost.code})`
|
||||
);
|
||||
});
|
||||
Umi.Server.watch('conn:error', error => {
|
||||
console.error('conn:error', error);
|
||||
});
|
||||
|
||||
Umi.Server.watch('ping:send', send => {
|
||||
if(dumpEvents) console.log('ping:send', send);
|
||||
});
|
||||
Umi.Server.watch('ping:long', long => {
|
||||
if(dumpEvents) console.log('ping:long', long);
|
||||
});
|
||||
Umi.Server.watch('ping:recv', recv => {
|
||||
if(dumpEvents) console.log('ping:recv', recv);
|
||||
});
|
||||
|
||||
|
||||
const playBannedSfx = async () => {
|
||||
await soundCtx.library.play('touhou:pichuun');
|
||||
};
|
||||
const playBannedBgm = async preload => {
|
||||
const name = 'touhou:th10score';
|
||||
|
||||
if(preload) {
|
||||
await soundCtx.library.loadBuffer(name);
|
||||
return;
|
||||
}
|
||||
|
||||
const source = await soundCtx.library.loadSource(name);
|
||||
source.setLoop(true, 10.512, 38.074);
|
||||
await source.play();
|
||||
};
|
||||
const displayBanMessage = baka => {
|
||||
let message;
|
||||
if(baka.perma)
|
||||
message = 'You have been banned till the end of time, please try again in a different dimension.';
|
||||
else if(baka.until)
|
||||
message = `You were banned until ${baka.until.toLocaleString()}!`;
|
||||
else
|
||||
message = 'You were kicked, refresh to log back in!';
|
||||
|
||||
const icon = baka.type === 'kick' ? 'bomb' : 'hammer';
|
||||
const header = baka.type === 'kick' ? 'Kicked!' : 'Banned!';
|
||||
|
||||
const currentView = views.current();
|
||||
|
||||
if(currentView === undefined || 'setIcon' in currentView) {
|
||||
playBannedBgm();
|
||||
getLoadingOverlay(icon, header, message);
|
||||
} else {
|
||||
const currentViewElem = views.currentElement();
|
||||
|
||||
MamiAnimate({
|
||||
duration: 550,
|
||||
easing: 'outExpo',
|
||||
start: () => {
|
||||
playBannedBgm(true);
|
||||
playBannedSfx();
|
||||
},
|
||||
update: t => {
|
||||
currentViewElem.style.transform = `scale(${(1 - .5 * t)}, ${(1 - 1 * t)})`;
|
||||
},
|
||||
end: () => {
|
||||
getLoadingOverlay(icon, header, message).then(() => {
|
||||
playBannedBgm();
|
||||
|
||||
// there's currently no way to reconnect after a kick/ban so just dispose of the ui entirely
|
||||
if(views.count() > 1)
|
||||
views.shift();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Umi.Server.watch('session:start', start => {
|
||||
if(dumpEvents) console.log('session:start', start);
|
||||
|
||||
const userInfo = new Umi.User(start.user.id, start.user.name, start.user.colour, start.user.permsRaw);
|
||||
Umi.User.setCurrentUser(userInfo);
|
||||
Umi.Users.Add(userInfo);
|
||||
|
||||
Umi.UI.Markup.Reset();
|
||||
Umi.UI.Emoticons.Init();
|
||||
Umi.Parsing.Init();
|
||||
|
||||
views.pop(ctx => MamiAnimate({
|
||||
async: true,
|
||||
duration: 120,
|
||||
easing: 'inOutSine',
|
||||
start: () => {
|
||||
ctx.toElem.style.zIndex = '100';
|
||||
ctx.fromElem.style.pointerEvents = 'none';
|
||||
ctx.fromElem.style.zIndex = '200';
|
||||
},
|
||||
update: t => {
|
||||
ctx.fromElem.style.transform = `scale(${1 + (.25 * t)})`;
|
||||
ctx.fromElem.style.opacity = 1 - (1 * t).toString();
|
||||
},
|
||||
end: () => {
|
||||
ctx.toElem.style.zIndex = null;
|
||||
},
|
||||
}));
|
||||
});
|
||||
Umi.Server.watch('session:fail', fail => {
|
||||
if(dumpEvents) console.log('session:fail', fail);
|
||||
|
||||
if(fail.baka !== undefined) {
|
||||
displayBanMessage(fail.baka);
|
||||
return;
|
||||
}
|
||||
|
||||
const message = (reason => {
|
||||
if(reason === 'authfail')
|
||||
return 'Authentication failed.';
|
||||
if(reason === 'sockfail')
|
||||
return 'Too many active connections.';
|
||||
if(reason === 'userfail')
|
||||
return 'Name in use.';
|
||||
if(reason === 'joinfail')
|
||||
return 'You are banned.';
|
||||
return `Unknown reason: ${reason}`;
|
||||
})(fail.session.reason);
|
||||
|
||||
getLoadingOverlay('cross', 'Failed!', message);
|
||||
|
||||
if(fail.session.needsAuth)
|
||||
setTimeout(() => location.assign(futami.get('login')), 1000);
|
||||
});
|
||||
Umi.Server.watch('session:term', term => {
|
||||
if(dumpEvents) console.log('session:term', term);
|
||||
|
||||
displayBanMessage(term.baka);
|
||||
});
|
||||
|
||||
Umi.Server.watch('user:add', add => {
|
||||
if(dumpEvents) console.log('user:add', add);
|
||||
|
||||
if(add.user.self)
|
||||
return;
|
||||
|
||||
const userInfo = new Umi.User(add.user.id, add.user.name, add.user.colour, add.user.permsRaw);
|
||||
Umi.Users.Add(userInfo);
|
||||
|
||||
if(add.msg !== undefined)
|
||||
Umi.Messages.Add(new Umi.Message(
|
||||
add.msg.id, add.msg.time, undefined, '', add.msg.channel, false,
|
||||
{
|
||||
isError: false,
|
||||
type: add.msg.botInfo.type,
|
||||
args: add.msg.botInfo.args,
|
||||
target: userInfo,
|
||||
}
|
||||
));
|
||||
});
|
||||
Umi.Server.watch('user:remove', remove => {
|
||||
if(dumpEvents) console.log('user:remove', remove);
|
||||
|
||||
const userInfo = Umi.Users.Get(remove.user.id);
|
||||
if(userInfo === null)
|
||||
return;
|
||||
|
||||
if(remove.msg !== undefined)
|
||||
Umi.Messages.Add(new Umi.Message(
|
||||
remove.msg.id,
|
||||
remove.msg.time,
|
||||
undefined,
|
||||
'',
|
||||
remove.msg.channel,
|
||||
false,
|
||||
{
|
||||
isError: false,
|
||||
type: remove.msg.botInfo.type,
|
||||
args: remove.msg.botInfo.args,
|
||||
target: userInfo,
|
||||
},
|
||||
));
|
||||
|
||||
Umi.Users.Remove(userInfo);
|
||||
});
|
||||
Umi.Server.watch('user:update', update => {
|
||||
if(dumpEvents) console.log('user:update', update);
|
||||
|
||||
const userInfo = Umi.Users.Get(update.user.id);
|
||||
userInfo.setName(update.user.name);
|
||||
userInfo.setColour(update.user.colour);
|
||||
userInfo.setPermissions(update.user.permsRaw);
|
||||
Umi.Users.Update(userInfo.getId(), userInfo);
|
||||
});
|
||||
Umi.Server.watch('user:clear', () => {
|
||||
if(dumpEvents) console.log('user:clear');
|
||||
|
||||
const self = Umi.User.currentUser;
|
||||
Umi.Users.Clear();
|
||||
if(self !== undefined)
|
||||
Umi.Users.Add(self);
|
||||
});
|
||||
|
||||
Umi.Server.watch('chan:add', add => {
|
||||
if(dumpEvents) console.log('chan:add', add);
|
||||
|
||||
Umi.Channels.Add(new Umi.Channel(
|
||||
add.channel.name,
|
||||
add.channel.hasPassword,
|
||||
add.channel.isTemporary,
|
||||
));
|
||||
});
|
||||
Umi.Server.watch('chan:remove', remove => {
|
||||
if(dumpEvents) console.log('chan:remove', remove);
|
||||
|
||||
Umi.Channels.Remove(Umi.Channels.Get(remove.channel.name));
|
||||
});
|
||||
Umi.Server.watch('chan:update', update => {
|
||||
if(dumpEvents) console.log('chan:update', update);
|
||||
|
||||
const chanInfo = Umi.Channels.Get(update.channel.previousName);
|
||||
chanInfo.setName(update.channel.name);
|
||||
chanInfo.setHasPassword(update.channel.hasPassword);
|
||||
chanInfo.setTemporary(update.channel.isTemporary);
|
||||
Umi.Channels.Update(update.channel.previousName, chanInfo);
|
||||
});
|
||||
Umi.Server.watch('chan:clear', () => {
|
||||
if(dumpEvents) console.log('chan:clear');
|
||||
|
||||
Umi.Channels.Clear();
|
||||
});
|
||||
Umi.Server.watch('chan:focus', focus => {
|
||||
if(dumpEvents) console.log('chan:focus', focus);
|
||||
|
||||
Umi.Channels.Switch(Umi.Channels.Get(focus.channel.name));
|
||||
});
|
||||
Umi.Server.watch('chan:join', join => {
|
||||
if(dumpEvents) console.log('chan:join', join);
|
||||
|
||||
const userInfo = new Umi.User(join.user.id, join.user.name, join.user.colour, join.user.permsRaw);
|
||||
Umi.Users.Add(userInfo);
|
||||
|
||||
if(join.msg !== undefined)
|
||||
Umi.Messages.Add(new Umi.Message(
|
||||
join.msg.id, null, undefined, '', join.msg.channel, false,
|
||||
{
|
||||
isError: false,
|
||||
type: leave.msg.botInfo.type,
|
||||
args: [ userInfo.getName() ],
|
||||
target: userInfo,
|
||||
},
|
||||
));
|
||||
});
|
||||
Umi.Server.watch('chan:leave', leave => {
|
||||
if(dumpEvents) console.log('chan:leave', leave);
|
||||
|
||||
if(leave.user.self)
|
||||
return;
|
||||
|
||||
const userInfo = Umi.Users.Get(leave.user.id);
|
||||
if(userInfo === null)
|
||||
return;
|
||||
|
||||
if(leave.msg !== undefined)
|
||||
Umi.Messages.Add(new Umi.Message(
|
||||
leave.msg.id, null, undefined, '', leave.msg.channel, false,
|
||||
{
|
||||
isError: false,
|
||||
type: leave.msg.botInfo.type,
|
||||
args: [ userInfo.getName() ],
|
||||
target: userInfo,
|
||||
},
|
||||
));
|
||||
|
||||
Umi.Users.Remove(userInfo);
|
||||
});
|
||||
|
||||
Umi.Server.watch('msg:add', add => {
|
||||
if(dumpEvents) console.log('msg:add', add);
|
||||
|
||||
const senderInfo = add.msg.sender;
|
||||
const userInfo = senderInfo.name === undefined
|
||||
? Umi.Users.Get(senderInfo.id)
|
||||
: new Umi.User(senderInfo.id, senderInfo.name, senderInfo.colour, senderInfo.permsRaw);
|
||||
|
||||
// hack
|
||||
let channelName = add.msg.channel;
|
||||
if(channelName !== undefined && channelName.startsWith('@~')) {
|
||||
const chanUserInfo = Umi.Users.Get(channelName.substring(2));
|
||||
if(chanUserInfo !== null)
|
||||
channelName = `@${chanUserInfo.getName()}`;
|
||||
}
|
||||
|
||||
// also hack
|
||||
if(add.msg.flags.isPM) {
|
||||
if(Umi.Channels.Get(channelName) === null)
|
||||
Umi.Channels.Add(new Umi.Channel(channelName, false, true, true));
|
||||
|
||||
// this should be raised for other channels too, but that is not possible yet
|
||||
Umi.UI.Menus.Attention('channels');
|
||||
}
|
||||
|
||||
Umi.Messages.Add(new Umi.Message(
|
||||
add.msg.id,
|
||||
add.msg.time,
|
||||
userInfo,
|
||||
add.msg.text,
|
||||
channelName,
|
||||
false,
|
||||
add.msg.botInfo,
|
||||
add.msg.flags.isAction,
|
||||
add.msg.silent,
|
||||
));
|
||||
});
|
||||
Umi.Server.watch('msg:remove', remove => {
|
||||
if(dumpEvents) console.log('msg:remove', remove);
|
||||
|
||||
Umi.Messages.Remove(Umi.Messages.Get(remove.msg.id));
|
||||
});
|
||||
Umi.Server.watch('msg:clear', () => {
|
||||
if(dumpEvents) console.log('msg:clear');
|
||||
|
||||
Umi.UI.Messages.RemoveAll();
|
||||
});
|
||||
|
||||
Umi.Server.open();
|
||||
|
||||
if(window.dispatchEvent)
|
||||
window.dispatchEvent(new Event('umi:connect'));
|
||||
|
|
|
@ -5,7 +5,7 @@ Umi.Message = (() => {
|
|||
|
||||
return function(msgId, time, user, text, channel, highlight, botInfo, isAction, isLog) {
|
||||
msgId = (msgId || '').toString();
|
||||
time = time === null ? new Date() : new Date(parseInt(time || 0) * 1000);
|
||||
time = time === null ? new Date() : (typeof time === 'object' ? time : new Date(parseInt(time || 0) * 1000));
|
||||
user = user !== null && typeof user === 'object' ? user : chatBot;
|
||||
text = (text || '').toString();
|
||||
channel = (channel || '').toString();
|
||||
|
@ -18,7 +18,10 @@ Umi.Message = (() => {
|
|||
|
||||
return {
|
||||
getId: () => msgId,
|
||||
getIdInt: () => msgIdInt,
|
||||
getIdInt: () => {
|
||||
const num = parseInt(msgId);
|
||||
return isNaN(num) ? (Math.round(Number.MIN_SAFE_INTEGER * Math.random())) : num;
|
||||
},
|
||||
getTime: () => time,
|
||||
getUser: () => user,
|
||||
getText: () => text,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include channels.js
|
||||
#include server.js
|
||||
#include ui/messages.jsx
|
||||
|
||||
Umi.Messages = (function() {
|
||||
|
|
|
@ -1,26 +1,3 @@
|
|||
#include sockchat_old.js
|
||||
|
||||
Umi.Server = (function() {
|
||||
let proto = null;
|
||||
|
||||
return {
|
||||
open: function(...args) {
|
||||
proto = new Umi.Protocol.SockChat.Protocol(...args);
|
||||
proto.open();
|
||||
},
|
||||
close: function() {
|
||||
if(!proto)
|
||||
return;
|
||||
proto.close();
|
||||
proto = null;
|
||||
},
|
||||
sendMessage: function(text) {
|
||||
if(!proto)
|
||||
return;
|
||||
text = (text || '').toString();
|
||||
if(!text)
|
||||
return;
|
||||
proto.sendMessage(text);
|
||||
},
|
||||
};
|
||||
})();
|
||||
Umi.Server = new Umi.Protocol.SockChat.Protocol;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -47,6 +47,7 @@ Umi.UI.Hooks = (function() {
|
|||
|
||||
Umi.Channels.OnSwitch.push(function(name, channel) {
|
||||
Umi.UI.Channels.Reload(name === null);
|
||||
Umi.Server.switchChannel(channel);
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ Umi.UI.Messages = (function() {
|
|||
'kick': { text: '%0 got bludgeoned to death.', action: 'got bludgeoned to death', avatar: 'invert', sound: 'kick' },
|
||||
'flood': { text: '%0 got kicked for flood protection.', action: 'got kicked for flood protection', avatar: 'invert', sound: 'flood' },
|
||||
'timeout': { text: '%0 exploded.', action: 'exploded', avatar: 'greyscale', sound: 'timeout' },
|
||||
'nick': { text: '%0 changed their name to %1.' },
|
||||
'nick': { text: '%0 changed their name to %1.', action: 'changed their name to %1' },
|
||||
'crchan': { text: 'Channel %0 has been created.' },
|
||||
'delchan': { text: 'Channel %0 has been deleted.' },
|
||||
'cpwdchan': { text: 'Channel password has been changed.' },
|
||||
|
@ -181,7 +181,7 @@ Umi.UI.Messages = (function() {
|
|||
|
||||
let actionSuccess = false;
|
||||
if(typeof bmInfo.action === 'string' && mami.settings.get('fancyInfo')) {
|
||||
const target = botInfo.target || Umi.Users.FindExact(bArgs[0]);
|
||||
const target = botInfo.target ?? Umi.Users.FindExact(bArgs[0]) ?? Umi.Users.FindExact('~' + bArgs[0]); // shitty fix for server sending invalid data
|
||||
|
||||
if(target) {
|
||||
actionSuccess = true;
|
||||
|
@ -191,7 +191,7 @@ Umi.UI.Messages = (function() {
|
|||
|
||||
$ari(classes, userClass);
|
||||
|
||||
msgText = bmInfo.action;
|
||||
msgText = formatTemplate(bmInfo.action, bArgs);
|
||||
if(typeof bmInfo.avatar === 'string')
|
||||
avatarClasses.push(`avatar-filter-${bmInfo.avatar}`);
|
||||
}
|
||||
|
|
|
@ -358,6 +358,11 @@ Umi.UI.Settings = (function() {
|
|||
title: 'Dump packets to console',
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
name: 'dumpEvents',
|
||||
title: 'Dump events to console',
|
||||
type: 'checkbox',
|
||||
},
|
||||
{
|
||||
name: 'neverUseWorker',
|
||||
title: 'Never use Worker for connection',
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include utility.js
|
||||
|
||||
const MamiWatcher = function() {
|
||||
const MamiWatcher = function(initCall) {
|
||||
if(typeof initCall !== 'boolean')
|
||||
initCall = true;
|
||||
|
||||
const handlers = [];
|
||||
|
||||
const watch = (handler, ...args) => {
|
||||
|
@ -10,8 +13,11 @@ const MamiWatcher = function() {
|
|||
throw 'handler already registered';
|
||||
|
||||
handlers.push(handler);
|
||||
args.push(true);
|
||||
handler(...args);
|
||||
|
||||
if(initCall) {
|
||||
args.push(true);
|
||||
handler(...args);
|
||||
}
|
||||
};
|
||||
|
||||
const unwatch = handler => {
|
||||
|
@ -22,7 +28,8 @@ const MamiWatcher = function() {
|
|||
watch: watch,
|
||||
unwatch: unwatch,
|
||||
call: (...args) => {
|
||||
args.push(false);
|
||||
if(initCall)
|
||||
args.push(false);
|
||||
|
||||
for(const handler of handlers)
|
||||
handler(...args);
|
||||
|
@ -30,7 +37,10 @@ const MamiWatcher = function() {
|
|||
};
|
||||
};
|
||||
|
||||
const MamiWatchers = function() {
|
||||
const MamiWatchers = function(initCall) {
|
||||
if(typeof initCall !== 'boolean')
|
||||
initCall = true;
|
||||
|
||||
const watchers = new Map;
|
||||
|
||||
const getWatcher = name => {
|
||||
|
@ -53,10 +63,10 @@ const MamiWatchers = function() {
|
|||
unwatch: unwatch,
|
||||
define: names => {
|
||||
if(typeof names === 'string')
|
||||
watchers.set(names, new MamiWatcher);
|
||||
watchers.set(names, new MamiWatcher(initCall));
|
||||
else if(Array.isArray(names))
|
||||
for(const name of names)
|
||||
watchers.set(name, new MamiWatcher);
|
||||
watchers.set(name, new MamiWatcher(initCall));
|
||||
else
|
||||
throw 'names must be an array of names or a single name';
|
||||
},
|
||||
|
|
|
@ -91,10 +91,15 @@ const UmiWebSocket = function(server, message, useWorker) {
|
|||
return intervals;
|
||||
};
|
||||
sendInterval = function(text, interval) {
|
||||
intervals.push(setInterval(function() {
|
||||
if(websocket)
|
||||
const intervalId = setInterval(function() {
|
||||
if(websocket) {
|
||||
websocket.send(text);
|
||||
}, interval));
|
||||
message({ act: 'ws:call_interval', id: intervalId });
|
||||
}
|
||||
}, interval);
|
||||
|
||||
intervals.push(intervalId);
|
||||
message({ act: 'ws:create_interval', id: intervalId });
|
||||
};
|
||||
clearIntervals = function() {
|
||||
for(let i = 0; i < intervals.length; ++i)
|
||||
|
|
|
@ -75,10 +75,15 @@ addEventListener('message', function(ev) {
|
|||
|
||||
case 'ws:send_interval':
|
||||
(function(interval, text) {
|
||||
intervals.push(setInterval(function() {
|
||||
if(websocket)
|
||||
const intervalId = setInterval(function() {
|
||||
if(websocket) {
|
||||
websocket.send(text);
|
||||
}, interval));
|
||||
postMessage({ act: 'ws:call_interval', id: intervalId });
|
||||
}
|
||||
}, interval);
|
||||
|
||||
intervals.push(intervalId);
|
||||
postMessage({ act: 'ws:create_interval', id: intervalId });
|
||||
})(ev.data.interval, ev.data.text);
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue