Coder Social home page Coder Social logo

askmetoo / katari Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dewarner/katari

0.0 0.0 0.0 153 KB

Katari - SIP (Session Initiated Protocol) Application Framework

License: BSD 3-Clause "New" or "Revised" License

Python 99.65% Shell 0.35%

katari's Introduction

alt text

Katari - SIP (Session Initiated Protocol) Application Framework

PyPI pyversions PyPI version shields.io PyPI license PyPI version shields.io

Documentation

https://katari.readthedocs.io/en/latest/

Installing

pip install Katari 

Installing from Git

pip install git+https://github.com/hyperioxx/Katari.git

Getting Started

to create a katari project run the following command in your terminal

katari --build-app <project name>

app.py

import settings
from Katari import KatariApplication
from Katari.sip.response import ResponseFactory

app = KatariApplication(settings=settings)

@app.invite()
def do_invite(request, client):
    # add INVITE logic here 
    response = ResponseFactory.build(200) # 200 OK
    app.send(request.create_response(response), client)

@app.register()
def do_register(request, client):
    # add REGISTER logic here 
    response = ResponseFactory.build(401) # 401 unauthorized 
    app.send(request.create_response(OK200()), client)

@app.options()
def do_options(request, client):
    # add OPTIONS logic here 
    response = ResponseFactory.build(200) # 200 OK
    app.send(request.create_response(response), client)

@app.info()
def do_info(request, client):
    # add INFO logic here 
    response = ResponseFactory.build(200) # 200 OK
    app.send(request.create_response(response), client)

if __name__ == "__main__":   
    app.run()

Writing your own middleware

create a directory called middleware within your project

myproject -
   - app.py
   - settings.py
   - middleware   << LIKE THIS 
     - __init__.py
     - test.py

your middleware can modify the sip message before it reaches your main logic using the process_request method and also modify the response before it gets sent back to the client using process response method.

Example

test.py

from Katari.interfaces import MiddlewareInterface

class Test(MiddlewareInterface):
    
    def process_request(self, message):
        print(str(message))
        return message

    
    def process_response(self, message):
        print(str(message))
        return message

settings.py

"""
##    ##    ###    ########    ###    ########  ####
##   ##    ## ##      ##      ## ##   ##     ##  ##
##  ##    ##   ##     ##     ##   ##  ##     ##  ##
#####    ##     ##    ##    ##     ## ########   ##
##  ##   #########    ##    ######### ##   ##    ##
##   ##  ##     ##    ##    ##     ## ##    ##   ##
##    ## ##     ##    ##    ##     ## ##     ## ####

SIP (Session Initiated Protocol) Application Framework

"""

HOST = "127.0.0.1" #Specify interface to listen on 

PORT = 5060 # Specify port to listen on

ALLOWED_HOSTS = ["127.0.0.1"] # Katari whitelist

USER_AGENT = "Katari Server 0.0.6" # User Agent sent in response 

# Logging settings
KATARI_LOGGING = {
                   "LOGFILE" :"Katari.log",
                   "LEVEL": "INFO", 
                   "OUTPUTMODE": "file"
                 }

# Katari middleware 
KATARI_MIDDLEWARE = [
    'middleware.test',   # Add import path here
    
]

katari's People

Contributors

hyperioxx avatar dewarner avatar wickedgenius avatar

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.