# Copyright (C) 2019-2025 Savoir-faire Linux Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# This file is based on earlier work by Dani Llewellyn, under the
# Expat License (also referred to as "the MIT License"), per the
# following notice:

# Copyright (C) 2017-2020 Dani Llewellyn <dani@bowlhat.net>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


name: jami
version: "RELEASE_VERSION"
adopt-info: jami
icon: common/icons/jami.svg
license: GPL-3.0+
summary: 'Privacy-oriented voice, video, chat, and conference platform and SIP phone'
description: |
  Jami, a GNU package, is software for universal and distributed peer-to-peer communication that respects the freedom and privacy of its users.

  Jami is the simplest and easiest way to connect with people (and devices) with instant messaging, audio and video calls over the Internet and LAN/WAN intranets.

  Jami is a free/libre, end-to-end encrypted, and private communication platform.

  Jami – which used to be known as Ring – is also an open-source alternative (to Facebook Messenger, Signal, Skype, Teams, Telegram, TikTok, Viber, WhatsApp, Zoom) that prioritizes the privacy of its users.

  Jami has a professional-looking design and is available for a wide range of platforms. Unlike the alternatives, calls using Jami are directly between users as it does not use servers to handle calls.

  This gives the greatest privacy as the distributed nature of Jami means your calls are only between participants.

  One-to-one and group conversations with Jami are enhanced with: instant messaging; audio and video calling; recording and sending audio and video messages; file transfers; screen sharing; and, location sharing.

  Jami can also function as a SIP client.

  Jami has multiple extensions available: Audio Filter; Auto Answer; Green Screen; Watermark; and, Whisper Transcript.

  Jami can be easily deployed in organizations with the “Jami Account Management Server” (JAMS), allowing users to connect with their corporate credentials or create local accounts. JAMS allows you to manage your own Jami community while taking advantage of Jami’s distributed network architecture.

  Jami is available for GNU/Linux, Windows, macOS, iOS, Android, and Android TV, making Jami an interoperable and cross-platform communication framework.

  Manage multiple SIP accounts, Jami accounts and JAMS accounts with the Jami client installed on one or multiple devices.

  Jami is free, unlimited, private, advertising free, compatible, fast, autonomous, and anonymous.

  Learn more about:
  Jami: https://jami.net/
  Jami extensions: https://jami.net/extensions/
  “Jami Account Management Server” (JAMS): https://jami.biz/
  Jami documentation: https://docs.jami.net/

  Follow us for more:
  Mastodon: https://mstdn.io/@Jami
  X: https://x.com/jami_social
  YouTube: https://www.youtube.com/@jami9311

  We’d love to hear from you! Join the Jami community:
  Contribute: https://jami.net/contribute/
  Forum: https://forum.jami.net/

  Build with Jami on your IoT project: re-use the universal communications technology of Jami with its portable library on your system of choice.

  Jami for Android TV is tested on NVIDIA SHIELD TV with Logitech cameras.

  Jami is published under the GPL license, version 3 or higher.
  Copyright © Savoir-faire Linux Inc.

confinement: strict
grade: stable
base: core24

plugs:
  gnome-46-2404:
    interface: content
    target: $SNAP/gnome-platform
    default-provider: gnome-46-2404
  gtk-3-themes:
    interface: content
    target: $SNAP/data-dir/themes
    default-provider: gtk-common-themes:gtk-3-themes
  icon-themes:
    interface: content
    target: $SNAP/data-dir/icons
    default-provider: gtk-common-themes:icon-themes
  sound-themes:
    interface: content
    target: $SNAP/data-dir/sounds
    default-provider: gtk-common-themes:sounds-themes
  gpu-2404:
    interface: content
    target: $SNAP/gpu-2404
    default-provider: mesa-2404

slots:
  dbus-jami:
    interface: dbus
    bus: session
    name: net.jami.Jami
  dbus-ring:
    interface: dbus
    bus: session
    name: cx.ring.Ring

layout:
  /usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/alsa-lib:
    bind: $SNAP/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/alsa-lib
  /usr/share/alsa:
    bind: $SNAP/usr/share/alsa
  /usr/share/X11/xkb:
    bind: $SNAP/usr/share/X11/xkb
  /usr/share/X11/XErrorDB:
    symlink: $SNAP/gpu-2404/X11/XErrorDB

environment:
  QT_BASE_DIR: "/usr/lib/libqt-jami"
  LD_LIBRARY_PATH: "${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$SNAP$QT_BASE_DIR/lib:$SNAP/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR:$SNAP/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/pulseaudio:$SNAP/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/libproxy"

apps:
  jami:
    command: usr/bin/jami
    command-chain:
    - bin/gpu-2404-wrapper
    - bin/desktop-launch
    - snap/command-chain/alsa-launch
    - bin/jami-wrapper
    autostart: net.jami.Jami.desktop
    common-id: net.jami.Jami
    desktop: usr/share/applications/net.jami.Jami.desktop
    environment:
      PIPEWIRE_CONFIG_NAME: "$SNAP/usr/share/pipewire/pipewire.conf"
      PIPEWIRE_MODULE_DIR: "$SNAP/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/pipewire-0.3"
      SPA_PLUGIN_DIR: "$SNAP/usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/spa-0.2"
    slots:
    - dbus-jami
    - dbus-ring
    plugs:
    - alsa
    - audio-playback
    - audio-record
    - browser-support
    - camera
    - desktop
    - desktop-legacy
    - gsettings
    - hardware-observe
    - home
    - network
    - network-bind
    - network-manager
    - opengl
    - removable-media
    - screen-inhibit-control
    - system-observe
    - unity7
    - wayland
    - x11

package-repositories:
  - type: apt
    components: [main]
    suites: [jami]
    key-id: A295D773307D25A33AE72F2F64CD5FA175348F84
    url: https://dl.jami.net/internal/ubuntu_24.04/

parts:
  desktop-launch:
    source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
    plugin: nil
    build-packages:
    - dpkg-dev
    - gcc
    - g++
    - cmake
    - cmake-data
    - libqt-jami
    - devscripts
    - equivs
    override-pull: |
      craftctl default
      sed -i -E 's|\. \$SNAP/flavor-select|USE_gtk3=true|' gtk/launcher-specific
      sed -i -E 's|\. \$SNAP/flavor-select|USE_qt5=true|' qt/launcher-specific
      sed -i -E 's|(append_dir GTK_PATH \$RUNTIME/usr/lib/\$ARCH/gtk-2.0)|#\1|' qt/launcher-specific
      sed -i -E 's|\$RUNTIME|$SNAP|g' qt/launcher-specific
      sed -i -E 's|\$WITH_RUNTIME|no|g' qt/launcher-specific
    override-build: |
      craftctl default
      gcc -Wall -O2 -o bindtextdomain.so -fPIC -shared src/bindtextdomain.c -ldl

      echo "#!/bin/bash" > desktop-launch
      cat common/init >> desktop-launch

      cat qt/runtime-exports >> desktop-launch
      cat gtk/runtime-exports >> desktop-launch

      cat common/desktop-exports >> desktop-launch

      cat qt/launcher-specific >> desktop-launch
      cat gtk/launcher-specific >> desktop-launch

      cat common/mark-and-exec >> desktop-launch

      install -D -m755 desktop-launch $CRAFT_PART_INSTALL/bin/desktop-launch
      install -D -m644 bindtextdomain.so $CRAFT_PART_INSTALL/lib/bindtextdomain.so

      mkdir -pv $CRAFT_PART_INSTALL/gnome-platform

  scripts:
    plugin: dump
    source: common/scripts
    organize:
      jami-wrapper: bin/jami-wrapper

  alsa-mixin:
    plugin: dump
    source: https://github.com/diddlesnaps/snapcraft-alsa.git
    source-subdir: snapcraft-assets
    stage:
      - -usr/lib/x86_64-linux-gnu/libp11-kit.so*
      - -usr/lib/x86_64-linux-gnu/libproxy.so*
      - -usr/share/doc/libp11-kit0/changelog.Debian.gz
      - -usr/share/doc/libproxy1v5/changelog.Debian.gz
      - -usr/lib/x86_64-linux-gnu/gio/modules/libdconfsettings.so
      - -usr/lib/x86_64-linux-gnu/libdconf.so.1.0.0
      - -usr/libexec/dconf-service
      - -usr/share/doc/libdconf1/changelog.Debian.gz
      - -usr/share/man/man1/dconf-service.1.gz
    build-packages:
      - libasound2-dev
    stage-packages:
      - libasound2t64
      - libasound2-plugins
      - yad

  jami:
    after: [alsa-mixin]
    source: .
    plugin: nil
    parse-info: [usr/share/metainfo/net.jami.Jami.metainfo.xml]
    stage:
      - -usr/lib/x86_64-linux-gnu/liblber-2.4.so*
      - -usr/lib/x86_64-linux-gnu/libldap_r-2.4.so*
      - -usr/share/doc/libldap-2.4-2/changelog.Debian.gz
      - -usr/share/doc/libldap-common/changelog.Debian.gz
    build-environment:
      - QT_BASE_DIR: "/usr/lib/libqt-jami"
      - PATH: "$QT_BASE_DIR/bin:$PATH"
      - LD_LIBRARY_PATH: "$QT_BASE_DIR/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
      - PKG_CONFIG_PATH: "$QT_BASE_DIR/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
    override-pull: |
      ls
      craftctl default
      sed -i -E 's|(tmpName) << (PACKAGE_NAME << "_shm_")|\1 << "snap.jami." << \2|' ./daemon/src/media/video/sinkclient.cpp
      sed -i -E 's|^Icon=.*|Icon=${SNAP}/usr/share/icons/hicolor/scalable/apps/net.jami.Jami.svg|' extras/data/net.jami.Jami.desktop
    override-build: |
      mkdir -p build
      cd build
      cmake .. -DENABLE_LIBWRAP=true \
               -DLIBJAMI_BUILD_DIR=$CRAFT_PART_BUILD/daemon/src \
               -DCMAKE_INSTALL_PREFIX=/usr \
               -DCMAKE_BUILD_TYPE=Release \
               -DCMAKE_PREFIX_PATH=$QT_BASE_DIR \
               -DBUILD_VERSION=BUILD_VERSION_PLACEHOLDER \
               -DBUILD_TESTING=Off
      make -j$CRAFT_PARALLEL_BUILD_COUNT
      DESTDIR=$CRAFT_PART_INSTALL make install
    build-packages:
    - autoconf
    - automake
    - autopoint
    - bzip2
    - cmake
    - curl
    - gcc
    - g++
    - gettext
    - gzip
    - libnotify-dev
    - libpipewire-0.3-dev
    - libspeex-dev
    - python3
    - python3-dev
    - uuid-dev
    - yasm
    - wget
    - nasm # ffmpeg
    - libva-dev
    - libvdpau-dev
    - libargon2-dev # opendht
    - libexpat1-dev
    - libjsoncpp-dev
    - libnm-dev # connectivityChanged()
    - libsystemd-dev # sdbus-cpp
    - libpulse-dev # pulse
    - libudev-dev
    - libopus-dev # Avoid to build opus from contrib
    - libglu1-mesa-dev # Qt 6
    - zlib1g-dev
    - libgl-dev
    - libvulkan-dev
    - libxkbcommon-dev
    - libgnutls28-dev # TLS
    - libssl-dev
    stage-packages:
    - libgnutls30
    - libdouble-conversion3
    - libgbm1
    - libjsoncpp25
    - libminizip1t64
    - libnm0
    - libnotify4
    - libnspr4
    - libnss3
    - libopus0
    - libpcre2-8-0
    - pipewire-bin
    - libqt-jami
    - libsnappy1v5
    - libspeex1
    - libproxy1v5
    - libwebpdemux2
    - libwebpmux3
    - libxkbfile1
    - libxtst6
    prime:
    - -usr/lib/libqt-jami/bin/
    - -usr/lib/libqt-jami/docs/
    - -usr/lib/libqt-jami/examples/
    - -usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/libLLVM-*.so*
    - -usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/libclang-*.so*
    - -usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/libflite*.so*

  gpu-2404:
    after: [jami]
    source: https://github.com/canonical/gpu-snap.git
    plugin: dump
    override-prime: |
      craftctl default
      ${CRAFT_PART_SRC}/bin/gpu-2404-cleanup mesa-2404
      # Workaround for https://bugs.launchpad.net/snapd/+bug/2055273
      mkdir -p "${CRAFT_PRIME}/gpu-2404"
    prime:
    - bin/gpu-2404-wrapper