public void Connect(String access_token) { IList <ClientTransport> transports = new List <ClientTransport>(); transports.Add(new LongPollingTransport(null)); client = new BayeuxClient(url, transports); // Subscribe and call 'Initialize' after successful login initListener = new InitializerListener(Initialize); client.getChannel(Channel_Fields.META_HANDSHAKE).addListener(initListener); // Subscribe to connect/disconnect-events connectionListener = new ConnectionListener(); client.getChannel(Channel_Fields.META_CONNECT).addListener(connectionListener); // Handshaking with oauth2 IDictionary <String, Object> handshakeAuth = new Dictionary <String, Object>(); handshakeAuth.Add("authType", "oauth2"); handshakeAuth.Add("oauth_token", access_token); IDictionary <String, Object> ext = new Dictionary <String, Object>(); ext.Add("ext", handshakeAuth); client.handshake(ext); client.handshake(handshakeAuth); }
public void Connect() { _client.RegisterListener(_channel, _listener); _client.handshake(); _client.waitFor(1000, new[] { State.CONNECTED }); //_client.getChannel(_channel).subscribe(_listener); }
public void Connect() { Console.WriteLine("Handshaking."); _bayeuxClient.handshake(); _bayeuxClient.waitFor(1000, new[] { BayeuxClient.State.CONNECTED }); Console.WriteLine("Connected."); _bayeuxClient.getChannel(channel).subscribe(new Listener()); Console.WriteLine("Waiting for data from server..."); }
public async Task StartAsync(CancellationToken cancellationToken) { appLifetime.ApplicationStarted.Register(OnStarted); appLifetime.ApplicationStopping.Register(OnStopping); appLifetime.ApplicationStopped.Register(OnStopped); logger.LogInformation("SalesforceStreamingService.StartAsync has been called."); logger.LogInformation("Authenticating with Salesforce..."); var authToken = await salesforceClient.GetToken(); logger.LogInformation("Enabling Bayeux protocol..."); var options = new Dictionary <String, Object> { { ClientTransport.TIMEOUT_OPTION, readTimeOut } }; var transport = new LongPollingTransport(options); // add the needed auth headers var headers = new NameValueCollection(); headers.Add("Authorization", "OAuth " + authToken.AccessToken); transport.AddHeaders(headers); // only need the scheme and host, strip out the rest var serverUri = new Uri(authToken.InstanceUrl); String endpoint = String.Format("{0}://{1}{2}", serverUri.Scheme, serverUri.Host, sfOptions.StreamEndpoint); bayeuxClient = new BayeuxClient(endpoint, new[] { transport }); logger.LogInformation("Handshaking with Salesforce stream..."); bayeuxClient.handshake(); bayeuxClient.waitFor(1000, new[] { BayeuxClient.State.CONNECTED }); logger.LogInformation("Connected to Salesforce stream..."); bayeuxClient.getChannel(sfOptions.Channel).subscribe(new Listener(logger)); logger.LogInformation("Waiting for data from server..."); }