Packages and Offers apply token
parent
d0986fcaf6
commit
aad071ac67
@ -0,0 +1,58 @@
|
||||
package com.ejada.hmg.opentok
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import com.ejada.hmg.R
|
||||
import io.flutter.plugin.common.StandardMessageCodec
|
||||
import io.flutter.plugin.platform.PlatformView
|
||||
import io.flutter.plugin.platform.PlatformViewFactory
|
||||
|
||||
class LocalVideoFactory : PlatformViewFactory(StandardMessageCodec.INSTANCE) {
|
||||
|
||||
companion object {
|
||||
private lateinit var view: LocalVideoPlatformView
|
||||
|
||||
fun getViewInstance(context: Context): LocalVideoPlatformView {
|
||||
if(!this::view.isInitialized) {
|
||||
view = LocalVideoPlatformView(context)
|
||||
}
|
||||
|
||||
return view
|
||||
}
|
||||
}
|
||||
|
||||
override fun create(context: Context, viewId: Int, args: Any?): PlatformView {
|
||||
return getViewInstance(context)
|
||||
}
|
||||
}
|
||||
|
||||
class LocalVideoPlatformView(context: Context) : PlatformView {
|
||||
private val videoContainer: LocalVideoContainer = LocalVideoContainer(context)
|
||||
|
||||
val container get() = videoContainer.publisherContainer
|
||||
|
||||
override fun getView(): View {
|
||||
return videoContainer
|
||||
}
|
||||
|
||||
override fun dispose() {}
|
||||
}
|
||||
|
||||
class LocalVideoContainer @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0,
|
||||
defStyleRes: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyle, defStyleRes) {
|
||||
|
||||
var publisherContainer: FrameLayout private set
|
||||
|
||||
init {
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.local_video, this, true)
|
||||
publisherContainer = view.findViewById(R.id.publisher_container)
|
||||
}
|
||||
}
|
||||
@ -1 +1 @@
|
||||
3f3d14a0ae775b56806906c2cb14a1f0
|
||||
3f8c659591fcdd0e47e3895f74af395c
|
||||
@ -0,0 +1,91 @@
|
||||
//
|
||||
// OpenTokLocalVideoFactory.swift
|
||||
// Runner
|
||||
//
|
||||
// Created by Zohaib Iqbal Kambrani on 20/10/2021.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class OpenTokLocalVideoFactory: NSObject, FlutterPlatformViewFactory {
|
||||
static var view: LocalVideoPlatformView?
|
||||
|
||||
static var viewToAddPub: UIView?
|
||||
|
||||
static func getViewInstance(
|
||||
frame: CGRect,
|
||||
viewId: Int64,
|
||||
args: Any?,
|
||||
messenger: FlutterBinaryMessenger?
|
||||
) -> LocalVideoPlatformView{
|
||||
if(view == nil) {
|
||||
view = LocalVideoPlatformView()
|
||||
if viewToAddPub != nil {
|
||||
view?.addPublisherView(viewToAddPub!)
|
||||
}
|
||||
}
|
||||
|
||||
return view!
|
||||
}
|
||||
|
||||
private var messenger: FlutterBinaryMessenger
|
||||
|
||||
init(messenger: FlutterBinaryMessenger) {
|
||||
self.messenger = messenger
|
||||
super.init()
|
||||
}
|
||||
|
||||
func create(
|
||||
withFrame frame: CGRect,
|
||||
viewIdentifier viewId: Int64,
|
||||
arguments args: Any?
|
||||
) -> FlutterPlatformView {
|
||||
return OpenTokLocalVideoFactory.getViewInstance(
|
||||
frame: frame,
|
||||
viewId: viewId,
|
||||
args: args,
|
||||
messenger: messenger)
|
||||
}
|
||||
}
|
||||
|
||||
class LocalVideoPlatformView: NSObject, FlutterPlatformView {
|
||||
private let videoContainer: LocalVideoContainer
|
||||
|
||||
override init() {
|
||||
videoContainer = LocalVideoContainer()
|
||||
super.init()
|
||||
}
|
||||
|
||||
public func addPublisherView(_ view: UIView) {
|
||||
videoContainer.addPublisherView(view)
|
||||
}
|
||||
|
||||
func view() -> UIView {
|
||||
return videoContainer
|
||||
}
|
||||
}
|
||||
|
||||
final class LocalVideoContainer: UIView {
|
||||
private let publisherContainer = UIView()
|
||||
|
||||
init() {
|
||||
super.init(frame: .zero)
|
||||
addSubview(publisherContainer)
|
||||
}
|
||||
|
||||
public func addPublisherView(_ view: UIView) {
|
||||
publisherContainer.addSubview(view)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
let width = frame.width
|
||||
let height = frame.height
|
||||
|
||||
publisherContainer.frame = CGRect(x: 0, y: 0, width: width, height: height)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
//
|
||||
// OpenTokRemoteVideoFactory.swift
|
||||
// Runner
|
||||
//
|
||||
// Created by Zohaib Iqbal Kambrani on 20/10/2021.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class OpenTokRemoteVideoFactory: NSObject, FlutterPlatformViewFactory {
|
||||
static var view: RemoteVideoPlatformView?
|
||||
|
||||
static var viewToAddSub: UIView?
|
||||
|
||||
static func getViewInstance(
|
||||
frame: CGRect,
|
||||
viewId: Int64,
|
||||
args: Any?,
|
||||
messenger: FlutterBinaryMessenger?
|
||||
) -> RemoteVideoPlatformView{
|
||||
if(view == nil) {
|
||||
view = RemoteVideoPlatformView()
|
||||
if viewToAddSub != nil {
|
||||
view?.addSubscriberView(viewToAddSub!)
|
||||
}
|
||||
}
|
||||
|
||||
return view!
|
||||
}
|
||||
|
||||
private var messenger: FlutterBinaryMessenger
|
||||
|
||||
init(messenger: FlutterBinaryMessenger) {
|
||||
self.messenger = messenger
|
||||
super.init()
|
||||
}
|
||||
|
||||
func create(
|
||||
withFrame frame: CGRect,
|
||||
viewIdentifier viewId: Int64,
|
||||
arguments args: Any?
|
||||
) -> FlutterPlatformView {
|
||||
return OpenTokRemoteVideoFactory.getViewInstance(
|
||||
frame: frame,
|
||||
viewId: viewId,
|
||||
args: args,
|
||||
messenger: messenger)
|
||||
}
|
||||
}
|
||||
|
||||
class RemoteVideoPlatformView: NSObject, FlutterPlatformView {
|
||||
private let videoContainer: RemoteVideoContainer
|
||||
|
||||
override init() {
|
||||
videoContainer = RemoteVideoContainer()
|
||||
super.init()
|
||||
}
|
||||
|
||||
public func addSubscriberView(_ view: UIView) {
|
||||
videoContainer.addSubscriberView(view)
|
||||
}
|
||||
|
||||
func view() -> UIView {
|
||||
return videoContainer
|
||||
}
|
||||
}
|
||||
|
||||
final class RemoteVideoContainer: UIView {
|
||||
private let subscriberContainer = UIView()
|
||||
|
||||
init() {
|
||||
super.init(frame: .zero)
|
||||
addSubview(subscriberContainer)
|
||||
}
|
||||
|
||||
|
||||
public func addSubscriberView(_ view: UIView) {
|
||||
subscriberContainer.addSubview(view)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
let width = frame.width
|
||||
let height = frame.height
|
||||
subscriberContainer.frame = CGRect(x: 0, y: 0, width: width, height: height)
|
||||
}
|
||||
}
|
||||
@ -1,20 +1,41 @@
|
||||
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class PackagesCustomerRequestModel {
|
||||
|
||||
String username;
|
||||
String first_name;
|
||||
String last_name;
|
||||
String email;
|
||||
String phoneNumber;
|
||||
String phone;
|
||||
String national_id;
|
||||
String date_of_birth;
|
||||
|
||||
PackagesCustomerRequestModel({@required this.email, @required this.phoneNumber});
|
||||
|
||||
PackagesCustomerRequestModel.fromUser(AuthenticatedUser user){
|
||||
this.username = "${user.patientID}";
|
||||
this.first_name = user.firstName;
|
||||
this.last_name = user.lastName;
|
||||
this.email = user.emailAddress;
|
||||
this.phone = user.mobileNumber;
|
||||
this.national_id = user.patientIdentificationNo;
|
||||
this.date_of_birth = user.dateofBirth;
|
||||
}
|
||||
|
||||
Map<String, dynamic> json() {
|
||||
return {
|
||||
"customer" : {
|
||||
"email": email,
|
||||
"addresses": [{
|
||||
"email": email,
|
||||
"phone_number": phoneNumber
|
||||
}]
|
||||
"email": email ?? '',
|
||||
"username": username ?? '',
|
||||
"national_id": national_id ?? '',
|
||||
"phone": phone ?? '',
|
||||
"date_of_birth": date_of_birth ?? '',
|
||||
"first_name": first_name ?? '',
|
||||
"last_name": last_name ?? '',
|
||||
// "addresses": [{
|
||||
// "email": email,
|
||||
// "phone_number": phoneNumber
|
||||
// }]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -0,0 +1,180 @@
|
||||
import 'package:diplomaticquarterapp/pages/conference/draggable_publisher.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'OpenTokPlatformBridge.dart';
|
||||
|
||||
|
||||
class OpenTokConnectCallPage extends StatefulWidget{
|
||||
final String sessionId;
|
||||
final String token;
|
||||
final String apiKey;
|
||||
OpenTokConnectCallPage({@required this.sessionId, @required this.token, @required this.apiKey});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => OpenTokState();
|
||||
|
||||
}
|
||||
|
||||
class OpenTokState extends State<OpenTokConnectCallPage>{
|
||||
OpenTokPlatformBridge openTokPlatform;
|
||||
OpenTokSDKState sdkState = OpenTokSDKState.LOGGED_OUT;
|
||||
|
||||
initOpenTok(){
|
||||
openTokPlatform = OpenTokPlatformBridge.init(
|
||||
apiKey: widget.apiKey,
|
||||
sessionID: widget.sessionId,
|
||||
token: widget.token,
|
||||
onStateChange: (state) {
|
||||
setState(() => sdkState = state);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
initOpenTok();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
actions: [
|
||||
TextButton(onPressed: (){
|
||||
initOpenTok();
|
||||
}, child: Icon(Icons.connect_without_contact_outlined, color: Colors.green,))
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Stack(
|
||||
children: [
|
||||
if(sdkState == OpenTokSDKState.LOGGED_IN)
|
||||
...platformVideoViews(),
|
||||
|
||||
|
||||
if(sdkState == OpenTokSDKState.LOGGED_OUT)
|
||||
Center(child: Text("Logged Out"),),
|
||||
|
||||
if(sdkState == OpenTokSDKState.ERROR)
|
||||
Center(child: Text("Error opening session"),),
|
||||
|
||||
if(sdkState == OpenTokSDKState.WAIT)
|
||||
Center(child: CircularProgressIndicator(),),
|
||||
|
||||
if(sdkState == OpenTokSDKState.ON_CALL)
|
||||
Container(),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
child: Text('Mute Video') ,onPressed: () => openTokPlatform.toggleVideo()
|
||||
),
|
||||
),
|
||||
SizedBox(width: 20,),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
child: Text('Mute Audio') ,onPressed: () => openTokPlatform.toggleAudio()
|
||||
),
|
||||
),
|
||||
SizedBox(width: 20,),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
child: Text('Change Camera') ,onPressed: () => openTokPlatform.swapCamera()
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool remoteVideoOnFull = true;
|
||||
List<Widget> platformVideoViews(){
|
||||
return [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height,
|
||||
child: remoteVideoOnFull ? remotePlatformVideoView() : localPlatformVideoView()
|
||||
),
|
||||
|
||||
DraggablePublisher(
|
||||
onButtonBarHeight: ((double)async*{}(50)),
|
||||
onButtonBarVisible: ((bool)async*{}(true)),
|
||||
availableScreenSize: MediaQuery.of(context).size,
|
||||
child: InkWell(
|
||||
child: (remoteVideoOnFull ? localPlatformVideoView() : remotePlatformVideoView()),
|
||||
onTap: (){
|
||||
print('');
|
||||
},
|
||||
),
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
Widget localPlatformVideoView(){
|
||||
return PlatformViewLink(
|
||||
viewType: 'local-video-container', // custom platform-view-type
|
||||
surfaceFactory:
|
||||
(BuildContext context, PlatformViewController controller) {
|
||||
return AndroidViewSurface(
|
||||
controller: controller,
|
||||
gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
|
||||
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
||||
);
|
||||
},
|
||||
|
||||
onCreatePlatformView: (PlatformViewCreationParams params) {
|
||||
return PlatformViewsService.initSurfaceAndroidView(
|
||||
id: params.id,
|
||||
viewType: 'local-video-container',
|
||||
// custom platform-view-type,
|
||||
layoutDirection: TextDirection.ltr,
|
||||
creationParams: {},
|
||||
creationParamsCodec: StandardMessageCodec(),
|
||||
)
|
||||
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
|
||||
..create();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget remotePlatformVideoView(){
|
||||
return PlatformViewLink(
|
||||
viewType: 'remote-video-container', // custom platform-view-type
|
||||
surfaceFactory:
|
||||
(BuildContext context, PlatformViewController controller) {
|
||||
return AndroidViewSurface(
|
||||
controller: controller,
|
||||
gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
|
||||
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
||||
);
|
||||
},
|
||||
onCreatePlatformView: (PlatformViewCreationParams params) {
|
||||
return PlatformViewsService.initSurfaceAndroidView(
|
||||
id: params.id,
|
||||
viewType: 'remote-video-container',
|
||||
// custom platform-view-type,
|
||||
layoutDirection: TextDirection.ltr,
|
||||
creationParams: {},
|
||||
creationParamsCodec: StandardMessageCodec(),
|
||||
)
|
||||
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
|
||||
..create();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
enum OpenTokSDKState{ LOGGED_OUT, LOGGED_IN, WAIT, ON_CALL, ERROR }
|
||||
final _platformMethodChannel = const MethodChannel('OpenTok-Platform-Bridge');
|
||||
|
||||
class OpenTokPlatformBridge{
|
||||
|
||||
|
||||
OpenTokSDKState _sdkState = OpenTokSDKState.LOGGED_OUT;
|
||||
bool _publishAudio = true;
|
||||
bool _publishVideo = true;
|
||||
|
||||
final void Function(OpenTokSDKState) onStateChange;
|
||||
|
||||
OpenTokPlatformBridge.init({@required String sessionID, @required String token, @required String apiKey, this.onStateChange}){
|
||||
_initSession({'apiKey':apiKey, 'sessionId':sessionID, 'token':token, });
|
||||
_platformMethodChannel.setMethodCallHandler(incomingMethodHadler);
|
||||
}
|
||||
|
||||
Future<dynamic> incomingMethodHadler(MethodCall methodCall) async {
|
||||
switch (methodCall.method) {
|
||||
case 'updateState':
|
||||
{
|
||||
var arguments = 'OpenTokSDKState.${methodCall.arguments}';
|
||||
_sdkState = OpenTokSDKState.values.firstWhere((v) {
|
||||
return v.toString() == arguments;
|
||||
});
|
||||
onStateChange(_sdkState);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw MissingPluginException('notImplemented');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> _initSession(Map<String,String> openTokCredentials) async {
|
||||
await requestPermissions();
|
||||
try {
|
||||
await _platformMethodChannel.invokeMethod('initSession', openTokCredentials);
|
||||
} on PlatformException catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> makeCall() async {
|
||||
try {
|
||||
await requestPermissions();
|
||||
|
||||
await _platformMethodChannel.invokeMethod('makeCall');
|
||||
} on PlatformException catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> requestPermissions() async {
|
||||
await [Permission.microphone, Permission.camera].request();
|
||||
}
|
||||
|
||||
Future<void> swapCamera() async {
|
||||
try {
|
||||
await _platformMethodChannel.invokeMethod('swapCamera');
|
||||
} on PlatformException catch (e) {}
|
||||
}
|
||||
|
||||
Future<void> toggleAudio() async {
|
||||
_publishAudio = !_publishAudio;
|
||||
dynamic params = {'publishAudio': _publishAudio};
|
||||
|
||||
try {
|
||||
await _platformMethodChannel.invokeMethod('publishAudio', params);
|
||||
} on PlatformException catch (e) {}
|
||||
}
|
||||
|
||||
Future<void> toggleVideo() async {
|
||||
_publishVideo = !_publishVideo;
|
||||
dynamic params = {'publishVideo': _publishVideo};
|
||||
|
||||
try {
|
||||
await _platformMethodChannel.invokeMethod('toggleVideo', params);
|
||||
} on PlatformException catch (e) {}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue