Guest User

Untitled

a guest
Feb 23rd, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import type { Ref } from 'react';
  2. import React, { Component } from "react";
  3. import { Dimensions, StyleSheet, Text, TouchableOpacity, View } from "react-native";
  4. import OpenTok, { Publisher } from 'react-native-opentok';
  5. import Icon from 'react-native-vector-icons/Ionicons';
  6.  
  7. var { height, width } = Dimensions.get('window');
  8.  
  9. const sessionId = '1_MX40NjA2NjM1Mn5-MTUxOTM4MTk5ODc5Mn5hUnFycTQzczR4cm90bGtoejNSTWdWVkV-fg';
  10. const token = 'T1==cGFydG5lcl9pZD00NjA2NjM1MiZzaWc9NTE2YTUyYmJmZWFiNmY1NjcyYTA4ZmI3NDI1ZGM1Nzc2Y2JlMzE2MTpzZXNzaW9uX2lkPTFfTVg0ME5qQTJOak0xTW41LU1UVXhPVE00TVRrNU9EYzVNbjVoVW5GeWNUUXpjelI0Y205MGJHdG9lak5TVFdkV1ZrVi1mZyZjcmVhdGVfdGltZT0xNTE5Mzg4MDM4Jm5vbmNlPTAuMjY1MTk2MjA3Nzk4MDA2MSZyb2xlPXB1Ymxpc2hlciZleHBpcmVfdGltZT0xNTE5OTkyODM3JmluaXRpYWxfbGF5b3V0X2NsYXNzX2xpc3Q9';
  11.  
  12.  
  13. export default class Publish extends Component<{}> {
  14.  
  15.     constructor(props) {
  16.         super(props);
  17.         this.openTokConnect();
  18.     }
  19.  
  20.     openTokConnect = async () => {
  21.         await OpenTok.connect(sessionId, token);
  22.     };
  23.  
  24.     ref: Ref<typeof Publisher>;
  25.  
  26.     render() {
  27.  
  28.         return (
  29.             <View style={styles.container}>
  30.                 <View style={{ flex: 0.7 }}>
  31.                     <Publisher
  32.                         sessionId={sessionId}
  33.                         onPublishStart={() => {
  34.                             console.log('started')
  35.                         }}
  36.                         style={styles.publisher}
  37.                         ref={ref => {
  38.                             this.ref = ref;
  39.                         }}
  40.                     />
  41.                 </View>
  42.                 <View style={{ flex: 0.15, flexDirection: 'row' }}>
  43.                     <View style={{ flex: 0.2 }}></View>
  44.                     <TouchableOpacity
  45.                         style={styles.iconBox}
  46.                         onPress={() => {
  47.                             if (typeof this.ref !== 'string') this.ref.switchCamera()
  48.                         }}>
  49.                         <Icon
  50.                             name="ios-reverse-camera"
  51.                             size={40} color="white" style={{ fontWeight: 'bold' }}
  52.                         />
  53.                     </TouchableOpacity>
  54.                     <TouchableOpacity
  55.                         style={styles.iconBox}>
  56.                         <Icon
  57.                             name="ios-volume-off"
  58.                             size={40} color="white" style={{ fontWeight: 'bold' }}
  59.                         />
  60.                     </TouchableOpacity>
  61.                     <View style={{ flex: 0.2 }}></View>
  62.                 </View>
  63.                 <View style={{ flex: 0.15, flexDirection: 'row' }}>
  64.                     <TouchableOpacity
  65.                         style={styles.cancelBtn}
  66.                         onPress={() => this.cancelAndBack()}>
  67.                         <Text style={{ color: 'white', fontSize: 20, fontWeight: 'bold', }}>Cancel</Text>
  68.                     </TouchableOpacity>
  69.                 </View>
  70.             </View>
  71.         );
  72.     }
  73.  
  74.     cancelAndBack() {
  75.         OpenTok.disconnect(sessionId);
  76.         this.props.navigation.goBack()
  77.     }
  78. };
  79.  
  80. const styles = StyleSheet.create({
  81.     container: {
  82.         flex: 1,
  83.     },
  84.     publisher: {
  85.         backgroundColor: 'black',
  86.         height: height,
  87.         width: width
  88.     },
  89.     iconBox: {
  90.         flex: 0.3,
  91.         margin: 5,
  92.         alignItems: 'center',
  93.         borderRadius: 5,
  94.         justifyContent: 'center',
  95.         borderWidth: 1,
  96.         backgroundColor: "transparent",
  97.         borderColor: 'white'
  98.     },
  99.     cancelBtn: {
  100.         backgroundColor: '#E74C3C',
  101.         flex: 1,
  102.         margin: 10,
  103.         alignItems: 'center',
  104.         justifyContent: 'center'
  105.     },
  106.     headerIcon: {
  107.         flex: 0.1,
  108.         justifyContent: 'center',
  109.         alignItems: 'center',
  110.         paddingLeft: 5,
  111.         paddingTop: 10
  112.     }
  113. });
Advertisement
Add Comment
Please, Sign In to add comment