Giter VIP home page Giter VIP logo

opentok-xamarin.forms's Introduction

OpenTok for Xamarin.Forms

https://tokbox.com/

Setup

  • Available on NuGet: Xamarin.Forms.OpenTok NuGet
  • Add nuget package to your Xamarin.Forms .netStandard/PCL project and to your platform-specific projects
  • Call PlatformOpenTokService.Init() in platform specific code (Typically it's AppDelegate for iOS and MainActivity for Android)

iOS: Add messages for requesting permissions to Info.plist file

	<key>NSCameraUsageDescription</key>
	<string>use camera to start video call</string>
	<key>NSMicrophoneUsageDescription</key>
	<string>use microphone to start video call</string>

Android: Add permissions to Manifest file

	<uses-permission android:name="android.permission.RECORD_AUDIO" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.CAMERA" />
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

Setup CrossCurrentActivity plugin in MainActivity:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        PlatformOpenTokService.Init();
        base.OnCreate(savedInstanceState);
            CrossCurrentActivity.Current.Activity = this; // Add this line
        Forms.Init(this, savedInstanceState);
        LoadApplication(new App());
        }
    }
Platform Version
Xamarin.iOS 8.0+
Xamarin.Android 15+

Samples

SAMPLE VIDEO: https://twitter.com/Andrik_Just4Fun/status/1151799321223995392

The sample you can find here: https://github.com/AndreiMisiukevich/OpenTok-Xamarin.Forms/tree/master/Xamarin.Forms.OpenTok.Sample

Use CrossOpenTok.Current for accessing OpenTok service.

Full api you can find here: https://github.com/AndreiMisiukevich/OpenTok-Xamarin.Forms/blob/master/Lib/Xamarin.Forms.OpenTok/Service/IOpenTokService.cs

Firstly you should setup your service

CrossOpenTok.Current.ApiKey = keys.ApiKey; // OpenTok api key from your account
CrossOpenTok.Current.SessionId = keys.SessionId; // Id of session for connecting
CrossOpenTok.Current.UserToken = keys.Token; // User's token

Then check wheather you have enough permissions for starting a call and if everything is fine it will start a session.

if(!CrossOpenTok.Current.TryStartSession())
{
    return;
}
//Session is starting, you may show Chat Page

Use OpenTokPublisherView and OpenTokSubscriberView for showing video from your camera and for recieving video from another chat participant. Just put them to any laouyt as you wish. When session was started, they would recieve video.

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:tok="clr-namespace:Xamarin.Forms.OpenTok;assembly=Xamarin.Forms.OpenTok"
             x:Class="Xamarin.Forms.OpenTok.Sample.ChatRoomPage"
             BackgroundColor="White">
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="80" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        
        <tok:OpenTokSubscriberView Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" />
        <tok:OpenTokPublisherView Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" />
        
        <Button Text="End Call" TextColor="Red" Grid.Row="2" Grid.Column="0" Clicked="OnEndCall" />
        <Button Text="Message" TextColor="Black" Grid.Row="2" Grid.Column="1" Clicked="OnMessage" />
        <Button Text="Swap Camera" TextColor="Purple" Grid.Row="2" Grid.Column="2" Clicked="OnSwapCamera" />
        
    </Grid>
</ContentPage>

Check source code for more info, or ๐Ÿ‡ง๐Ÿ‡พ just ask me =) ๐Ÿ‡ง๐Ÿ‡พ

License

The MIT License (MIT) see License file

Contribution

Feel free to create issues and PRs ๐Ÿ˜ƒ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.