1 |
|
2 | const Model = require("./Model")
|
3 |
|
4 | class Channel extends Model {
|
5 |
|
6 | constructor(json, stream) {
|
7 | super(json)
|
8 | this.setStream(stream)
|
9 | }
|
10 |
|
11 | defaultFields() {
|
12 | return {
|
13 | userId: {
|
14 | type: String,
|
15 | required: true
|
16 | },
|
17 | deviceId: {
|
18 | type: String,
|
19 | required: true
|
20 | },
|
21 | streamId: {
|
22 | type: String,
|
23 | required: true
|
24 | },
|
25 | dynamic: Boolean,
|
26 | name: String,
|
27 | type: String
|
28 | }
|
29 | }
|
30 |
|
31 | setStream(stream) {
|
32 |
|
33 | this.stream = stream
|
34 |
|
35 | if(stream) {
|
36 | this.streamId = stream.name
|
37 | this.userId = stream.getDevice().userId
|
38 | this.deviceId = stream.getDevice().id
|
39 | }
|
40 | else {
|
41 | this.streamId = null
|
42 | this.userId = null
|
43 | this.deviceId = null
|
44 | }
|
45 |
|
46 | }
|
47 |
|
48 | getStream() {
|
49 | return this.stream || null
|
50 | }
|
51 |
|
52 | }
|
53 |
|
54 | module.exports = Channel
|