Skip to content

Commit

Permalink
add timer to finish config before recording
Browse files Browse the repository at this point in the history
  • Loading branch information
federico-bohn committed Nov 18, 2016
1 parent 3c1e8ff commit 4ff69ff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
11 changes: 10 additions & 1 deletion PublisherView.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class PublisherView extends React.Component {
* Enable video
*/
videoEnabled: React.PropTypes.bool,
/**
* This function is called when the pushisher is being resumed
*
*/
onPublishResumed: React.PropTypes.func,
};


Expand All @@ -144,13 +149,17 @@ class PublisherView extends React.Component {
onArchiveStarted: noop,
onArchiveStopped: noop,
onThumbnailReady: noop,
onPublishResumed: noop,
};

pausePublish() {
OpenTokPublisherViewManager.pausePublish();
}
resumePublish() {
OpenTokPublisherViewManager.resumePublish();
OpenTokPublisherViewManager.resumePublish()
setTimeout(() => {
if (this.props.onPublishResumed) this.props.onPublishResumed();
}, 3000);
}
stopPublish() {
OpenTokPublisherViewManager.stopPublish();
Expand Down
21 changes: 17 additions & 4 deletions RCTOpenTokPublisherView.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ @implementation RCTOpenTokPublisherView {
BOOL _isSessionCreated;
BOOL _isPaused;
BOOL _isPublished;
NSTimer *_recordTimer;
}

/**
Expand Down Expand Up @@ -55,6 +56,9 @@ - (void) createSession {
} else {
_isSessionCreated = YES;
}

[_recordTimer invalidate];
_recordTimer = nil;
}

/**
Expand Down Expand Up @@ -240,12 +244,21 @@ - (void)session:(OTSession*)session didFailWithError:(OTError*)error {

#pragma mark - OTSession delegate - archive callbacks
- (void)session:(OTSession *)session archiveStartedWithId:(NSString *)archiveId name:(NSString *)name {
[self saveThumbnail];

if (_recordTimer == nil) {
NSMutableArray *params = [NSMutableArray array];
[params addObject:archiveId];
[params addObject:name];
_recordTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(_progressRecordTimerFired:) userInfo:params repeats:NO];
}
}

- (void)_progressRecordTimerFired:(NSTimer *)progressTimer {
_onArchiveStarted(@{
@"archiveId": archiveId,
@"name": name,
@"archiveId": progressTimer.userInfo[0],
@"name": progressTimer.userInfo[1],
});

[self saveThumbnail];
}

- (void)session:(OTSession *)session archiveStoppedWithId:(NSString *)archiveId {
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ onSessionDidConnect | function
onSessionDidDisconnect | function
onArchiveStarted | function
onArchiveStopped | function
onPublishResumed | function
------------ | -------------
onSubscribeStart | function
onSubscribeError | function
Expand Down

0 comments on commit 4ff69ff

Please sign in to comment.