This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
forked from kyroskoh/KappaGen
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
582 lines (536 loc) · 21.4 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
var CORSProvider = "//cbenni.com/cors-proxy/";
//var CORSProvider = "//127.0.0.1:9003/";
function log(msg) {
console.log(msg);
}
function parseQueryParams(url) {
var res = {};
url.replace(/([^?=&]+)(?:=([^&]*))?/g,function(m, k, v){res[decodeURIComponent(k)] = v?decodeURIComponent(v):true; });
return res;
}
function guid() {
function s4() { // generates 4 random lowercase alphanumeric characters
return Math.floor((1 + Math.random()) * 1679616) // 1679616 = 36^4 = 1000 in base 36
.toString(36)
.substring(1);
}
var res = Math.floor(10 * Math.random())+""; // first character is a digit and denotes the cluster we connect to.
for(var i=0;i<6;++i) res += s4();
return res;
}
// startsWith polyfill
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position){
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
// global handleMessage for debug
_handleMessage = null;
alertify.logPosition("top right");
var app = angular.module("app",["firebase"]);
app.controller("AppCtrl",function($scope, $firebaseObject, $sce, $window, $http){
$scope.loaded = false;
var params = parseQueryParams(window.location.search);
var channel = params.channel
if(!channel) {
window.location.href = window.location.origin+window.location.pathname+"settings";
return;
}
if(params.background) document.body.style.background = params.background;
channel = channel.toLowerCase();
var userAccounts = {};
var lastSent = {};
var animatedemotes = [];
function addUserAccount(user, time) {
var d = Date.now();
userAccounts[user] = Math.max(0,(lastSent[user]-d+userAccounts[user]) || 0)+time;
lastSent[user] = d;
}
function getUserAccount(user) {
return Math.max(0,(lastSent[user]-Date.now()+userAccounts[user]) || 0);
}
var animationkeys = [];
function drawEmote(user, emote) {
// check rate limit and if we are allowed to use this emote
if($scope.settings.chatemotes && getUserAccount(user)<1000 && (!$scope.settings.channelonly || emote.channel)) {
console.log("User account for "+user+": "+getUserAccount(user))
var ratelimit = 1000*$scope.settings.limit;
if(ratelimit != 0)addUserAccount(user, ratelimit+10); // +10 to account for execution time, preventing limit violations.
var animationparams = initializers[$scope.settings.animation](ctx, $scope.settings);
var img = new ImageEx(emote.url, emote.type == "gif" || emote.type == "bits-animated");
img.onload = function() {
animatedemotes.push({url: emote.url, animation: animationparams, start: performance.now(), img: this, w: this.width, h: this.height, type: emote.type});
}
}
}
var canvas = document.getElementById("emoteScreen");
var ctx = canvas.getContext('2d');
function setSetting(key, val) {
if(defaults[key] === undefined) {
alertify.error("Invalid setting "+key);
return;
} else {
var type = typeof(defaults[key]);
if(type === "number") {
val = parseFloat(val);
if(isNaN(val)) {
alertify.error("Invalid value '"+val+"' for integer setting "+key);
return;
}
} else if(type === "boolean") {
if(val === "true" || val === "on" || val === true) val = true;
else if(val === "false" || val === "off" || val === false) val = false;
else {
alertify.error("Invalid value '"+val+"' for boolean setting "+key);
return;
}
} else if(type === "object") {
val = JSON.parse(val);
}
}
$scope.$apply(function(){$scope.settings[key] = val});
return val;
}
var rafStart = performance.now();
function animStep(t){
ctx.clearRect(0, 0, canvas.width, canvas.height);
var f = t - rafStart;
for(var i=animatedemotes.length-1;i>=0;--i) {
var emote = animatedemotes[i];
var speedmult = 1/(1000.0*emote.animation.duration);
var age = (t-emote.start)*speedmult;
if(age >= 0) {
animations[emote.animation.type](ctx, $scope.settings, f*speedmult, age, emote);
if(age > 1) {
animatedemotes.splice(i,1);
if(emote.oncomplete) emote.oncomplete.call(emote);
}
}
}
rafStart = t;
window.requestAnimationFrame(animStep);
}
function emotesplosion(allowedEmotes, emoteCount) {
// allowedEmotes can be a list of emotes (in which case we dont change it)
// of a string, for example "ffz, bttv"
if(typeof(allowedEmotes) === "string") {
var types = allowedEmotes.toLowerCase().match(/\w+/g);
allowedEmotes = [];
for(var j=0;j<types.length;++j) {
if("subscribers".startsWith(types[j])) for(var i=0;i<subEmotes.sub.length;++i) allowedEmotes.push(subEmotes.sub[i]);
if("bttv" == types[j]) for(var i=0;i<subEmotes.bttv.length;++i) allowedEmotes.push(subEmotes.bttv[i]);
if("bttv" == types[j] && $scope.settings.gif || "gif" == types[j]) for(var i=0;i<subEmotes.gif.length;++i) allowedEmotes.push(subEmotes.gif[i]);
if("ffz" == types[j]) for(var i=0;i<subEmotes.ffz.length;++i) allowedEmotes.push(subEmotes.ffz[i]);
}
// or undefined
} else {
if(allowedEmotes === undefined) {
allowedEmotes = [];
}
}
// if no emotes have been added so far, we try sub emotes
if(allowedEmotes.length == 0) {
for(var i=0;i<subEmotes.sub.length;++i) allowedEmotes.push(subEmotes.sub[i]);
}
// still none (not partnered)? FFZ+BTTV emotes if allowed by the settings
if(allowedEmotes.length == 0) {
if($scope.settings.bttv) for(var i=0;i<subEmotes.bttv.length;++i) allowedEmotes.push(subEmotes.bttv[i]);
if($scope.settings.bttv && $scope.settings.gif) for(var i=0;i<subEmotes.gif.length;++i) allowedEmotes.push(subEmotes.gif[i]);
if($scope.settings.ffz) for(var i=0;i<subEmotes.ffz.length;++i) allowedEmotes.push(subEmotes.ffz[i]);
}
// still none (not partnered, no FFZ or BTTV emotes), add global emotes (Those exist)
if(allowedEmotes.length == 0) {
allowedEmotes = globalEmotes;
}
var num = emoteCount || $scope.settings.emotesplosion;
console.log("Emotesplosion with "+num+" emotes");
emotesplosions[$scope.settings.emotesplosiontype](ctx, $scope.settings, allowedEmotes, animatedemotes, num);
}
function handleCommand(w,data) {
split = data.text.trim().toLowerCase().split(" ");
if(split.length >= 2 && (data.nick === channel || data.nick === "cbenni" || data.nick === "onslaught" || $scope.settings.mods && data.tags.mod === "1")) {
if(split[1] == "emotesplosiontest") {
if(split.length >= 3) {
emotesplosion(split.slice(2).join(" "));
} else {
handleMessage(null, ":twitchnotify!twitchnotify@twitchnotify.tmi.twitch.tv PRIVMSG #"+channel+" :test_user just subscribed!");
}
} else if(split[1] == "customsplosion") {
var allowedEmotes = [];
for(var i=0;i<data.emotes.length;i++) {
var emote = data.emotes[i];
var imgPath = "//static-cdn.jtvnw.net/emoticons/v1/"+emote.id+"/3.0";
allowedEmotes.push({"url":imgPath});
}
var usplit = data.text.split(" ");
for(var i=2;i<usplit.length;++i) {
var emote = extraEmotes[usplit[i]];
if(emote !== undefined && $scope.settings[emote.type] && (emote.type != "gif" || $scope.settings.bttv)) {
allowedEmotes.push(emote);
}
}
emotesplosion(allowedEmotes);
} else if(split.length == 3) {
var oldval = $scope.settings[split[1]];
var res = setSetting(split[1],split[2]);
if(res !== undefined && oldval !== res) alertify.success(data.nick+" set setting "+split[1]+" from "+oldval+" to "+res);
}
}
}
function handleMessage(w,data) {
var parsedmessage = parseIRCMessage(data);
log(data);
console.log(""+data);
if(parsedmessage[STATE_COMMAND] == "PING") w.send('PONG');
else if (parsedmessage[STATE_COMMAND]=="PRIVMSG") {
var extmsg = getPrivmsgInfo(parsedmessage);
if(extmsg.text.toLowerCase().startsWith("!kappagen")) {
handleCommand(w,extmsg);
return;
}
else if($scope.settings.subonly && extmsg.tags && !gw_subs[extmsg.nick] && extmsg.tags.subscriber !== "1" && extmsg.tags.mod !== "1" && extmsg.nick != channel) return; // do nothing for plebs when sub only mode is active.
else if(extmsg.nick === "twitchnotify") {
if(getEmotesplosionTriggers("s"))emotesplosion();
return;
} else if($scope.settings.once) {
for(var i=0;i<extmsg.emoteids.length;i++) {
var emoteid = extmsg.emoteids[i];
var imgPath = "//static-cdn.jtvnw.net/emoticons/v1/"+emoteid+"/3.0";
// use the saved sub emotes if present.
drawEmote(extmsg.nick, id2SubEmote[emoteid] || {url: imgPath, type: "twitch", channel: false});
}
} else {
for(var i=0;i<extmsg.emotes.length;i++) {
var emote = extmsg.emotes[i];
log("drawing emote with id "+emote.id);
var imgPath = "//static-cdn.jtvnw.net/emoticons/v1/"+emote.id+"/3.0";
// use the saved sub emotes if present.
drawEmote(extmsg.nick, id2SubEmote[emote.id] || {url: imgPath, type: "twitch", channel: false});
}
}
var foundemotes = {};
var words = parsedmessage[STATE_TRAILING].trim().split(" ")
for(var i=0;i<words.length;++i) {
var emote = extraEmotes[words[i]];
if(emote !== undefined && $scope.settings[emote.type] && (emote.type != "gif" || $scope.settings.bttv)) {
if(!$scope.settings.once || !foundemotes[emote]) {
drawEmote(extmsg.nick, emote);
foundemotes[emote] = true;
}
}
}
// Find bits... fml
var foundbits = {};
var allbits = [];
// check if bits are enabled and this message contains any bits
if($scope.settings.bits && parsedmessage[STATE_V3] && parseInt(parsedmessage[STATE_V3].bits) > 0) {
// get the total, just double checking for exploits
var total = parseInt(parsedmessage[STATE_V3].bits);
// iterate over the words of the message
for(var i=0;i<words.length;++i) {
var word = words[i];
// for each word, iterate over the different cheer types we have
for(var j=0;j<bitEmotes.length;++j) {
var bitEmote = bitEmotes[j];
var match = bitEmote.regexp.exec(word);
if(match) {
var prefix = parseInt(match[1]);
var bits = parseInt(match[2]);
if(total >= bits) {
// if enough bits remain, find the correct tier to use.
for(var k=bitEmote.tiers.length-1;k>=0;--k) {
var tier = bitEmote.tiers[k];
if(tier.min_bits <= bits) {
var state = $scope.settings.staticbits?"static":bitEmote.state;
var url = tier.images[bitEmote.background][state][bitEmote.scale];
var emote = {url: CORSProvider + url, type: "bits-"+state, channel: false};
for(var l=0;l<bits;++l) {
allbits.push(emote);
}
total -= bits;
// draw cheermotes if cheersplosions are disabled
if((!foundbits[url] || !$scope.settings.once) && !$scope.settings.cheersplosions) {
drawEmote(extmsg.nick, emote);
}
foundbits[url] = (foundbits[url] || 0)+bits;
break; // were done here.
}
}
}
break; // next word
}
}
}
// show cheersplosions if enabled
if($scope.settings.cheersplosions && allbits.length > 0) {
// calculate the number of emotes to explode
// The formula was found in parts by trial and error, but is mostly just a log with a highly stretched linear part.
var x = allbits.length;
var num = Math.ceil((1000*Math.log(1000+x)-1000*Math.log(1001)+1));
console.log("Cheersplosion with "+num+" cheermotes");
emotesplosion(allbits, num);
}
}
}
else if (parsedmessage[STATE_COMMAND] == "USERNOTICE") {
if(parsedmessage[STATE_V3]
&& parsedmessage[STATE_V3]["msg-id"] == "resub"
&& getEmotesplosionTriggers("s")) {
emotesplosion();
}
}
}
window._handleMessage = handleMessage;
extraEmotes = {};
function loadFFZ(response) {
var sets = Object.keys(response.data.sets);
for(var i=0;i<sets.length;++i){
var set = response.data.sets[sets[i]];
for(var j=0;j<set.emoticons.length;++j) {
var x = set.emoticons[j].urls;
var emote = {"url": (x[4] || x[2] || x[1]), "type": "ffz", "channel": false};
// non-channel emotes have a lower precedence
if(!extraEmotes[set.emoticons[j].name]) extraEmotes[set.emoticons[j].name] = emote;
}
}
}
function loadFFZChannel(response) {
var sets = Object.keys(response.data.sets);
for(var i=0;i<sets.length;++i){
var set = response.data.sets[sets[i]];
for(var j=0;j<set.emoticons.length;++j) {
var x = set.emoticons[j].urls;
var emote = {"url": (x[4] || x[2] || x[1]), "type": "ffz", "channel": true};
extraEmotes[set.emoticons[j].name] = emote;
subEmotes["ffz"].push(emote);
}
}
}
function loadBTTV(response) {
for(var i=0;i<response.data.emotes.length;++i){
var emote = response.data.emotes[i];
if(emote.imageType == "gif") {
var emote = {"url": CORSProvider + "https:" + response.data.urlTemplate.replace("{{id}}",emote.id).replace("{{image}}","3x"), type: "gif", code: emote.code, "channel": false};
} else {
var emote = {"url": response.data.urlTemplate.replace("{{id}}",emote.id).replace("{{image}}","3x"), type: "bttv", code: emote.code, "channel": false};
}
// non-channel emotes have a lower precedence
if(!extraEmotes[emote.code]) extraEmotes[emote.code] = emote;
}
}
function loadBTTVChannel(response) {
for(var i=0;i<response.data.emotes.length;++i){
var emote = response.data.emotes[i];
if(emote.imageType == "gif") {
var emote = {"url": CORSProvider + "https:" + response.data.urlTemplate.replace("{{id}}",emote.id).replace("{{image}}","3x"), type: "gif", code: emote.code, "channel": true};
} else {
var emote = {"url": response.data.urlTemplate.replace("{{id}}",emote.id).replace("{{image}}","3x"), type: "bttv", code: emote.code, "channel": true};
}
extraEmotes[emote.code] = emote;
subEmotes[emote.type].push(emote);
}
}
var globalEmotes = [];
function loadGlobalEmotes(response) {
var set = response.data.emoticon_sets[0];
for(var i=0;i<set.length;++i) {
var emote = set[i];
globalEmotes.push({"url":"//static-cdn.jtvnw.net/emoticons/v1/"+emote.id+"/3.0", type: emote.imageType == "global", "channel": false});
}
}
var bitEmotes = [];
function loadBits(response) {
bitEmotes = [];
for(var i=0;i<response.data.actions.length;++i) {
var action = response.data.actions[i];
var scale = action.scales[action.scales.length-1];
var state = "animated";
var background = "light";
if(action.states && action.states.indexOf(state) < 0) state = action.states[0];
if(action.backgrounds && action.backgrounds.indexOf(background) < 0) background = action.backgrounds[0];
bitEmotes.push({"regexp":new RegExp("^("+action.prefix+")(\\d+)$","i"), tiers: action.tiers, prefix: action.prefix, scale: scale, state: state, background: background});
}
}
var getEmotesplosionTriggers = function(type) {
if(!$scope.settings.emotesplosions) return false;
var triggers = $scope.settings.emotesplosiontriggers.split("+");
for(var i=0;i<triggers.length;++i){
if(triggers[i][0] === type) return true;
}
return false;
}
// follows
var lastfollowers = undefined;
function updateFollows()
{
if(getEmotesplosionTriggers("f")) {
$http.jsonp("//api.twitch.tv/kraken/channels/"+channel+"/follows?limit=1&callback=JSON_CALLBACK&client_id="+twitchAuth.clientId).then(function (response) {
if(response.data.follows.length>0)
{
var newestfollower = response.data.follows[0].user.name;
if(lastfollowers === undefined) lastfollowers=[newestfollower];
if(lastfollowers.indexOf(newestfollower)<0)
{
emotesplosion();
lastfollowers.push(newestfollower)
}
}
else if(lastfollowers === undefined) lastfollowers = [];
});
}
}
var settingsLoaded = function() {
updateFollows(channel);
setInterval(updateFollows,10000);
// do gamewisp stuff (load list of subs, connect singularity)
gamewispConnect();
$http.get("//api.betterttv.net/2/channels/"+channel).then(loadBTTVChannel);
$http.get("//api.betterttv.net/2/emotes").then(loadBTTV);
}
// load API data
$http.get("//api.frankerfacez.com/v1/room/"+channel).then(loadFFZChannel);
if(channel !== "cbenni") {
$http.get("//api.frankerfacez.com/v1/room/cbenni").then(loadFFZ);
}
$http.get("//api.frankerfacez.com/v1/set/global").then(loadFFZ);
$http.jsonp("//api.twitch.tv/kraken/chat/emoticon_images?emotesets=0&client_id="+twitchAuth.clientId+"&callback=JSON_CALLBACK").then(loadGlobalEmotes);
$http.jsonp("https://api.twitch.tv/kraken/bits/actions?client_id="+twitchAuth.clientId+"&callback=JSON_CALLBACK&api_version=5").then(loadBits);
var id2SubEmote = {};
var subEmotes = {"sub":[], "ffz":[], "bttv":[], "gif": []};
$http.jsonp("//api.twitch.tv/api/channels/"+channel+"/product?callback=JSON_CALLBACK&client_id="+twitchAuth.clientId).then(function( response ) {
var emotes = response.data.emoticons;
for(var i=0;i<emotes.length;++i) {
var emote = emotes[i];
if(emote.state === "active") {
var emoteObj = {type:"sub",url:"//static-cdn.jtvnw.net/emoticons/v1/"+emote.id+"/3.0", "channel": true};
id2SubEmote[emote.id] = emoteObj;
subEmotes.sub.push(emoteObj);
}
}
});
var w=new WebSocket('wss://irc-ws.chat.twitch.tv');
w.onmessage=function(e){
var lines = e.data.split("\r\n");
for(var i=0;i<lines.length;++i){
var line = lines[i];
if(line.length) handleMessage(w,line);
}
}
w.onopen=function(e) {
w.send('CAP REQ :twitch.tv/tags twitch.tv/commands');
w.send('NICK justinfan1');
w.send('JOIN #'+channel);
}
// initialize rendering
window.requestAnimationFrame(animStep);
window.addEventListener('resize', resizeCanvas, false);
function resizeCanvas() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
resizeCanvas();
var singularity = null;
var lastGWToken = null;
var gw_subs = {};
// singularity: socket.io connection to gamewisp
var gamewispConnect = function() {
if(!$scope.settings) return;
var gw = $scope.settings.gamewisp;
if(gw) {
if(gw.token != lastGWToken) {
if(singularity) {
singularity.disconnect();
singularity = null;
}
// get gamewisp subs
$http.jsonp(gamewispAuth.subsUrl+"?token="+gw.token+"&callback=JSON_CALLBACK").then(function(subs) {
gw_subs = {};
for(var i=0;i<subs.data.length;++i) {
var sub = subs.data[i];
var status = sub.status;
var nick = sub.user.data.username.toLowerCase();
if(status == "active" || status == "trial") {
gw_subs[nick] = true;
}
}
}, function(error) {
console.error(error);
});
lastGWToken = gw.token;
console.log("Connecting to gamewisp channel");
}
if(!singularity) {
singularity = io("https://singularity.gamewisp.com");
_sing = singularity;
singularity.on("connect", function(){
console.log("Singularity connected!");
setTimeout(function() {
singularity.emit("authentication", { key: gamewispAuth.clientId, access_token: gw.token });
}, 10);
});
var session = null;
singularity.on("authenticated", function(data){
session = data.result.session;
console.log("Singularity authenticated!");
singularity.emit("channel-connect", { access_token: $scope.settings.gamewisp.token });
//singularity.emit("channel-subscribers", { status: "all", benefits: true, session: session, access_token: gw.token });
});
singularity.on("app-channel-connected", function(data){
console.log("Connected to gamewisp channel!");
});
singularity.on("subscriber-new", function(data) {
if(getEmotesplosionTriggers("s")) emotesplosion();
var nick = JSON.parse(data).data.usernames.twitch;
if(nick) {
gw_subs[nick] = true;
}
});
singularity.on("subscriber-anniversary", function(data) {
if(getEmotesplosionTriggers("s")) emotesplosion();
});
singularity.on("app-channel-subscribers", function(data) {
console.log(data);
});
}
} else {
lastGWToken = null;
if(singularity) {
singularity.disconnect();
singularity = null;
}
}
}
$scope.$watch("settings.gamewisp.token", gamewispConnect);
// load settings
if(params.cuid) {
var cluster = params.cuid.substring(0,1);
console.log("//kappagen-"+cluster+".firebaseio.com/"+params.cuid);
var ref = new Firebase("//kappagen-"+cluster+".firebaseio.com/"+params.cuid);
var syncObject = $firebaseObject(ref);
syncObject.$bindTo($scope, "settings");
syncObject.$loaded().then(function(data) {
if(data.v === undefined) {
$scope.settings = angular.copy(defaults);
}
$scope.loaded = true;
var defaultkeys = Object.keys(defaults);
for(var i=0;i<defaultkeys.length;++i) {
var key = defaultkeys[i];
if($scope.settings[key] === undefined) $scope.settings[key] = defaults[key];
}
settingsLoaded();
});
} else {
$scope.settings = angular.copy(defaults);
var paramkeys = Object.keys(params);
for(var i=0;i<paramkeys.length;++i) {
var key = paramkeys[i];
var val = params[key];
if(key === "channel") continue;
if(val[0] == "{") $scope.settings[key] = JSON.parse(val);
else $scope.settings[key] = val;
}
settingsLoaded();
}
});