Repository navigation
Expand file tree
/
Copy pathrecorder.js
More file actions
108 lines (98 loc) · 2.44 KB
/
Copy pathrecorder.js
File metadata and controls
108 lines (98 loc) · 2.44 KB
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
import TogetherJS from "./core/togetherjs.js";
import $ from "./dom/dom.js";
import util from "./core/util.js";
import channels from "./core/channels.js";
var recorder = util.Module("recorder");
var channel = null;
var clientId = "recorder";
function display(el) {
el = $(el);
var toggles = el.attr("data-toggles");
if (toggles) {
$(toggles).hide();
}
el.show();
}
recorder.start = function (options) {
$(function () {
$("#record").css({height: $(window).height() - 50});
$("#restart").click(function () {
location.reload();
});
$("#select").click(function () {
$("#record").select();
});
recorder.activate(options);
});
};
recorder.activate = function (options) {
var match;
recorder.shareId = TogetherJS.startup._joinShareId;
if (! recorder.shareId) {
match = /\&togetherjs=([^&]+)/.exec(location.hash);
if (! match) {
display("#no-session-id");
return;
}
recorder.shareId = match[1];
}
var hubBase = options.defaultHubBase;
match = /\&hubBase=([^&]+)/.exec(location.hash);
if (match) {
hubBase = match[1];
}
hubBase = hubBase.replace(/\/*$/, "");
var url = hubBase + "/hub/" + recorder.shareId;
channel = new channels.WebSocketChannel(url);
channel.onmessage = function (msg) {
if (msg.type == "hello-back") {
display("#connected");
}
if (msg.type == "hello") {
sendHello(true);
}
if (msg.type == "get-logs") {
sendLogs(msg);
return;
}
recorder.logMessage(msg);
};
sendHello(false);
};
function sendHello(helloBack) {
var msg = {
type: helloBack ? "hello-back" : "hello",
name: "Recorder 'bot",
// FIXME: replace with robot:
color: "#888888",
rtcSupported: false,
clientId: clientId,
url: "about:blank"
};
channel.send(msg);
}
function sendLogs(req) {
var msg = {
type: "logs",
clientId: clientId,
logs: $("#record").val(),
request: req
};
channel.send(msg);
}
recorder.logMessage = function (msg) {
msg.date = Date.now();
msg = JSON.stringify(msg);
var $record = $("#record");
$record.val($record.val() + msg + "\n\n");
};
$(window).on("pagehide", function () {
channel.send({
type: "bye",
clientId: clientId
});
});
export default recorder;