hangyeol_channel 0.0.7 copy "hangyeol_channel: ^0.0.7" to clipboard
hangyeol_channel: ^0.0.7 copied to clipboard

easy channel connect implementation util.

Easy channel connect implementation util

Features #

onData() 만 override하면 끝!

Getting started #

  1. HangyeolChannelInterface 클래스를 상속받은 클래스 작성
  2. onData 메서드 event객체에 통신 내용이 들어온다. 로직을 작성하자
  3. 클래스 인스턴스를 만들고 .connet() 하면 연결 완료

Usage #

  • 클래스 정의
class SampleChannel extends HangyeolChannelInterface {
  SampleChannel({
    required String url,
    required Map<String, Object> payload,
  }) : super(url, payload);

  @override
  Future<void> onData(ChannelEvent event, IOWebSocketChannel channel) async {
    switch (event.type) {
      case 'request':
        channel.sink.add(encode('response', {'key': 'value'}));
        break;
    }
  }
}

  • 사용
final channel = SampleChannel(
    url: 'your host', payload: {'required': 'values', 'on every': 'send'});

channel.connect();
channel.add('send', {'key': 'value'});
channel.exit();
  • logging
class LogingChannel extends HangyeolChannelInterface {
    ...

    @override
    void log(Map<String, dynamic> event){
        // your logging stratage;
        // defualt : print(event);
    }
}


final channel = LogingChannel(
    url: 'your host', 
    payload: {'required': 'values', 'on every': 'send'},
    logging: true,
);

1
likes
130
pub points
0%
popularity

Publisher

unverified uploader

easy channel connect implementation util.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, web_socket_channel

More

Packages that depend on hangyeol_channel