User consent dialog
By default, Cobrowse will show a user consent dialog when a new session is incoming. You may modify and customize the consent prompt as you wish, using the SDK hooks described below.
Admin users may also disable this consent prompt from your account settings if you prefer to remove it entirely: https://cobrowse.io/dashboard/settings
Web
iOS / Mac OS
Android
React Native
Xamarin
Windows
1
CobrowseIO.confirmSession = function() {
2
return new Promise(function(resolve, reject) {
3
// show your UI here
4
// call resovle(true) to accept the session
5
resolve(true)
6
// or reject() to reject the session
7
})
8
}
Copied!
1
-(void) cobrowseHandleSessionRequest:(CBIOSession*) session {
2
// show your own UI here
3
// call [session activate: <callback>] to accept and start the session
4
// provide a callback to handle any errors during session initiation
5
[session activate: nil];
6
// or [session end: nil]; to reject the session
7
}
Copied!
1
@Override
2
public void handleSessionRequest(final Activity currentActivity, final Session session) {
3
// Do something here, e.g. showing a permission request dialog
4
// Make sure to call activate(<callback>) on the session object if
5
// you want to start the session.
6
// Provide a callback if you wish to handle errors during session
7
// initiation.
8
session.activate(null);
9
// or session.end(null) to reject the session
10
}
Copied!
1
CobrowseIO.handleSessionRequest = function(session) {
2
// Replace this with your own logic
3
// Just be sure to call session.activate() to
4
// accept the session, or session.end() to reject it
5
session.activate()
6
}
Copied!

Xamarin.iOS implementation

1
public override void CobrowseHandleSessionRequest(Session session) {
2
// show your own UI here
3
// call Activate(<callback>) to accept and start the session
4
// provide a callback to handle any errors during session initiation
5
session.Activate(callback: null);
6
// or session.End(null) to reject the session
7
}
Copied!

Xamarin.Android implementation

1
public void HandleSessionRequest(Activity activity, Session session) {
2
// Do something here, e.g. showing a permission request dialog
3
// Make sure to call Activate(<callback>) on the session object if
4
// you want to start the session.
5
// Provide a callback if you wish to handle errors during session
6
// initiation.
7
session.Activate(callback: null);
8
// or session.End(null) to reject the session
9
}
Copied!

Xamarin.Forms implementation

You can also achieve this functionality from a cross-platform project. In this case you don't have to implement your own delegate, but instead you subscribe to the SessionDidRequest event:
1
CobrowseIO.Instance.SessionDidRequest += OnCobrowseSessionDidRequest;
2
...
3
private async void OnCobrowseSessionDidRequest(object sender, ISession session) {
4
// Do something here, e.g. showing a permission request dialog
5
// Make sure to call Activate(<callback>) on the session object if
6
// you want to start the session.
7
// Provide a callback if you wish to handle errors during session
8
// initiation.
9
session.Activate(null);
10
// or session.End(null) to reject the session
11
}
Copied!
You can override the default session authorization dialog by adding a handler to the CobrowseIO.Instance.SessionAuthorizing event:
1
CobrowseIO.Instance.SessionAuthorizing += OnSessionAuthorizing;
Copied!
Warning: Callback will be called from non-UI thread, so be sure to dispatch it to the UI one.
  • To confirm session:
1
await CobrowseIO.Instance.CurrentSession.Activate();
Copied!
  • To reject a session:
1
await CobrowseIO.Instance.CurrentSession.End();
Copied!

Example UIs

We've created a set of sample UIs that you may drop directly into your app or website as a starting point to customize the consent prompt.
Web
iOS
Android
React Native
Xamarin
MacOS
Windows
1
// A generic consent dialog class
2
function Consent() {
3
var container = document.createElement('div');
4
function content(title, description){
5
return '\
6
<div style="background: rgba(50, 50, 50, 0.4); position: fixed; z-index: 2147483647; bottom: 0; top: 0; left: 0; right: 0">\
7
<div style="color: #333; font-family:sans-serif; line-height:140%; position:fixed; padding:25px; background:white; border-radius:15px; z-index:2147483647; top:50px; left:50%; width:75%; max-width:350px; transform:translateX(-50%); box-shadow:0px 0px 15px #33333322;">\
8
<div style="text-align:center; margin-top:10px; margin-bottom:20px"><b>'+title+'</b></div>\
9
<div>'+description+'</div>\
10
<div style="float:right; margin-top:40px; color:rgb(0, 122, 255);">\
11
<a class="cobrowse-deny" style="cursor:pointer; padding:10px;">Deny</a>\
12
<a class="cobrowse-allow" style="cursor:pointer; padding:10px; font-weight: bold;">Allow</a>\
13
</div>\
14
</div>\
15
</div>\
16
';
17
}
18
19
this.show = function(title, description) {
20
return new Promise(function(resolve) {
21
container.innerHTML = content(title, description);
22
container.querySelector('.cobrowse-allow').addEventListener('click', function(){ resolve(true); this.hide() }.bind(this));
23
container.querySelector('.cobrowse-deny').addEventListener('click', function(){ resolve(false); this.hide() }.bind(this));
24
if (document.body) document.body.appendChild(container);
25
}.bind(this));
26
}.bind(this);
27
28
this.hide = function() {
29
if (container.parentNode) {
30
container.parentNode.removeChild(container);
31
}
32
}.bind(this);
33
}
34
35
// Integration with Cobrowse
36
CobrowseIO.confirmSession = function() {
37
return new Consent().show('Session Request', 'Do you want to share your screen?');
38
}
Copied!
1
@implementation CBAppDelegate // should implement CobrowseIODelegate
2
3
- (BOOL)application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions {
4
CobrowseIO.instance.delegate = self;
5
// ... the rest of your app setup
6
return YES;
7
}
8
9
-(void) cobrowseHandleSessionRequest:(CBIOSession*) session {
10
// show your own UI here
11
// call [session activate: <callback>] to accept and start the session
12
// provide a callback to handle any errors during session initiation
13
[session activate: nil];
14
}
15
16
@end
Copied!
1
public class MainApplication extends Application implements CobrowseIO.SessionRequestDelegate {
2
3
@Override
4
public void onCreate() {
5
super.onCreate();
6
CobrowseIO.instance().setDelegate(this);
7
8
// and the rest of cobrowse setup ...
9
}
10
11
@Override
12
public void handleSessionRequest(final Activity currentActivity, final Session session) {
13
// Do something here, e.g. showing a permission request dialog
14
// Make sure to call activate(<callback>) on the session object if
15
// you want to start the session.
16
// Provide a callback if you wish to handle errors during session
17
// initiation.
18
session.activate(null);
19
}
20
21
// ...
22
}
Copied!
1
CobrowseIO.handleSessionRequest = function(session) {
2
// Replace this with your own logic
3
// Just be sure to call session.activate() to
4
// accept the session.
5
Alert.alert(
6
'Session Requested',
7
'A cobrowse session has been requested',
8
[
9
{
10
text: 'Cancel',
11
onPress: () => {},
12
style: 'cancel',
13
},
14
{text: 'OK', onPress: () => session.activate()},
15
],
16
{cancelable: true},
17
);
18
}
Copied!

Xamarin.iOS implementation

1
using Xamarin.CobrowseIO;
2
3
[Register("AppDelegate")]
4
public class AppDelegate : UIResponder, IUIApplicationDelegate
5
{
6
[Export("application:didFinishLaunchingWithOptions:")]
7
public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
8
{
9
// ... the rest of your app setup
10
CobrowseIO.Instance.SetDelegate(new CustomCobrowseDelegate());
11
return true;
12
}
13
}
14
15
public class CustomCobrowseDelegate : CobrowseIODelegate
16
{
17
public override void CobrowseHandleSessionRequest(Session session)
18
{
19
// show your own UI here
20
// call Activate(<callback>) to accept and start the session
21
// provide a callback to handle any errors during session initiation
22
session.Activate(callback: null);
23
}
24
25
// ...
26
}
Copied!

Xamarin.Android implementation

1
using Xamarin.CobrowseIO;
2
3
[Application]
4
public class MainApplication : Application
5
{
6
public MainApplication()
7
{
8
}
9
10
protected MainApplication(IntPtr javaReference, JniHandleOwnership transfer)
11
: base(javaReference, transfer)
12
{
13
}
14
15
public override void OnCreate()
16
{
17
base.OnCreate();
18
CobrowseIO.Instance.SetDelegate(new CustomCobrowseDelegate());
19
// and the rest of cobrowse setup ...
20
}
21
}
22
23
public class CustomCobrowseDelegate : Java.Lang.Object, CobrowseIO.ISessionRequestDelegate
24
{
25
public CustomCobrowseDelegate()
26
{
27
}
28
29
public CustomCobrowseDelegate(IntPtr handle, JniHandleOwnership transfer)
30
: base(handle, transfer)
31
{
32
}
33
34
public void HandleSessionRequest(Activity activity, Session session)
35
{
36
// Do something here, e.g. showing a permission request dialog
37
// Make sure to call Activate(<callback>) on the session object if
38
// you want to start the session.
39
// Provide a callback if you wish to handle errors during session
40
// initiation.
41
session.Activate(callback: null);
42
}
43
44
// ...
45
}
Copied!

Xamarin.Forms implementation

You can also achieve this functionality from a cross-platform project. In this case you don't have to implement your own delegate, but instead you subscribe to the SessionDidRequest event:
1
using Xamarin.CobrowseIO.Abstractions;
2
3
public partial class App : Xamarin.Forms.Application
4
{
5
public App()
6
{
7
InitializeComponent();
8
9
CobrowseIO.Instance.License = "trial";
10
CobrowseIO.Instance.Start();
11
// and the rest of cobrowse setup ...
12
}
13
14
protected override void OnStart()
15
{
16
Subscribe();
17
}
18
19
protected override void OnSleep()
20
{
21
Unsubscribe();
22
}
23
24
protected override void OnResume()
25
{
26
Subscribe();
27
}
28
29
private void Subscribe()
30
{
31
CobrowseIO.Instance.SessionDidRequest += OnCobrowseSessionDidRequest;
32
}
33
34
private void Unsubscribe()
35
{
36
CobrowseIO.Instance.SessionDidRequest -= OnCobrowseSessionDidRequest;
37
}
38
39
private async void OnCobrowseSessionDidRequest(object sender, ISession session)
40
{
41
// Do something here, e.g. showing a permission request dialog
42
// Make sure to call Activate(<callback>) on the session object if
43
// you want to start the session.
44
// Provide a callback if you wish to handle errors during session
45
// initiation.
46
bool allowed = await this.MainPage.DisplayAlert(
47
title: "Cobrowse.io",
48
message: "Allow Cobrowse.io session?",
49
accept: "Allow",
50
cancel: "Reject");
51
if (allowed)
52
{
53
session.Activate(null);
54
}
55
else
56
{
57
session.End(null);
58
}
59
}
60
}
Copied!
1
@implementation CBAppDelegate // should implement CobrowseIODelegate
2
3
- (void)applicationDidFinishLaunching:(NSNotification *)notification
4
CobrowseIO.instance.delegate = self;
5
// ... the rest of your app setup
6
}
7
8
-(void) cobrowseHandleSessionRequest:(CBIOSession*) session {
9
// show your own UI here
10
// call [session activate: <callback>] to accept and start the session
11
// provide a callback to handle any errors during session initiation
12
[session activate: nil];
13
}
14
15
@end
Copied!
1
if (MessageBox.Show(
2
window,
3
"Would you like to authorize the Cobrowse.io screenshare session?",
4
"Authorization",
5
MessageBoxButton.YesNo,
6
MessageBoxImage.Question
7
) == MessageBoxResult.Yes)
8
await CobrowseIO.Instance.CurrentSession.Activate();
9
else
10
await CobrowseIO.Instance.CurrentSession.End();
Copied!
Copy link
Contents
Example UIs