-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
164 lines (136 loc) · 5.02 KB
/
index.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
import Blastream from './src/Blastream';
const fs = require('fs');
let config = JSON.parse(fs.readFileSync('config.json'));
class Samples {
constructor() {
this.blastream = new Blastream(config.PUBLIC_KEY, config.PRIVATE_KEY);
if(config.URL)
this.blastream.setRequestUrl(config.URL);
this.blastream.setTimeout(6000);
}
async createOrGetChannel() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let iframe = channel.getIframe(800, 600, {
username: 'admin_user'
});
console.log(iframe);
}
async createCollaborator() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let colaborator = await channel.createOrGetCollaborator('alan', 'animator'); //The collaborator username is unique for a channel
let iframe = colaborator.getIframe(800, 600);
console.log('iframe', iframe);
}
async createParticipant() {
let channel = await this.blastream.createOrGetParticipant('my-channel', 'my-part');
let iframe = channel.getIframe(800, 600);
console.log('iframe', iframe);
}
async getReplays() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let list = await channel.getReplays();
console.log('replays', list);
}
async registerHook() {
let res = await this.blastream.registerHook('https://http.jay.invaders.stream/hook_from_blastream.php');
console.log('res', res);
}
async updateSubscription() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let res = await channel.updateSubscription('pro2', 'hourly');
console.log('res', res);
}
async setAccessRule() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let res = await channel.setAccessRule('PRIVATE', {
knock: 1 //can be knock or password, if you set password you have to put the password value : password => 'my-password'
});
console.log('res', res);
}
async updateSettings() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let res = await channel.updateSettings({
autojoin: 1
});
console.log('res', res);
}
async updateCollaborator() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let colaborator = await channel.createOrGetCollaborator('Collaborator Username', 'moderator');
let res = await colaborator.update('New username', 'animator');
console.log('res', res);
}
async updateCustom() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let upload = await channel.uploadPic('logo.png');
let res = await channel.setCustom({
colors: [
"#ff0000",
"#ff0000",
"#ff0000",
"#ff0000"
],
js: 'alert(\'ok\')',
css: '',
logo: upload.file
});
console.log('res', res)
}
async updateScene() {
let channel = await this.blastream.createOrGetChannel('my-channel');
let scenes = await channel.getScenes();
//can be 'overlay', 'logo' or 'background'
let upload = await channel.uploadScenePic('overlay', 'logo.png');
for(var i in scenes) {
let scene = scenes[i];
if(scene.isDefault()) {
let res = await scene.update({
overlay: {
src: upload['file'],
play: true
},
background: {
color: '#ff0000'
}
});
console.log('res', res);
}
}
}
async createReadme() {
let props = Object.getOwnPropertyNames(Samples.prototype);
let script = fs.readFileSync('index.js', 'utf8');
let finalScripts = {};
for(var i in props) {
let fct = props[i];
let fctNext = props[(parseInt(i) + 1)];
console.log('fct', fct, fctNext)
if(fct == 'createReadme' || fct == 'constructor')
continue;
finalScripts[fct] = script.split('async ' + fct + '() {').pop().split('async ' + fctNext + '()').shift();
for(var j=0; j<3; j++)
finalScripts[fct] = finalScripts[fct].substring(0, finalScripts[fct].lastIndexOf("\n"));
finalScripts[fct] = finalScripts[fct].substring(finalScripts[fct].indexOf("\n") + 1);
finalScripts[fct] = finalScripts[fct].replaceAll('this.blastream', 'blastream');
}
//let samples = '```js' + "\n" + finalScripts.join('```' + "\n" + '```js' + "\n") + '```';
let samples = [];
for(var i in finalScripts) {
samples.push('#### ' + i);
samples.push('```js')
samples.push(finalScripts[i])
samples.push('```')
samples.push("\n");
}
let readme = fs.readFileSync('README_TPL.md', 'utf8');
readme = readme.replace('[SAMPLES]', samples.join("\n"));
fs.writeFileSync('README.md', readme, 'utf8');
}
}
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
console.log(process.argv[2]);
let samples = new Samples();
samples[process.argv[2]]();