Giter Club home page Giter Club logo

swift-nio-irc-webclient's Introduction

SwiftNIO IRC Web Client

Swift4 Swift5 macOS tuxOS

This is a very simple WebSocket based IRC WebClient/Server.

It contains a small chat-webapp as the frontend (a single-page webapp written in plain JavaScript, not frameworks), it contains a WebSocket/IRC bridge using the SwiftNIO IRC client module, and a small HTTP server which delivers the webapp and serves as a websocket endpoint.

This WebClient is a regular Swift package and can be imported in other Swift servers!

What it looks like

On the surface it is a very simple chat webapp, with basic support for channels and direct messages:

Sometimes a live demo installation is running on http://irc.noze.io/. We probably have to shut it down once abuse starts to take place :-) If it doesn't run and you want to play with it, just install it locally, it is a matter of minutes using MiniIRCd.

Overview

Swift NIO Parts

This module contains the middlepart, the webserver. It serves two purposes:

  1. Deliver the client side (JavaScript) webapp to the browser (single page, HTML + CSS + JS).
  2. Server as an HTTP endpoint for the WebSocket connection. If the JS webapp creates a WebSocket connection, it'll contact the HTTP server, which will then upgrade the HTTP connection to the WebSocket protocol.
                            ┌───────────────────────┐
               HTML         │  ┌─────────────────┐  │
        ┌───────JS──────────┼──│ NIO HTTP Server │  │
        │                   │  └─────────────────┘  │
        │                   │           │           │
        ▼                   │       Upgrades        │
┌──────────────┐            │      Connection       │
│              │            │           │           │
│  WebBrowser  │            │           ▼           │       ┌──────────────┐
│              │  WebSocket │  ┌─────────────────┐  │       │              │
│  JavaScript  │◀────JSON───┼─▶│  NIO WebSocket  │◀─┼─IRC──▶│  IRC Server  │
│    WebApp    │            │  └─────────────────┘  │       │              │
│              │            │       WebServer       │       └──────────────┘
└──────────────┘            └───────────────────────┘

JavaScript Client

The JavaScript web app is embedded into the compiled Swift module (using a Makefile all the resources are bundled together into a single Swift source file). Yet it also works as a standalone web application (you can drag the Client.html into your browser.

The client app is located in Sources/IRCWebClient/WebApp.

Importing the module using Swift Package Manager

An example Package.swift importing the necessary modules:

// swift-tools-version:5.0

import PackageDescription

let package = Package(
    name: "MyOwnIRCServer",
    dependencies: [
        .package(url: "https://github.com/NozeIO/swift-nio-irc-webclient.git",
                 from: "0.7.0")
    ],
    targets: [
        .target(name: "MyIRCServer",
                dependencies: [ "IRCServer", "IRCWebClient" ])
    ]
)

Using the Server

let webServer = IRCWebClientServer()
webServer.listen()

Check the Configuration object for the supported configuration options.

One can configure three connection parameters:

  1. host/port - this is the address the HTTP server is running on
  2. ircHost/port - this is the address of the IRC server
  3. externalHost/port - the address the browser is using to connect to the HTTP server. Often but not necessarily the same like 1.

Who

Brought to you by ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.

swift-nio-irc-webclient's People

Contributors

helje5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

swift-nio-irc-webclient's Issues

Support Markdown in messages

Would be really great to support markdown in the chat messages. Would be OK to add another javascript library for this (a small one).

Add a way to close direct chats

Currently we have no way to close a direct message conversation (called a query in IRC). Maybe the sidebar should get close buttons (shown on hover?) for both, channels and queries.

Enhance UI to show channel members

When a channel is joined, the server does send a list of channel members.

Those need to be transferred by the bridge, and somehow displayed by the web client.

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.