패키지, 저장소 및 앱 카테고리 검색

GitHub 저장소infitio/flutter_socket_io

flutter_socket_io

플러터용 소켓 IO 지원. 스위프트 및 자바 기여자를 찾고 있습니다.

flutter_socket_io 프로젝트 이미지
스타
190
포크
111
최근 푸시(UTC)
2024. 8. 9.
프로젝트 상태
활성

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

adhara_socket_io

.github/workflows/flutter_integration.yaml

socket.io for flutter by adhara

supports both Android and iOS

socket.io version supported: v2 development in progress for v3 and v4

If you are using v3/v4 socket on server side, you may face connection issues, please downgrade and try in such scenario.

Usage:

See example/lib/main.dart for more detailed example

	final SOCKET_SERVER = 'http://192.168.1.2:7070/';	//To be modified accordingly
        SocketIO socket;
	StreamSubscription connectSubscription;
	StreamSubscription echoSubscription;

	Future<void> demonstrateSocket() async {
    	// Create a socket instance
		socket = await SocketIOManager().createInstance(
        	SocketOptions(SOCKET_SERVER),
        );

	// Listen to socket connect event
	subscription = socket.onConnect.listen((data){
	  print('connected: $data');
	  socket.emit('message', ['Hello world!']);
	});

        // Listen to an custom ("news") event
	echoSubscription = socket.on('echo', (data){
  	    print("news event recieved with data: $data");
	});

	// There are 2 ways to connect to socket server
	//  - normal: doesn't wait for connectio success
	//  - sync: ensures connection or errors out on failure

        // normal:
        //  connect to socket server - will initialize connection,
        //  but not ensure the connection yet.
        //  If this method used to connect to server, then emit events should be sent
        //  only after ensuring connection to socket server is successful by listening
        //  to onConnect events
	// await socket.connect();

	// sync:
        //  This API will ensure connection to server is successful
        //  or will throw error on connect error
        await socket.connectSync();

        // publish data - will publish to server, won't ensure the delivery
	await socket.emit('echo', ['hello']);

        // emit with acknowledgement - will publish to server
        //  and ensure delivery with ack if ack is implemented in server
        dynamic ackData = await socket.emitWithAck('echo', ['hello']);
            print('acknowledgement recieved from server: $ackData');
    	}

	Future<void> dispose() async {
	    // cancel echo and onConnect subscriptions
	    await echoSubscription.cancel();
	    await connectSubscription.cancel();

            // clear socket instance from manager
            await SocketIOManager().clearInstance(socket);
        }

	// register liteners, connect to a socket, and publish data
	demonstrateSocket();

	// will dispose listeners and socket
	dispose();

Running example:

  1. clone the project
  2. start socket server in the background
cd socket.io.server
npm i
./node_modules/.bin/pm2/ index.js
cd ../
  1. open example/lib/main.dart and edit the URI in #7 to point to your hosted/local socket server instances as mentioned step 2

    For example:

    const String URI = "http://192.168.1.2:7000/";
    
    const String URI = "http://mysite.com/";
    
  2. run example

cd example
flutter run

iOS support 📢📢

This project uses Swift for iOS support, please enable Swift support for your project for this plugin to work

Android support for SDK > 27

Configure android:usesCleartextTraffic="true" as a property of <application ...> tag in android/app/src/main/AndroidManifest.xml

For example:


<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="adhara_socket_io_example"
        android:usesCleartextTraffic="true"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"...>...</activity>
        ...
</application>

Refer to discussion here

Running tests

This plugin uses flutter driver to run integration tests tests. Use below command to run integration tests on Android/iOS

sh bin/run_tests.sh

Sample Video - Running the example

Running adhara socket io for flutter, example

FAQ's

AdharaSocketIoPlugin.m:2:9: fatal error: 'adhara_socket_io/adhara_socket_io-Swift.h' file not found

add use_frameworks! to your Podfile as in the example https://github.com/infitio/flutter_socket_io/blob/master/example/ios/Podfile#L30

Read more about this: discussion

Other Packages:

Feel free to checkout our Adhara package

infitio GitHub avatar
GitHub 작성자

infitio ↗

언어DartJavaSwiftObjective-CRubyJavaScriptHTMLShellKotlin

분류

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 2 개

  • flutter{"sdk":"flutter"}
  • pedantic^1.9.2

프로젝트에 맞는 저장소를 선택하려면?

사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.

  1. 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
  2. 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
  3. 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.

출처 및 관리

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗