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 11{
22 "name" : " opentok-react" ,
3- "version" : " 0.5 .0" ,
3+ "version" : " 0.6 .0" ,
44 "description" : " React components for OpenTok.js" ,
55 "main" : " dist/index.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -34,17 +34,17 @@ export default class OTPublisher extends Component {
3434 } ;
3535
3636 if ( shouldUpdate ( 'videoSource' , undefined ) ) {
37+ this . destroyPublisher ( ) ;
3738 this . createPublisher ( ) ;
3839 return ;
3940 }
4041
4142 updatePublisherProperty ( 'publishAudio' , true ) ;
4243 updatePublisherProperty ( 'publishVideo' , true ) ;
4344
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 ) {
4746 this . destroyPublisher ( prevProps . session ) ;
47+ this . createPublisher ( ) ;
4848 }
4949 }
5050
@@ -100,9 +100,8 @@ export default class OTPublisher extends Component {
100100 }
101101
102102 createPublisher ( ) {
103- this . destroyPublisher ( ) ;
104-
105103 if ( ! this . props . session ) {
104+ this . setState ( { publisher : null , lastStreamId : '' } ) ;
106105 return ;
107106 }
108107
Original file line number Diff line number Diff line change @@ -13,6 +13,26 @@ export default class OTSession extends Component {
1313 }
1414
1515 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+
1636 this . sessionHelper = createSession ( {
1737 apiKey : this . props . apiKey ,
1838 sessionId : this . props . sessionId ,
@@ -33,14 +53,16 @@ export default class OTSession extends Component {
3353 this . setState ( { streams } ) ;
3454 }
3555
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 ( ) ;
4265 }
43- this . sessionHelper . disconnect ( ) ;
4466 }
4567
4668 render ( ) {
Original file line number Diff line number Diff line change @@ -29,16 +29,9 @@ export default class OTSubscriber extends Component {
2929 updateSubscriberProperty ( 'subscribeToAudio' ) ;
3030 updateSubscriberProperty ( 'subscribeToVideo' ) ;
3131
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 ) {
4133 this . destroySubscriber ( prevProps . session ) ;
34+ this . createSubscriber ( ) ;
4235 }
4336 }
4437
@@ -51,9 +44,8 @@ export default class OTSubscriber extends Component {
5144 }
5245
5346 createSubscriber ( ) {
54- this . destroySubscriber ( ) ;
55-
5647 if ( ! this . props . session || ! this . props . stream ) {
48+ this . setState ( { subscriber : null } ) ;
5749 return ;
5850 }
5951
You can’t perform that action at this time.
0 commit comments