opentok-react-native
Advanced tools
Comparing version 0.6.2 to 0.6.3
{ | ||
"name": "opentok-react-native", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "React Native components for OpenTok iOS and Android SDKs", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -14,2 +14,3 @@ # opentok-react-native | ||
- [OTSubscriber Component](https://github.com/opentok/opentok-react-native/tree/master/docs/OTSubscriber.md) | ||
- [Samples](#samples) | ||
- [Contributing](#contributing) | ||
@@ -126,4 +127,8 @@ | ||
## Samples | ||
To see this library in action, check out the [opentok-react-native-samples](https://github.com/opentok/opentok-react-native-samples) repo. | ||
## Contributing | ||
If you make changes to the project that you would like to contribute back then please follow the [contributing guidelines](CONTRIBUTING.md). All contributions are greatly appreciated! |
import { reassignEvents } from './OTHelper'; | ||
import { handleSignalError } from '../OTError'; | ||
import { handleSignalError, handleError } from '../OTError'; | ||
import { each, isNull, isEmpty, isString } from 'underscore'; | ||
@@ -41,3 +42,3 @@ const sanitizeSessionEvents = (events) => { | ||
const isString = value => (typeof value !== 'string' ? '' : value); | ||
const validateString = value => (isString(value) ? value : ''); | ||
@@ -53,4 +54,4 @@ const sanitizeSignalData = (signal) => { | ||
return { | ||
type: signal.type ? isString(signal.type) : '', | ||
data: signal.data ? isString(signal.data) : '', | ||
type: validateString(signal.type), | ||
data: validateString(signal.data), | ||
errorHandler: typeof signal.errorHandler !== 'function' ? handleSignalError : signal.errorHandler, | ||
@@ -60,5 +61,18 @@ }; | ||
const sanitizeCredentials = (credentials) => { | ||
const _credentials = {}; | ||
each(credentials, (value, key) => { | ||
if(!isString(value) || isEmpty(value) || isNull(value)) { | ||
handleError(`Please add the ${key}`); | ||
} else { | ||
_credentials[key] = value; | ||
} | ||
}); | ||
return _credentials; | ||
}; | ||
export { | ||
sanitizeSessionEvents, | ||
sanitizeSignalData, | ||
sanitizeCredentials, | ||
}; |
@@ -5,5 +5,6 @@ import React, { Component, Children, cloneElement } from 'react'; | ||
import { setNativeEvents, removeNativeEvents, OT } from './OT'; | ||
import { sanitizeSessionEvents, sanitizeSignalData } from './helpers/OTSessionHelper'; | ||
import { sanitizeSessionEvents, sanitizeSignalData, sanitizeCredentials } from './helpers/OTSessionHelper'; | ||
import { logOT } from './helpers/OTHelper'; | ||
import { handleError } from './OTError'; | ||
import { pick } from 'underscore'; | ||
@@ -18,6 +19,10 @@ export default class OTSession extends Component { | ||
componentWillMount() { | ||
const sessionEvents = sanitizeSessionEvents(this.props.eventHandlers); | ||
setNativeEvents(sessionEvents); | ||
this.createSession(); | ||
logOT(this.props.apiKey, this.props.sessionId, 'rn_initialize'); | ||
const credentials = pick(this.props, ['apiKey', 'sessionId', 'token']); | ||
const sanitizedCredentials = sanitizeCredentials(credentials); | ||
if (Object.keys(sanitizedCredentials).length === 3) { | ||
const sessionEvents = sanitizeSessionEvents(this.props.eventHandlers); | ||
setNativeEvents(sessionEvents); | ||
this.createSession(sanitizedCredentials); | ||
logOT(sanitizedCredentials.apiKey, sanitizedCredentials.sessionId, 'rn_initialize'); | ||
} | ||
} | ||
@@ -45,5 +50,5 @@ componentDidUpdate(previousProps) { | ||
} | ||
createSession() { | ||
OT.initSession(this.props.apiKey, this.props.sessionId); | ||
OT.connect(this.props.token, (error) => { | ||
createSession(credentials) { | ||
OT.initSession(credentials.apiKey, credentials.sessionId); | ||
OT.connect(credentials.token, (error) => { | ||
if (error) { | ||
@@ -56,3 +61,3 @@ handleError(error); | ||
}); | ||
logOT(this.props.apiKey, this.props.sessionId, 'rn_on_connect', sessionInfo.connection.connectionId); | ||
logOT(credentials.apiKey, credentials.sessionId, 'rn_on_connect', sessionInfo.connection.connectionId); | ||
const signalData = sanitizeSignalData(this.props.signal); | ||
@@ -59,0 +64,0 @@ OT.sendSignal(signalData, signalData.errorHandler); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115318
660
133