1.0.23 • Published 6 years ago

luffy-echo v1.0.23

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

luffy-echo

获取socket消息

安装

npm install lufyy-echo

使用

初始化

import {Echo} from 'luffy-echo';

window.Echo = new Echo('a82393d886a0e6ddfae5', {
    host: 'ws://10.202.203.222:8091',
    auth: {
        url: 'http://tests.test/api/pusher/auth',
        headers: {
            'Accept': 'application/json',
            'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC90ZXN0cy50ZXN0XC9hcGlcL3B1c2hlclwvYXV0aCIsImlhdCI6MTUzOTE2ODAwMSwiZXhwIjoxNTM5MTcxNjAxLCJuYmYiOjE1MzkxNjgwMDEsImp0aSI6IktMOHdsMG9Gb2FNZzA3UHkiLCJzdWIiOjEsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.nuSaYl3mvmTx-5YRQEviMqpry6gt-tWZig1gho-jlC4',
        },
        params: {}
    },
})

###公共频道示例

Echo.channel('order').listen('new', (e) => {
    console.log(e);
}).listen('send', (e) => {
    console.log(e);
  });

###private频道示例

Echo.private('order.1').listen('new', (e) => {
    console.log(e);
}).listen('send', (e) => {
    console.log(e);
});

###presence频道示例

window.Echo.join(`chat.1`)
    .here((users) => {
        console.log('全部人员');
        console.log(users)
    })
    .joining((user) => {
        console.log('新人加入');
        console.log(user);
    })
    .leaving((user) => {
        console.log('有人退出');
        console.log(user);
    }).listen('NewMessage', (e) => {
    console.log(e);
});

###客户端事件 广播一个事件给其它已经连接的客户端

whisper 方法来广播客户端事件

Echo.private('chat')
    .whisper('typing', {
        name: this.user.name
    });

你可以使用 listenForWhisper 方法来监听客户端事件:

Echo.private('chat')
    .listenForWhisper('typing', (e) => {
        console.log(e.name);
    });

###订阅方法

    Echo.subscribe('order');
    Echo.subscribe('private-order');
    Echo.subscribe('presence-order');

###示意图 Image text

###socket服务配置 https://github.com/woguolufei/echo/blob/master/doc/socket.md

License

ISC license.

1.0.23

6 years ago

1.0.22

6 years ago

1.0.20

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago