Comments (34)
How to receive messages? it seems, there is not receiveMessageHandler like ios native sample.
right?
I can't get messages OnMessage handler.
from centrifuge-mobile.
@tiandage here is an example for Go , for iOS, for Android
from centrifuge-mobile.
Hello @FZambia
I used config.json like this.
{
"secret": "secret",
"web": true,
"admin_password": "password",
"admin_secret": "secret",
"publish": true,
"presence": true,
"join_leave": true,
"watch": true,
"namespaces": [
{
"name": "public",
"anonymous": true,
"publish": true,
"watch": true,
"presence": true,
"join_leave": true,
"history_size": 10,
"history_lifetime": 30,
"recover": true
}
]
}
Then i can receive message in localhost admin. but I can't get message in other side.(pc or mobile app)
what am i wrong?
from centrifuge-mobile.
Sorry but I can't say what's wrong seeing just a Centrifugo config file, most probably your connection with Centrifugo was not successfully established for some reason - wrong token, wrong connection address maybe?
from centrifuge-mobile.
pubish is working fine. Only onMessage is not working fine.
I will share objective-c code.
#import <Centrifuge/Centrifuge.h>
#import "ViewController.h"
@interface ViewController ()<CentrifugeConnectHandler, CentrifugeDisconnectHandler, CentrifugeMessageHandler>
{
CentrifugeSub *sub;
}
@property (weak, nonatomic) IBOutlet UILabel *label;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_label.text = @"Connecting...";
CentrifugeCredentials *creds = CentrifugeNewCredentials(@"42", @"1488055494", @"", @"24d0aa4d7c679e45e151d268044723d07211c6a9465d0e35ee35303d13c5eeff");
NSString *url = @"ws://192.168.1.109:9000/connection/websocket";
CentrifugeClient *client = CentrifugeNew(url, creds, CentrifugeNewEventHandler(), CentrifugeDefaultConfig());
NSError *error = nil;
if (![client connect:&error]) {
if (error != nil) {
_label.text = @"Error on connect...";
}
}
CentrifugeSubEventHandler *subEventHandler = CentrifugeNewSubEventHandler();
[subEventHandler onMessage:self];
error = nil;
sub = [client subscribe:@"public:chat" events:subEventHandler error:&error];
if (error != nil) {
_label.text = @"Subscribe error";
}
NSString *data = @"{\"input\": \"hello\"}";
error = nil;
if (![sub publish:[data dataUsingEncoding:NSUTF8StringEncoding] error:&error]) {
if (error != nil) {
_label.text = @"Publish error";
}
}
}
- (void)onConnect:(CentrifugeClient *)p0 p1:(CentrifugeConnectContext *)p1 {
_label.text = [NSString stringWithFormat:@"Connected %@", p1.clientID];
}
- (void)onDisconnect:(CentrifugeClient *)p0 p1:(CentrifugeDisconnectContext *)p1 {
_label.text = [NSString stringWithFormat:@"Disconnected..."];
}
- (void)onMessage:(CentrifugeSub *)p0 p1:(CentrifugeMessage *)p1 {
_label.text = [NSString stringWithFormat:@"%@, %@", p0.channel, p1.data];
}
- (IBAction)clickedTest:(id)sender {
NSString *data = @"{\"input\": \"hello1234567\"}";
NSError *error = nil;
if (![sub publish:[data dataUsingEncoding:NSUTF8StringEncoding] error:&error]) {
if (error != nil) {
_label.text = @"Publish error";
}
}
}
from centrifuge-mobile.
Do onConnect
and onDisconnect
callbacks work in your case?
from centrifuge-mobile.
I have just checked, it doesnt' work
from centrifuge-mobile.
Then I think that most probably the problem is in how you register those callbacks. Of course this can be library problem but it worked for me when using Swift. I need some time to figure out how to properly register callbacks in Objective C
from centrifuge-mobile.
Could you share code where you also registering connect and disconnect callbacks - it can help me
from centrifuge-mobile.
Sorry, Above code is full code.
from centrifuge-mobile.
I never programmed in ObjC before but don't you need to write at least sth like this:
CentrifugeEventHandler *eventHandler = CentrifugeNewEventHandler();
[eventHandler onConnect:self];
[eventHandler onDisconnect:self];
CentrifugeClient *client = CentrifugeNew(url, creds, eventHandler, CentrifugeDefaultConfig());
To register connect and disconnect callbacks to event handler? I.e. the same as you do for subscription message handler
from centrifuge-mobile.
I think, this is correct for objective-c
@interface ViewController ()<CentrifugeEventHandler, ....>
... ...
[eventHandler setDelegate:self]
... ...
- (void)onConnect:(CentrifugeClient *)p0 p1:(CentrifugeConnectContext *)p1 {
_label.text = [NSString stringWithFormat:@"Connected %@", p1.clientID];
}
- (void)onDisconnect:(CentrifugeClient *)p0 p1:(CentrifugeDisconnectContext *)p1 {
_label.text = [NSString stringWithFormat:@"Disconnected..."];
}
from centrifuge-mobile.
onMessage is also same...
delegate must be registed into object...
CentrifugeSubEventHandler *subEventHandler = CentrifugeNewSubEventHandler();
[subEventHandler setDelegate:self];
from centrifuge-mobile.
Does it work now?
from centrifuge-mobile.
no, sir. there is not delegate in your current project.
from centrifuge-mobile.
Hmm, I am almost sure that the problem here is just to find a way to properly register callbacks, looks like I need to dive a bit into ObjectiveC then to say how to do this using this bindings.
from centrifuge-mobile.
Currently onMessage function is calling one time in the first. because there is not delegate to get callback.
from centrifuge-mobile.
okay sir. Looking forward to hearing from you soon.
from centrifuge-mobile.
Hello, @FZambia
Please check swift ios project on your actual device. Simulator is working fine, but actual device has one below issue.
clang: error: linker command failed with exit code 1 (use -v to see invocation)
from centrifuge-mobile.
@tiandage thanks for pointing - I'll find a way to check it out, I tested on real Android device only yet.
from centrifuge-mobile.
@tiandage just tried ObjectiveC in emulator - everything works, here is a code:
//
// ViewController.m
// CentrifugoObjectiveC
//
// Created by Alexander Emelin on 05/04/2017.
// Copyright © 2017 Alexander Emelin. All rights reserved.
//
#import "Centrifuge/Centrifuge.objc.h"
#import "ViewController.h"
@interface ViewController () <CentrifugeConnectHandler, CentrifugeDisconnectHandler, CentrifugeMessageHandler>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CentrifugeCredentials *creds = CentrifugeNewCredentials(@"42", @"1488055494", @"", @"24d0aa4d7c679e45e151d268044723d07211c6a9465d0e35ee35303d13c5eeff");
NSString *url = @"ws://localhost:8000/connection/websocket";
CentrifugeEventHandler *eventHandler = CentrifugeNewEventHandler();
[eventHandler onConnect:self];
[eventHandler onDisconnect:self];
CentrifugeClient *client = CentrifugeNew(url, creds, eventHandler, CentrifugeDefaultConfig());
NSError *error = nil;
if (![client connect:&error]) {
if (error != nil) {
NSLog(@"Error connect");
}
}
CentrifugeSubEventHandler *subEventHandler = CentrifugeNewSubEventHandler();
[subEventHandler onMessage:self];
error = nil;
[client subscribe:@"public:chat" events:subEventHandler error:&error];
if (error != nil) {
NSLog(@"Subscribe error");
}
}
- (void)onMessage:(CentrifugeSub *)p0 p1:(CentrifugeMessage *)p1 {
NSLog(@"Messsage received");
}
- (void)onConnect:(CentrifugeClient *)p0 p1:(CentrifugeConnectContext *)p1 {
NSLog(@"Connected");
}
- (void)onDisconnect:(CentrifugeClient *)p0 p1:(CentrifugeDisconnectContext *)p1 {
NSLog(@"Disconnected");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
I launched app, then sent several messages into channel public:chat
, then stopped Centrifugo. Here is an output in console:
2017-04-06 00:17:52.087 CentrifugoObjectiveC[29854:2009993] Connected
2017-04-06 00:18:08.551 CentrifugoObjectiveC[29854:2010049] Messsage received
2017-04-06 00:18:13.805 CentrifugoObjectiveC[29854:2010043] Messsage received
2017-04-06 00:18:14.304 CentrifugoObjectiveC[29854:2010049] Messsage received
2017-04-06 00:18:14.750 CentrifugoObjectiveC[29854:2010043] Messsage received
2017-04-06 00:18:21.970 CentrifugoObjectiveC[29854:2010055] Messsage received
2017-04-06 00:18:25.941 CentrifugoObjectiveC[29854:2010043] Messsage received
2017-04-06 00:20:40.881 CentrifugoObjectiveC[29854:2010043] Disconnected
I have no idea why it have not worked for you - maybe wrong header file? Here is screenshot to show you project structure (XCode Version 8.2.1):
I have not tested on real device yet, will write as soon as I do this.
from centrifuge-mobile.
Successfully installed on real device (iPhone 5c), but I had to disable bitcode in project options:
because I came across a similar issue described here golang/go#16966 - the fact that Go does not generate bitcode not a big problem at moment but it's hard to say what will be if Apple decides to do bitcode presence a requirement.
Actually there is a traceback in XCode (click on red exclamation mark after failed build) with more information about clang
exception you got - hopefully it's the same.
from centrifuge-mobile.
You really awesome! Thanks.
Real device is working fine, I think my XCode has some issues.
from centrifuge-mobile.
Hello @FZambia
I got why the project is not working on simulator well.
Did you get result on simulator or real device? I checked objective-c and swift project.
If I include centrifuge.framework and run CentrifugeNewCredentials(), the simulator is crashing app with below error.
Message from debugger: The LLDB RPC server has crashed. The crash log is located in ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log.
I have found about this error, but I can't get reason. perhaps is there one problem in the project?
Anyway, real device is working fine.
My XCode version is 8.3.
from centrifuge-mobile.
At moment I've checked both simulator and real devices - both working fine for me. I will update my XCode to 8.3 and try again.
from centrifuge-mobile.
@FZambia you have a 100% golang stack on server and mobile, so you can use golang quic instead of web sockets. Worth thinking from a code maintenance and perf aspect.
QUIC is really easy to use and is not kernel dependent and runs on mobile networks MUCH bette than websockets. The telecom provides run everything using UPD (whihc is the transport QUIC ride on).
See this for just how easy it can be !
https://github.com/simia-tech/netx/blob/master/PRESENTATION.slide
from centrifuge-mobile.
@joeblew99 thanks, I already thought about QUIC, maybe one day it will be in Centrifugo. We have little use on mobile at moment, so as soon as developers will integrate Centrifugo into mobile stack we can consider improvements in this area. Do you have experience with QUIC in mobile networks btw or maybe sth to read about this?
It's still important to have Websocket as stable and supported by browsers and native mobile language libraries transport.
from centrifuge-mobile.
Hello @FZambia
How is it running on XCode 8.3?
from centrifuge-mobile.
@tiandage already installed it but had no time to check - will do this later today
from centrifuge-mobile.
@tiandage the same code I posted above works on iPhone 5c installed via XCode 8.3 too
from centrifuge-mobile.
Thanks for your reply, I will check on my side again.
from centrifuge-mobile.
@tiandage any news, did you make it work for you?
from centrifuge-mobile.
no, @FZambia.
Simulator debugging is crashed when app is started, but simulator works, not crash.
So I am developing with actual device.
from centrifuge-mobile.
Just updated Android and iOS examples to use latest bindings so we are done for a moment.
@tiandage that crash is strange, the error states for looking at crash log and filing a bug in XCode - maybe this is what you should do.
from centrifuge-mobile.
Related Issues (19)
- Add event contexts
- app crashes HOT 2
- App crashes while trying to connect, happens only on ZenFone 4 (A450CG) Android 4.4.2 HOT 2
- Make a flutter GUI
- Subscription always null in PublishHandler HOT 7
- Track IOS bit code suport HOT 4
- The android emulator collapse ?? HOT 4
- Crash on Android Q emulator
- Warning in iOS HOT 2
- history publication does not received after subscribing on channel HOT 2
- Trust SSL socket x509 Problem in Android API 24 and lower
- Update to the latest ecosystem stack
- Client to server automatic periodic ping support HOT 1
- Can you add create token feature into the project. HOT 6
- Can you make multi credentials example? HOT 3
- get `permission denied` even publish is true HOT 3
- Crash on onPrivateSub callback for private channel subscription. HOT 2
- Getting timed out message from socket on subscribe or presence HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from centrifuge-mobile.