Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MAUI example app to csharp samples #4078

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion pjsip-apps/src/swig/csharp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,31 @@ SWIG_FLAGS += -w312
PROJ_NAME=pjsua2xamarin
OUT_DIR=$(PROJ_NAME)/$(PROJ_NAME)/pjsua2
NAMESPACE=$(PROJ_NAME).pjsua2
MAUI_PROJ_NAME=pjsua2maui
MAUI_NAMESPACE=libpjsua2.maui

ARCH=$(TARGET_ARCH)

ifeq ($(OS),android)
LIBPJSUA2_DIR=$(PROJ_NAME)/$(PROJ_NAME).Android/lib/$(ARCH)
LIBPJSUA2=$(LIBPJSUA2_DIR)/libpjsua2.so
SUP_CLASS_DIR=$(PROJ_NAME)/$(PROJ_NAME).Android/org/pjsip
MAUI_LIBPJSUA2_DIR=$(MAUI_PROJ_NAME)/$(MAUI_PROJ_NAME)/Platforms/Android/lib/$(ARCH)
MAUI_LIBPJSUA2=$(MAUI_LIBPJSUA2_DIR)/libpjsua2.so
MAUI_SUP_CLASS_DIR=$(MAUI_PROJ_NAME)/$(MAUI_PROJ_NAME)/Platforms/Android/org/pjsip
MAUI_OUT_DIR=$(MAUI_PROJ_NAME)/$(MAUI_PROJ_NAME)/Platforms/Android/pjsua2
else
ifeq ($(OS),ios)
LIBPJSUA2_DIR=$(PROJ_NAME)/$(PROJ_NAME).iOS/lib/$(ARCH)
MAUI_LIBPJSUA2_DIR=$(MAUI_PROJ_NAME)/$(MAUI_PROJ_NAME)/Platforms/iOS/lib/$(ARCH)
SWIG_FLAGS += -dllimport "__Internal"
MAUI_OUT_DIR=$(MAUI_PROJ_NAME)/$(MAUI_PROJ_NAME)/Platforms/iOS/pjsua2
else
LIBPJSUA2_DIR=$(PROJ_NAME)/lib

endif
LIBPJSUA2=$(LIBPJSUA2_DIR)/libpjsua2.a
MAUI_LIBPJSUA2=$(MAUI_LIBPJSUA2_DIR)/libpjsua2.a
endif

# Build settings
Expand All @@ -44,7 +54,7 @@ MY_LDFLAGS := $(PJ_LDXXFLAGS) $(PJ_LDXXLIBS) $(LDFLAGS)

.PHONY: all install uninstall

all: $(LIBPJSUA2) sample
all: $(LIBPJSUA2) $(MAUI_LIBPJSUA2) sample

$(LIBPJSUA2): $(OUT_DIR)/pjsua2_wrap.o
mkdir -p $(LIBPJSUA2_DIR)
Expand Down Expand Up @@ -74,6 +84,34 @@ $(OUT_DIR)/pjsua2_wrap.cpp: ../pjsua2.i ../symbols.i Makefile $(SRCS)
mkdir -p $(OUT_DIR)
swig $(SWIG_FLAGS) -namespace $(NAMESPACE) -csharp -o $(OUT_DIR)/pjsua2_wrap.cpp ../pjsua2.i

$(MAUI_LIBPJSUA2): $(MAUI_OUT_DIR)/pjsua2_wrap.o
mkdir -p $(MAUI_LIBPJSUA2_DIR)
ifeq ($(OS),android)
mkdir -p $(MAUI_SUP_CLASS_DIR)
$(PJ_CXX) -shared -o $(MAUI_LIBPJSUA2) $(MAUI_OUT_DIR)/pjsua2_wrap.o \
$(MY_CFLAGS) $(MY_LDFLAGS)
# copy libc++_shared.so manually
cp -f ${STD_CPP_LIB} $(MAUI_LIBPJSUA2_DIR)
else
$(AR) $(MAUI_LIBPJSUA2) $(AR_FLAGS) $(MAUI_OUT_DIR)/pjsua2_wrap.o $(PJ_LIBXX_FILES)
endif
ifneq (,$(findstring PJMEDIA_VIDEO_DEV_HAS_ANDROID=1,$(ANDROID_CFLAGS)))
@echo "Copying Android camera helper components..."
cp $(PJDIR)/pjmedia/src/pjmedia-videodev/android/PjCamera*.java $(MAUI_SUP_CLASS_DIR)/
endif
ifneq (,$(findstring PJMEDIA_AUDIO_DEV_HAS_OBOE=1,$(OBOE_CFLAGS)))
@echo "Copying Android Oboe audio device helper components..."
cp $(PJDIR)/pjmedia/src/pjmedia-audiodev/android/PjAudioDevInfo.java $(MAUI_SUP_CLASS_DIR)/
endif

$(MAUI_OUT_DIR)/pjsua2_wrap.o: $(MAUI_OUT_DIR)/pjsua2_wrap.cpp
$(PJ_CXX) -c $(MAUI_OUT_DIR)/pjsua2_wrap.cpp -o $(MAUI_OUT_DIR)/pjsua2_wrap.o \
$(MY_CFLAGS)

$(MAUI_OUT_DIR)/pjsua2_wrap.cpp: ../pjsua2.i ../symbols.i Makefile $(SRCS)
mkdir -p $(MAUI_OUT_DIR)
swig $(SWIG_FLAGS) -namespace $(MAUI_NAMESPACE) -csharp -o $(MAUI_OUT_DIR)/pjsua2_wrap.cpp ../pjsua2.i

sample: sample.cs
@echo "Copying sample code..."
cp sample.cs $(PROJ_NAME)/$(PROJ_NAME)
Expand Down
6 changes: 6 additions & 0 deletions pjsip-apps/src/swig/csharp/pjsua2maui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.dll
.java
.class
.jar
.so
/*/obj/
22 changes: 22 additions & 0 deletions pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pjsua2maui", "pjsua2maui\pjsua2maui.csproj", "{C9D0190E-58BC-417B-9810-335D234D5002}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9D0190E-58BC-417B-9810-335D234D5002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9D0190E-58BC-417B-9810-335D234D5002}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9D0190E-58BC-417B-9810-335D234D5002}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9D0190E-58BC-417B-9810-335D234D5002}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.dll
.java
.class
.jar
.so
/*/obj/
14 changes: 14 additions & 0 deletions pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:pjsua2maui"
x:Class="pjsua2maui.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
11 changes: 11 additions & 0 deletions pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace pjsua2maui;

public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new AppShell();
}
}
14 changes: 14 additions & 0 deletions pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/AppShell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="pjsua2maui.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:pjsua2maui.Views"
Shell.FlyoutBehavior="Disabled">

<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:BuddyPage}"
Route="BuddyPage" />

</Shell>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace pjsua2maui;

public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace pjsua2maui.Controls;

public class CallView : ContentView
{
public CallView()
{
}
}
40 changes: 40 additions & 0 deletions pjsip-apps/src/swig/csharp/pjsua2maui/pjsua2maui/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.Extensions.Logging;
using pjsua2maui.Controls;
#if ANDROID
using pjsua2maui.Platforms.Android;
#endif
#if IOS
using pjsua2maui.Platforms.iOS;
#endif

namespace pjsua2maui;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif
#if __ANDROID__
builder.ConfigureMauiHandlers((x) => {
x.AddHandler(typeof(CallView), typeof(CallPageRenderer));
});
#endif
#if __IOS__
builder.ConfigureMauiHandlers((x) => {
x.AddHandler(typeof(CallView), typeof(CallPageRenderer));
});
#endif
return builder.Build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
using libpjsua2.maui;

namespace pjsua2maui.Messages;

public class AddBuddyMessage : ValueChangedMessage<BuddyConfig>
{
public AddBuddyMessage(BuddyConfig buddyConfig) : base(buddyConfig)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using CommunityToolkit.Mvvm.Messaging.Messages;
using libpjsua2.maui;

namespace pjsua2maui.Messages;

public class EditBuddyMessage : ValueChangedMessage<BuddyConfig>
{
public EditBuddyMessage(BuddyConfig buddyConfig) : base(buddyConfig)
{
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CommunityToolkit.Mvvm.Messaging.Messages;
using pjsua2maui.Models;

namespace pjsua2maui.Messages;

public class SaveAccountConfigMessage : ValueChangedMessage<SoftAccountConfigModel>
{
public SaveAccountConfigMessage(SoftAccountConfigModel softAccountConfigModel) : base(softAccountConfigModel)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using CommunityToolkit.Mvvm.Messaging.Messages;
using libpjsua2.maui;

namespace pjsua2maui.Messages;

public class UpdateCallStateMessage : ValueChangedMessage<CallInfo>
{
public UpdateCallStateMessage(CallInfo callInfo) : base(callInfo)
{
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using CommunityToolkit.Mvvm.Messaging.Messages;
using libpjsua2.maui;

namespace pjsua2maui.Messages;

public class UpdateMediaCallStateMessage : ValueChangedMessage<CallInfo>
{
public UpdateMediaCallStateMessage(CallInfo callInfo) : base(callInfo)
{
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
namespace pjsua2maui.Models;

/* Interface to separate UI & engine a bit better */
public interface ISoftObserver
{
void notifyRegState(int code, String reason, long expiration);
void notifyIncomingCall(SoftCall call);
void notifyCallState(SoftCall call);
void notifyCallMediaState(SoftCall call);
void notifyBuddyState(SoftBuddy buddy);
void notifyChangeNetwork();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using libpjsua2.maui;

namespace pjsua2maui.Models;

public class SoftAccount : Account
{
public List<SoftBuddy> buddyList = new List<SoftBuddy>();
public AccountConfig cfg;

~SoftAccount()
{
Console.WriteLine("*** Account is being deleted");
}

public SoftAccount(AccountConfig config)
{
cfg = config;
}

public SoftBuddy addBuddy(BuddyConfig bud_cfg)
{
/* Create Buddy */
SoftBuddy bud = new SoftBuddy(bud_cfg);
try
{
bud.create(this, bud_cfg);
}
catch (Exception)
{
bud.Dispose();
}

if (bud != null)
{
buddyList.Add(bud);
if (bud_cfg.subscribe)
try
{
bud.subscribePresence(true);
}
catch (Exception) { }
}

return bud;
}

public void delBuddy(SoftBuddy buddy)
{
buddyList.Remove(buddy);
buddy.Dispose();
}

override public void onRegState(OnRegStateParam prm)
{
AccountInfo ai = getInfo();
Console.WriteLine("***" + (ai.regIsActive ? "" : "Un") +
"Register: code=" + prm.code);

SoftApp.observer.notifyRegState((int)prm.code, prm.reason, prm.expiration);
}

override public void onIncomingCall(OnIncomingCallParam prm)
{
Console.WriteLine("======== Incoming call ======== ");
SoftCall call = new SoftCall(this, prm.callId);
SoftApp.observer.notifyIncomingCall(call);
}

override public void onInstantMessage(OnInstantMessageParam prm)
{
Console.WriteLine("======== Incoming pager ======== ");
Console.WriteLine("From : " + prm.fromUri);
Console.WriteLine("To : " + prm.toUri);
Console.WriteLine("Contact : " + prm.contactUri);
Console.WriteLine("Mimetype : " + prm.contentType);
Console.WriteLine("Body : " + prm.msgBody);
}
}
Loading