') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - infitio/flutter_socket_io: Socket IO supprt for flutter. Looking for contributors Swift and Java. · GitHub
Skip to content

Repository files navigation

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

finalSOCKET_SERVER='http://192.168.1.2:7070/';	//To be modified accordinglySocketIO socket;
StreamSubscription connectSubscription;
StreamSubscription echoSubscription;
Future<void> demonstrateSocket() async {
// Create a socket instance
socket =awaitSocketIOManager().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 errorawait socket.connectSync();
// publish data - will publish to server, won't ensure the deliveryawait socket.emit('echo', ['hello']);
// emit with acknowledgement - will publish to server// and ensure delivery with ack if ack is implemented in serverdynamic ackData =await socket.emitWithAck('echo', ['hello']);
print('acknowledgement recieved from server: $ackData');
}
Future<void> dispose() async {
// cancel echo and onConnect subscriptionsawait echoSubscription.cancel();
await connectSubscription.cancel();
// clear socket instance from managerawaitSocketIOManager().clearInstance(socket);
}
// register liteners, connect to a socket, and publish datademonstrateSocket();
// will dispose listeners and socketdispose();

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:

    constStringURI="http://192.168.1.2:7000/";
    constStringURI="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:

<applicationandroid:name="io.flutter.app.FlutterApplication"android:label="adhara_socket_io_example"android:usesCleartextTraffic="true"android:icon="@mipmap/ic_launcher">
<activityandroid: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

About

Socket IO supprt for flutter. Looking for contributors Swift and Java.

Topics

Resources

Stars

190 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages