Skip to content

Flutter app does not receive Events fired from Laravel Soketi server  #12

Description

@mwangaben

Please assist on where do i go wrong on the Flutter app testing on the Google pixel mobile phone using common Ip address
My ip is 192.168.0.102

Soketi configurations

{
adapter: {
 driver: 'local',
 redis: {
   requestsTimeout: 5000,
   prefix: '',
   redisPubOptions: {},
   redisSubOptions: {},
   clusterMode: false
 },
 cluster: { requestsTimeout: 5000 },
 nats: {
   requestsTimeout: 5000,
   prefix: '',
   servers: [ '127.0.0.1:4222' ],
   user: null,
   pass: null,
   token: null,
   timeout: 10000,
   nodesNumber: null
 }
},
appManager: {
 driver: 'array',
 cache: { enabled: false, ttl: -1 },
 array: {
   apps: [ { id: 'app-id', key: 'app-key', secret: 'app-secret' } ]
 },
 dynamodb: { table: 'apps', region: 'us-east-1', endpoint: null },
 mysql: { table: 'apps', version: '8.0', useMysql2: false },
 postgres: { table: 'apps', version: '13.3' }
},
cache: { driver: 'memory', redis: { redisOptions: {}, clusterMode: false } },
channelLimits: { maxNameLength: 200, cacheTtl: 3600 },
cluster: {
 hostname: '0.0.0.0',
 helloInterval: 500,
 checkInterval: 500,
 nodeTimeout: 2000,
 masterTimeout: 2000,
 port: 11002,
 prefix: '',
 ignoreProcess: true,
 broadcast: '255.255.255.255',
 unicast: null,
 multicast: null
},
cors: {
 credentials: true,
 origin: [ '*' ],
 methods: [ 'GET', 'POST', 'PUT', 'DELETE', 'OPTIONS' ],
 allowedHeaders: [
   'Origin',
   'Content-Type',
   'X-Auth-Token',
   'X-Requested-With',
   'Accept',
   'Authorization',
   'X-CSRF-TOKEN',
   'XSRF-TOKEN',
   'X-Socket-Id'
 ]
},
database: {
 mysql: {
   host: '127.0.0.1',
   port: 3306,
   user: 'root',
   password: 'password',
   database: 'main'
 },
 postgres: {
   host: '127.0.0.1',
   port: 5432,
   user: 'postgres',
   password: 'password',
   database: 'main'
 },
 redis: {
   host: '127.0.0.1',
   port: 6379,
   db: 0,
   username: null,
   password: null,
   keyPrefix: '',
   sentinels: null,
   sentinelPassword: null,
   name: 'mymaster',
   clusterNodes: []
 }
},
databasePooling: { enabled: false, min: 0, max: 7 },
debug: true,
eventLimits: {
 maxChannelsAtOnce: 100,
 maxNameLength: 200,
 maxPayloadInKb: 100,
 maxBatchSize: 10
},
host: '192.168.0.102',
httpApi: { requestLimitInMb: 100, acceptTraffic: { memoryThreshold: 85 } },
instance: { process_id: 31230 },
metrics: {
 enabled: false,
 driver: 'prometheus',
 host: '0.0.0.0',
 prometheus: { prefix: 'soketi_' },
 port: 9601
},
mode: 'full',
port: 6002,
pathPrefix: '',
presence: { maxMembersPerChannel: 100, maxMemberSizeInKb: 2 },
queue: {
 driver: 'sync',
 redis: { concurrency: 1, redisOptions: {}, clusterMode: false },
 sqs: {
   region: 'us-east-1',
   endpoint: null,
   clientOptions: {},
   consumerOptions: {},
   queueUrl: '',
   processBatch: false,
   batchSize: 1,
   pollingWaitTimeMs: 0
 }
},
rateLimiter: { driver: 'local', redis: { redisOptions: {}, clusterMode: false } },
shutdownGracePeriod: 3000,
ssl: { certPath: '', keyPath: '', passphrase: '', caPath: '' },
userAuthenticationTimeout: 30000,
webhooks: { batching: { enabled: false, duration: 50 } }
}
📡 soketi initialization....
⚡ Initializing the HTTP API & Websockets Server...
⚡ Initializing the Websocket listeners and channels...
⚡ Initializing the HTTP webserver...
🕵️‍♂️ Initiating metrics endpoints...

🎉 Server is up and running!
📡 The Websockets server is available at 127.0.0.1:6002
🔗 The HTTP API server is available at http://127.0.0.1:6002
🎊 The /usage endpoint is available on port 9601.

(node:31230) NOTE: The AWS SDK for JavaScript (v2) is in maintenance mode.
SDK releases are limited to address critical bug fixes and security issues only.

Please migrate your code to use AWS SDK for JavaScript (v3).
For more information, check the blog post at https://a.co/cUPnyil
(Use `node --trace-warnings ...` to show where the warning was created)
[Mon Nov 04 2024 22:01:40 GMT+0300 (East Africa Time)] Promoted from node to master.
{
isMaster: true,
isMasterEligible: true,
weight: -0.1730746900058,
address: '127.0.0.1',
advertisement: undefined
}


Flutter Code

import 'package:block101/http/app_store.dart';
import 'package:laravel_echo_null/laravel_echo_null.dart';
import 'package:pusher_client_socket/pusher_client_socket.dart' as PUSHER;


const String host ='192.168.0.102';
const int wsPort = 6002;
const String key = "app-key";
const String hostAuthEndPoint = "http://192.168.0.102/broadcasting/auth";

Echo<PUSHER.PusherClient, PusherChannel> echo = Echo.pusher(
  key,
  authEndPoint: hostAuthEndPoint, // String?: auth host
  authHeaders: { // authenticate headers
    'Authorization': 'Bearer ${AppStore.getAccessToken()}',
    'Content-Type': 'application/json',
    'Accept': 'application/json',
  },
  // cluster: 'PUSHER_CLUSTER', // String?: pusher cluster
  host: host,
  wsPort: wsPort,
  wssPort: 443,
  encrypted: false,
  activityTimeout: 120000,
  pongTimeout: 30000,
  // maxReconnectionAttempts: 6,
  reconnectGap: const Duration(seconds: 2),
  enableLogging: true,
  autoConnect: false, // bool: client connection automatically
  nameSpace: 'App\\Events',
);

Flutter code that listen from the sever events

class PostsView extends StatefulWidget {
  const PostsView({super.key});

  @override
  State<PostsView> createState() => _PostsViewsState();
}

class _PostsViewsState extends State<PostsView> {
  void fetchPost() {
    final postCubit = context.read<PostCubit>();

    postCubit.fetchPosts();
  }

  @override
  void initState() {
    // fetchPost();

    Channel publicChannel = echo.channel('comments');
    publicChannel.listen('CommentCreated', (data){
      log('on log $data');
      print('on print $data');
    });

    super.initState();
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions