Giter VIP home page Giter VIP logo

signalrminiprogram-client's Introduction

博客园博文地址 https://www.cnblogs.com/LiangSW/p/9415246.html

SignalRMiniProgram

AspNet Core SignalR 微信小程序客户端

效果演示

### Get Started

创建对象

let hub  = new HubConnection();

开启连接

hub.start(url,queryString);
例如
hub.start(url,{
    access_token:"bearer token"
});

事件

//连接开启事件
hub.onOpen = (res)={
    console.log("连接已开启")
};

//连接关闭事件
hub.onClose = (res)={
    console.log("连接已关闭")
};

//通讯过程中的Error事件
hub.onError = (res) =>{
    console.log(res)
};

//手动关闭连接
hub.close({reason:"手动关闭"});

调用服务端方法(无返回值)

hub.send(methodName,agrs...);

调用服务端方法(有返回值)

//该方法会返回一个Promise
hub.invoke(methodName,agrs...).then((res)=>{
    console.log("返回值:"+ res);
});

注册客户端方法供服务端调用

//该方法会返回一个Promise
hub.on("clientMethod",(res)=>{
    console.log("被服务端调用");
})

signalrminiprogram-client's People

Contributors

realliangshiwei 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.