This repository has been archived by the owner on Nov 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
conclave.js
114 lines (100 loc) · 3.68 KB
/
conclave.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
import Peer from 'peerjs_fork_firefox40';
import SimpleMDE from 'simplemde';
import $ from 'jquery';
import Controller from './build/controller';
class Conclave {
constructor(options) {
const defaults = {
peerId: null,
peer: null,
shareLink: true,
icons: true,
video: true,
changeUrl: true,
errorMessage:true,
showPeers: true,
peersLeft: true,
placeholder: 'Share the link to invite collaborators to your room'
};
options = Object.assign(defaults, options);
this.generateConclaveEditor(options);
this.initializeController(options);
}
generateConclaveEditor(options) {
const editorHTMLStr = `<div class="text-wrapper">
<div id="peerId">
<p class='no-margin-bottom'>Peers:</p>
</div>
<div class="editor">
<div class="header">
<div class="peer-toggle show"></div>
<p class='share-link hide'>
<a id='myLink' target="_blank">Public Share Link</a>
<span id="myLinkInput" class="disappear aside"></span>
<span class="copy-container" data-tooltip="Copy to Clipboard"></span>
<span class="copy-status">Copied!</span>
</p>
<div class="buttons">
<button id="download" type="button">Save</button>
<label id="upload" for="file">Upload</label>
<input id="file" type="file" accept=".txt, .js, .rb, .md, .pug, .py"/>
</div>
</div>
<div class="textarea">
<textarea row="10" col="20"></textarea>
</div>
</div>
</div>
<div class="video-modal hide">
<div class="video-bar"></div>
<div class="video-container">
<video></video>
</div>
</div>`;
const $editor = $(editorHTMLStr);
$('#conclave').append($editor).addClass('hide');
if (options.shareLink) $('.share-link').removeClass('hide');
if (!options.peersLeft) $('.text-wrapper').addClass('reverse');
if (!options.showPeers) $('#peerId').addClass('disappear');
}
initializeController(options) {
const peerOptions = [{
host: 'conclavepeerjs.herokuapp.com',
port: 443,
secure: true,
config: {'iceServers':
[
{ url: 'stun:stun1.l.google.com:19302' },
{ url: 'turn:numb.viagenie.ca',
credential: 'conclave-rulez',
username: '[email protected]'
}
]
},
debug: 1
}];
if (options.peerId) peerOptions.unshift(options.peerId);
const peer = options.peer || new Peer(...peerOptions);
const locale = !!location.origin.match(/file:\/\//) ? location.href.split('?')[0] : location.origin;
this.controller = new Controller(
(location.search.slice(1) || '0'),
locale,
peer,
new SimpleMDE({
placeholder: options.placeholder,
spellChecker: false,
toolbar: false,
autofocus: false,
indentWithTabs: true,
status: false,
tabSize: 4,
indentUnit: 4,
lineWrapping: false,
shortCuts: []
}),
options
);
this.controller.init();
}
}
export default Conclave;