瀏覽代碼

Add Recorder controller.

j8
yanas 9 年之前
父節點
當前提交
99d9b16c13
共有 1 個檔案被更改,包括 101 行新增0 行删除
  1. 101
    0
      modules/recorder/Recorder.js

+ 101
- 0
modules/recorder/Recorder.js 查看文件

@@ -0,0 +1,101 @@
1
+/* global config, APP */
2
+/*
3
+ * Copyright @ 2015 Atlassian Pty Ltd
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ *     http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+import VideoLayout from '../UI/videolayout/VideoLayout';
18
+import Feedback from '../UI/Feedback.js';
19
+import Toolbar from '../UI/toolbars/Toolbar';
20
+import BottomToolbar from '../UI/toolbars/BottomToolbar';
21
+
22
+const _RECORDER_CUSTOM_ROLE = "recorder-role";
23
+
24
+class Recorder {
25
+    /**
26
+     * Initializes a new {Recorder} instance.
27
+     *
28
+     * @param conference the {conference} which is to transport
29
+     * {Recorder}-related information between participants
30
+     * @param UI the {UI} which is the source (model/state) to be sent to
31
+     * remote participants if the local participant is the moderator or the
32
+     * destination (model/state) to receive from the remote moderator if the
33
+     * local participant is not the moderator
34
+     */
35
+    constructor (conference, UI) {
36
+        var self = this;
37
+        this._conference = conference;
38
+        this._UI = UI;
39
+
40
+        // If I am a recorder then I publish my recorder custom role to notify
41
+        // everyone.
42
+        if (config.iAmRecorder) {
43
+            VideoLayout.enableDeviceAvailabilityIcons(conference.localId, true);
44
+            this._publishMyRecorderRole();
45
+            Feedback.enableFeedback(false);
46
+            Toolbar.enable(false);
47
+            BottomToolbar.enable(false);
48
+        }
49
+
50
+        // Listen to "CUSTOM_ROLE" commands.
51
+        this._conference.commands.addCommandListener(
52
+            this._conference.commands.defaults.CUSTOM_ROLE,
53
+            this._onCustomRoleCommand.bind(this));
54
+    }
55
+
56
+    /**
57
+     * Publish the recorder custom role.
58
+     * @private
59
+     */
60
+    _publishMyRecorderRole () {
61
+        var conference = this._conference;
62
+
63
+        var commands = conference.commands;
64
+
65
+        commands.removeCommand(commands.defaults.CUSTOM_ROLE);
66
+        var self = this;
67
+        commands.sendCommandOnce(
68
+            commands.defaults.CUSTOM_ROLE,
69
+            {
70
+                attributes: {
71
+                    recorderRole: true
72
+                }
73
+            });
74
+    }
75
+
76
+    /**
77
+     * Notifies this instance about a &qout;Custom Role&qout; command (delivered
78
+     * by the Command(s) API of {this._conference}).
79
+     *
80
+     * @param attributes the attributes {Object} carried by the command
81
+     * @param id the identifier of the participant who issued the command. A
82
+     * notable idiosyncrasy of the Command(s) API to be mindful of here is that
83
+     * the command may be issued by the local participant.
84
+     */
85
+    _onCustomRoleCommand ({ attributes }, id) {
86
+        // We require to know who issued the command because (1) only a
87
+        // moderator is allowed to send commands and (2) a command MUST be
88
+        // issued by a defined commander.
89
+        if (typeof id === 'undefined'
90
+            || this._conference.isLocalId(id)
91
+            || !attributes.recorderRole)
92
+            return;
93
+
94
+        var isRecorder = (attributes.recorderRole == 'true');
95
+
96
+        if (isRecorder)
97
+            VideoLayout.enableDeviceAvailabilityIcons(id, isRecorder);
98
+    }
99
+}
100
+
101
+export default Recorder;

Loading…
取消
儲存