This repository was archived by the owner on Nov 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +37
-24
lines changed Expand file tree Collapse file tree 4 files changed +37
-24
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " opentok-react" ,
3
- "version" : " 0.5 .0" ,
3
+ "version" : " 0.6 .0" ,
4
4
"description" : " React components for OpenTok.js" ,
5
5
"main" : " dist/index.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -34,17 +34,17 @@ export default class OTPublisher extends Component {
34
34
} ;
35
35
36
36
if ( shouldUpdate ( 'videoSource' , undefined ) ) {
37
+ this . destroyPublisher ( ) ;
37
38
this . createPublisher ( ) ;
38
39
return ;
39
40
}
40
41
41
42
updatePublisherProperty ( 'publishAudio' , true ) ;
42
43
updatePublisherProperty ( 'publishVideo' , true ) ;
43
44
44
- if ( ! prevProps . session && this . props . session ) {
45
- this . createPublisher ( ) ;
46
- } else if ( prevProps . session && ! this . props . session ) {
45
+ if ( this . props . session !== prevProps . session ) {
47
46
this . destroyPublisher ( prevProps . session ) ;
47
+ this . createPublisher ( ) ;
48
48
}
49
49
}
50
50
@@ -100,9 +100,8 @@ export default class OTPublisher extends Component {
100
100
}
101
101
102
102
createPublisher ( ) {
103
- this . destroyPublisher ( ) ;
104
-
105
103
if ( ! this . props . session ) {
104
+ this . setState ( { publisher : null , lastStreamId : '' } ) ;
106
105
return ;
107
106
}
108
107
Original file line number Diff line number Diff line change @@ -13,6 +13,26 @@ export default class OTSession extends Component {
13
13
}
14
14
15
15
componentWillMount ( ) {
16
+ this . createSession ( ) ;
17
+ }
18
+
19
+ componentDidUpdate ( prevProps ) {
20
+ if (
21
+ prevProps . apiKey !== this . props . apiKey ||
22
+ prevProps . sessionId !== this . props . sessionId ||
23
+ prevProps . token !== this . props . token
24
+ ) {
25
+ this . createSession ( ) ;
26
+ }
27
+ }
28
+
29
+ componentWillUnmount ( ) {
30
+ this . destroySession ( ) ;
31
+ }
32
+
33
+ createSession ( ) {
34
+ this . destroySession ( ) ;
35
+
16
36
this . sessionHelper = createSession ( {
17
37
apiKey : this . props . apiKey ,
18
38
sessionId : this . props . sessionId ,
@@ -33,14 +53,16 @@ export default class OTSession extends Component {
33
53
this . setState ( { streams } ) ;
34
54
}
35
55
36
- componentWillUnmount ( ) {
37
- if (
38
- this . props . eventHandlers &&
39
- typeof this . props . eventHandlers === 'object'
40
- ) {
41
- this . sessionHelper . session . off ( this . props . eventHandlers ) ;
56
+ destroySession ( ) {
57
+ if ( this . sessionHelper ) {
58
+ if (
59
+ this . props . eventHandlers &&
60
+ typeof this . props . eventHandlers === 'object'
61
+ ) {
62
+ this . sessionHelper . session . off ( this . props . eventHandlers ) ;
63
+ }
64
+ this . sessionHelper . disconnect ( ) ;
42
65
}
43
- this . sessionHelper . disconnect ( ) ;
44
66
}
45
67
46
68
render ( ) {
Original file line number Diff line number Diff line change @@ -29,16 +29,9 @@ export default class OTSubscriber extends Component {
29
29
updateSubscriberProperty ( 'subscribeToAudio' ) ;
30
30
updateSubscriberProperty ( 'subscribeToVideo' ) ;
31
31
32
- if (
33
- ( ! prevProps . session || ! prevProps . stream ) &&
34
- this . props . session && this . props . stream
35
- ) {
36
- this . createSubscriber ( ) ;
37
- } else if (
38
- prevProps . session && prevProps . stream &&
39
- ( ! this . props . session || ! this . props . stream )
40
- ) {
32
+ if ( this . props . session !== prevProps . session || this . props . stream !== prevProps . stream ) {
41
33
this . destroySubscriber ( prevProps . session ) ;
34
+ this . createSubscriber ( ) ;
42
35
}
43
36
}
44
37
@@ -51,9 +44,8 @@ export default class OTSubscriber extends Component {
51
44
}
52
45
53
46
createSubscriber ( ) {
54
- this . destroySubscriber ( ) ;
55
-
56
47
if ( ! this . props . session || ! this . props . stream ) {
48
+ this . setState ( { subscriber : null } ) ;
57
49
return ;
58
50
}
59
51
You can’t perform that action at this time.
0 commit comments