Giter Club home page Giter Club logo

sockjs's Introduction

SockJS server Build Status codecov crates.io

SockJS server for Actix framework.


Actix SockJS is licensed under the Apache-2.0 license.

Usage

To use sockjs, add this to your Cargo.toml:

[dependencies]
sockjs = "0.2"

Supported transports

Simple chat example

extern crate actix;
extern crate actix_web;
extern crate sockjs;

use actix_web::*;
use actix::prelude::*;
use sockjs::{Message, Session, CloseReason, SockJSManager, SockJSContext};

struct Chat;

/// `SockJSContext` context is required for sockjs session
impl Actor for Chat {
    type Context = SockJSContext<Self>;
}

/// Session has to implement `Default` trait
impl Default for Chat {
    fn default() -> Chat { Chat }
}

/// Sockjs session trait
impl Session for Chat {
    fn opened(&mut self, ctx: &mut SockJSContext<Self>) {
        ctx.broadcast("Someone joined.")
    }
    fn closed(&mut self, ctx: &mut SockJSContext<Self>, _: CloseReason) {
        ctx.broadcast("Someone left.")
    }
}

/// Session has to be able to handle `sockjs::Message` messages
impl Handler<Message> for Chat {
    type Result = ();

    fn handle(&mut self, msg: Message, ctx: &mut SockJSContext<Self>)
    {
        // broadcast message to all sessions
        ctx.broadcast(msg);
    }
}


fn main() {
    let sys = actix::System::new("sockjs-chat");

    // SockJS sessions manager
    let sm: Addr<Syn, _> = SockJSManager::<Chat>::start_default();

    HttpServer::new(move || {
        let manager = sm.clone();
        Application::new()
            // register SockJS application
            .handler(
                "/sockjs/", sockjs::SockJS::new(manager.clone()))})
        .bind("127.0.0.1:8080").unwrap()
        .start();

    // let _ = sys.run();
}

Full chat example

sockjs's People

Contributors

comerc avatar fafhrd91 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sockjs's Issues

`()` doesn't implement `std::fmt::Display`

rustc 1.26.0 (a77568041 2018-05-07)
error[E0277]: `()` doesn't implement `std::fmt::Display`
  --> /Users/intellild/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/sockjs-0.3.0/src/transports/xhrsend.rs:89:49
   |
89 |                                             Err(error::ErrorNotFound(())),
   |                                                 ^^^^^^^^^^^^^^^^^^^^ `()` cannot be formatted with the default formatter; try using `:?` instead if you are using a format string
   |
   = help: the trait `std::fmt::Display` is not implemented for `()`
   = note: required by `actix_web::error::ErrorNotFound`

error[E0277]: `()` doesn't implement `std::fmt::Display`
   --> /Users/intellild/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/sockjs-0.3.0/src/transports/jsonp.rs:271:49
    |
271 |                                             Err(error::ErrorNotFound(())),
    |                                                 ^^^^^^^^^^^^^^^^^^^^ `()` cannot be formatted with the default formatter; try using `:?` instead if you are using a format string
    |
    = help: the trait `std::fmt::Display` is not implemented for `()`
    = note: required by `actix_web::error::ErrorNotFound`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `sockjs`.

error: multiple packages link to native library `ring-asm`, but a native library can be linked only once

Can't build with latest version of actix-web. Here is the error:

C:\Users\candronikos\Projects\project>cargo build
error: multiple packages link to native library `ring-asm`, but a native library can be linked only once

package `ring v0.13.2`
    ... which is depended on by `cookie v0.11.0`
    ... which is depended on by `actix-web v0.7.3`
    ... which is depended on by `project v0.1.0 (file:///C:/Users/candronikos/Projects/project)`
links to native library `ring-asm`

package `ring v0.12.1`
    ... which is depended on by `cookie v0.10.1`
    ... which is depended on by `actix-web v0.5.8`
    ... which is depended on by `sockjs v0.3.0`
    ... which is depended on by `project v0.1.0 (file:///C:/Users/candronikos/Projects/project)`
also links to native library `ring-asm`

I would like to contribute

Hey there, I would like to contribute to this project, although I'm relatively new to rust but if anyone can point me to the right direction towards how to go about upgrading it to the latest actix-web would be a good start.
I'm at your disposal ๐Ÿคฃ
Thanks

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.