-
Notifications
You must be signed in to change notification settings - Fork 4
/
background.js
79 lines (67 loc) · 1.62 KB
/
background.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
var tabs = {};
chrome.extension.onConnect.addListener(function(port)
{
port.onMessage.addListener(function(msg)
{
var curTab = msg.tabid;
if (!curTab)
{
return;
}
if (curTab < 0)
{
return;
}
if (!tabs[curTab])
{
tabs[curTab] = {};
tabs[curTab].panning = 0;
tabs[curTab].enabled = 0;
tabs[curTab].panNode;
tabs[curTab].context;
tabs[curTab].source;
}
if (msg.type == 'set_request')
{
tabs[curTab].panning = msg.value;
if (tabs[curTab].enabled == 0)
{
chrome.tabCapture.capture(
{
audio: true,
video: false
}, function (stream)
{
tabs[curTab].context = new AudioContext();
tabs[curTab].source = tabs[curTab].context.createMediaStreamSource(stream);
tabs[curTab].panNode = tabs[curTab].context.createStereoPanner();
tabs[curTab].panNode.pan.setValueAtTime(tabs[curTab].panning, tabs[curTab].context.currentTime);
tabs[curTab].source.connect(tabs[curTab].panNode).connect(tabs[curTab].context.destination);
});
tabs[curTab].enabled = 1;
}
else
{
tabs[curTab].panNode.pan.setValueAtTime(tabs[curTab].panning, tabs[curTab].context.currentTime);
}
}
else if (msg.type == 'update_request')
{
var msgdata = {
'type':'update_response',
'value': tabs[curTab].panning,
'tabid': curTab
};
port.postMessage(msgdata);
}
else if (mst.type == 'resetall_request')
{
}
});
});
chrome.tabs.onRemoved.addListener(function(tabid, removed) {
if (tabs[tabid])
{
delete tabs[tabid];
}
});