sockjs_client_wrapper 1.0.2 copy "sockjs_client_wrapper: ^1.0.2" to clipboard
sockjs_client_wrapper: ^1.0.2 copied to clipboard

outdatedDart 1 only

A Dart wrapper for the `sockjs-client` JS library.

example/main.dart

// Copyright 2017 Workiva Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:async';

import 'package:sockjs_client_wrapper/sockjs_client_wrapper.dart';

Future<Null> main() async {
  print('Starting example');
  final echoUri = Uri.parse('http://localhost:9999/echo');
  final options = new SockJSOptions(
      transports: ['websocket', 'xhr-streaming', 'xhr-polling']);
  final socket = new SockJSClient(echoUri, options: options);

  socket.onOpen.listen((event) {
    print('OPEN: ${event.transport} ${event.url}');
  });

  socket.onMessage.listen((event) {
    print('MSG: ${event.data}');
  });

  socket.onClose.listen((event) {
    print('CLOSE: ${event.code} ${event.reason} (wasClean ${event.wasClean})');
  });

  await new Future<Null>.delayed(const Duration(milliseconds: 500));
  socket.send('test');

  await new Future<Null>.delayed(const Duration(milliseconds: 500));
  socket.send('test 2');

  await new Future<Null>.delayed(const Duration(seconds: 5));

  socket.close(4002);
}
0
likes
0
pub points
71%
popularity

Publisher

verified publisherworkiva.com

A Dart wrapper for the `sockjs-client` JS library.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

js, w_common

More

Packages that depend on sockjs_client_wrapper