{"id":19299204,"url":"https://github.com/bmatcuk/bayeuxclient","last_synced_at":"2025-04-22T09:32:57.156Z","repository":{"id":16949959,"uuid":"19712127","full_name":"bmatcuk/BayeuxClient","owner":"bmatcuk","description":"A client implementation of the Bayeux protocol for OSX and iOS.","archived":false,"fork":false,"pushed_at":"2014-05-30T18:28:22.000Z","size":204,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-16T07:20:52.241Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bmatcuk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-12T19:26:32.000Z","updated_at":"2020-05-08T07:25:41.000Z","dependencies_parsed_at":"2022-08-21T02:50:10.442Z","dependency_job_id":null,"html_url":"https://github.com/bmatcuk/BayeuxClient","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmatcuk%2FBayeuxClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmatcuk%2FBayeuxClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmatcuk%2FBayeuxClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmatcuk%2FBayeuxClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bmatcuk","download_url":"https://codeload.github.com/bmatcuk/BayeuxClient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250215386,"owners_count":21393789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T23:10:31.701Z","updated_at":"2025-04-22T09:32:56.938Z","avatar_url":"https://github.com/bmatcuk.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BayeuxClient\n\nA client implementation of the Bayeux protocol for OSX and iOS using WebSockets for communication. Using this library, it's easy to connect to a [Faye](http://faye.jcoglan.com/) server, or, theoretically, any other server that implements the [Bayeux Protocol](http://svn.cometd.org/trunk/bayeux/bayeux.html) over a WebSocket.\n\n## Requirements\n\nBayeuxClient supports OSX versions 10.7 and higher, and iOS versions 5.0 and higher. It requires ARC support, in addition to a few other compiler tricks that are only available in Apple's LLVM Compiler v4.0+ (xcode 4.4+), or the open source LLVM Compiler v3.1+.\n\nBayeuxClient uses [SocketRocket](https://github.com/square/SocketRocket) to handle the WebSocket connection.\n\n## Installation\n\nThe recommended installation method is via CocoaPods. Add the following to your Podfile:\n\n```ruby\npod 'BayeuxClient', '~\u003e 0.1.1'\n```\n\nand then run `pod install`. This will download and install BayeuxClient and the SocketRocket dependency for your project.\n\n## Usage\n\nImport the `BayeuxClient.h` header file into your project and implement the `BayeuxClientDelegate` protocol:\n\n```objc\n// BayeuxTest.h\n#import \u003cFoundation/Foundation.h\u003e\n#import \"BayeuxClient.h\"\n\n@interface BayeuxTest : NSObject \u003cBayeuxClientDelegate\u003e\n\n@property BayeuxClient *client;\n\n@end\n\n\n// BayeuxTest.m\n#import \"BayeuxTest.h\"\n\n@implementation BayeuxTest\n\n- (void)connectToServer\n{\n  // initialize the client with the URL to the server... may also use http or https protocols.\n  self.client = [[BayeuxClient alloc] initWithURLString:@\"ws://domain.ext/path\"];\n\n  // subscribe to a channel - you can call subscribeToChannel: before or after you connect\n  [self.client subscribeToChannel:@\"/example/channel\"];\n\n  // assign myself to be the delegate (see BayeuxClientDelegate methods implemented below)\n  self.client.delegate = self;\n\n  // connect\n  [self.client connect];\n}\n\n#pragma mark - Required BayeuxClientDelegate methods\n\n- (void)bayeuxClient:(BayeuxClient *)client receivedMessage:(NSDictionary *)message fromChannel:(NSString *)channel\n{\n  NSLog(@\"A message was received - this is the only method you MUST implement from the BayeuxClientDelegate protocol.\");\n}\n\n#pragma mark - Optional BayeuxClientDelegate methods\n\n- (void)bayeuxClientDidConnect:(BayeuxClient *)client\n{\n  NSLog(@\"The client connected.\");\n}\n\n- (void)bayeuxClient:(BayeuxClient *)client subscribedToChannel:(NSString *)channel\n{\n  NSLog(@\"The client successfully connected to a channel.\");\n}\n\n- (void)bayeuxClient:(BayeuxClient *)client unsubscribedFromChannel:(NSString *)channel\n{\n  NSLog(@\"The client successfully unsubscribed from a channel.\");\n}\n\n- (void)bayeuxClient:(BayeuxClient *)client publishedMessageId:(NSString *)messageId toChannel:(NSString *)channel error:(NSError *)error\n{\n  NSLog(@\"The server has responded to a published message.\");\n}\n\n- (void)bayeuxClient:(BayeuxClient *)client failedToSubscribeToChannel:(NSString *)channel withError:(NSError *)error\n{\n  NSLog(@\"The client encountered an error while subscribing to a channel.\");\n}\n\n- (void)bayeuxClient:(BayeuxClient *)client failedToSerializeMessage:(id)message withError:(NSError *)error\n{\n  NSLog(@\"The client encountered an error while serializing a message.\");\n}\n\n- (void)bayeuxClient:(BayeuxClient *)client failedToDeserializeMessage:(id)message withError:(NSError *)error\n{\n  NSLog(@\"The client encountered an error while deserializing a message.\");\n}\n\n- (void)bayeuxClient:(BayeuxClient *)client failedWithError:(NSError *)error\n{\n  NSLog(@\"The client encountered some error which likely caused it to disconnect.\");\n}\n\n- (void)bayeuxClientDidDisconnect:(BayeuxClient *)client\n{\n  NSLog(@\"The client successfully disconnected gracefully, because you asked it to.\");\n}\n\n@end\n```\n\nWhen you are done, you may gracefully disconnect by using the `[self.client disconnect]` method. This method will send a disconnect message to the server, which will then reply and fire the `bayeuxClientDidDisconnect:` method on the delegate.\n\nOr you could do a hard disconnect by releasing the client (ie, `self.client = nil` which will cause ARC to release it). The server will realize you've disconnected after a minute or two. Obviously, a graceful disconnect is preferred.\n\n## Publishing\n\nOnce you have a client connected, you may publish messages to different channels using:\n\n```objc\nmessageId = [self.client publishMessage:@\"This is a test.\" toChannel:@\"/test/channel\"];\n```\n\nAccording to the Bayeux protocol documentation, the server is not required to respond. But, if it does, it will call `bayeuxClient:publishedMessageId:toChannel:error:` on your delegate. The `messageId` argument will match the value returned from `publishMessage:toChannel:` and the `error` argument will either be `nil`, meaning the publish was successful, or an `NSError` describing why the message could not be published.\n\n## Extensions\n\nIt is also possible to insert Bayeux Extensions. These extensions can be used to modify a message just before it is sent to the server, or just after they are received from the server and are typically used to implement some custom authentication schemes. An extension class implements the `BayeuxClientExtension` protocol:\n\n```objc\n// BayeuxTestExtension.h\n#import \u003cFoundation/Foundation.h\u003e\n#import \"BayeuxClient.h\"\n\n@interface BayeuxTestExtension : NSObject \u003cBayeuxClientExtension\u003e\n@end\n\n\n// BayeuxTestExtension.m\n#import \"BayeuxTestExtension.h\"\n\n@implement BayeuxTestExtension\n\n// implement one or both of these optional methods\n\n- (BOOL)bayeuxClient:(BayeuxClient *)client willSendMessage:(NSMutableDictionary *)message\n{\n  NSLog(@\"The client is just about to send a message to the server.\");\n  return YES;\n}\n\n- (BOOL)bayeuxClient:(BayeuxClient *)client willReceiveMessage:(NSMutableDictionary *)message\n{\n  NSLog(@\"The client just received a message from the server.\");\n  return YES;\n}\n\n@end\n```\n\nBoth methods return a `BOOL`. If you return `NO`, the message will be thrown away (ie, the message won't be sent to the server, or the received message won't be processed). The extension can be added with a:\n\n```objc\n[self.client addExtension:[[BayeuxTestExtension alloc] init]];\n```\n\nThe client maintains a strong reference to the extension.\n\n## Known Issues\n\n1. Message publishing hasn't been tested (I didn't need publishing for my project), but should work.\n2. There's no way to substitute a different transport protocol.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmatcuk%2Fbayeuxclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbmatcuk%2Fbayeuxclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmatcuk%2Fbayeuxclient/lists"}