|
| 1 | +# Setup and Authentication |
| 2 | + |
| 3 | +This guide shows how to migrate setup and authentication code from `stream-chat-java` to `stream-sdk-java`. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +**Before (stream-chat-java):** |
| 8 | + |
| 9 | +Maven: |
| 10 | +```xml |
| 11 | +<dependency> |
| 12 | + <groupId>io.getstream</groupId> |
| 13 | + <artifactId>stream-chat-java</artifactId> |
| 14 | + <version>LATEST</version> |
| 15 | +</dependency> |
| 16 | +``` |
| 17 | + |
| 18 | +Gradle: |
| 19 | +```groovy |
| 20 | +implementation 'io.getstream:stream-chat-java:LATEST' |
| 21 | +``` |
| 22 | + |
| 23 | +**After (stream-sdk-java):** |
| 24 | + |
| 25 | +Maven: |
| 26 | +```xml |
| 27 | +<dependency> |
| 28 | + <groupId>io.getstream</groupId> |
| 29 | + <artifactId>stream-sdk-java</artifactId> |
| 30 | + <version>LATEST</version> |
| 31 | +</dependency> |
| 32 | +``` |
| 33 | + |
| 34 | +Gradle: |
| 35 | +```groovy |
| 36 | +implementation 'io.getstream:stream-sdk-java:LATEST' |
| 37 | +``` |
| 38 | + |
| 39 | +**Key changes:** |
| 40 | +- Artifact ID changes from `stream-chat-java` to `stream-sdk-java` |
| 41 | + |
| 42 | +## Client Initialization |
| 43 | + |
| 44 | +**Before (stream-chat-java):** |
| 45 | + |
| 46 | +```java |
| 47 | +import io.getstream.chat.java.services.framework.DefaultClient; |
| 48 | +import java.util.Properties; |
| 49 | + |
| 50 | +Properties props = new Properties(); |
| 51 | +props.put("io.getstream.chat.apiKey", "your-api-key"); |
| 52 | +props.put("io.getstream.chat.apiSecret", "your-api-secret"); |
| 53 | + |
| 54 | +DefaultClient client = new DefaultClient(props); |
| 55 | +DefaultClient.setInstance(client); |
| 56 | +``` |
| 57 | + |
| 58 | +**After (stream-sdk-java):** |
| 59 | + |
| 60 | +```java |
| 61 | +import io.getstream.services.framework.StreamSDKClient; |
| 62 | + |
| 63 | +StreamSDKClient client = new StreamSDKClient("your-api-key", "your-api-secret"); |
| 64 | +``` |
| 65 | + |
| 66 | +**Key changes:** |
| 67 | +- `DefaultClient` with singleton pattern becomes `StreamSDKClient` with direct instantiation |
| 68 | +- Property names change from `io.getstream.chat.*` to `io.getstream.*` |
| 69 | +- Environment variables change from `STREAM_KEY`/`STREAM_SECRET` to `STREAM_API_KEY`/`STREAM_API_SECRET` |
| 70 | + |
| 71 | +## Client Initialization with Environment Variables |
| 72 | + |
| 73 | +**Before (stream-chat-java):** |
| 74 | + |
| 75 | +```java |
| 76 | +import io.getstream.chat.java.services.framework.DefaultClient; |
| 77 | + |
| 78 | +// Reads STREAM_KEY and STREAM_SECRET from environment |
| 79 | +DefaultClient client = new DefaultClient(); |
| 80 | +DefaultClient.setInstance(client); |
| 81 | +``` |
| 82 | + |
| 83 | +**After (stream-sdk-java):** |
| 84 | + |
| 85 | +```java |
| 86 | +import io.getstream.services.framework.StreamSDKClient; |
| 87 | + |
| 88 | +// Reads STREAM_API_KEY and STREAM_API_SECRET from environment |
| 89 | +StreamSDKClient client = new StreamSDKClient(); |
| 90 | +``` |
| 91 | + |
| 92 | +**Key changes:** |
| 93 | +- Environment variable names change: `STREAM_KEY` to `STREAM_API_KEY`, `STREAM_SECRET` to `STREAM_API_SECRET` |
| 94 | +- No singleton pattern required; use the client instance directly |
| 95 | + |
| 96 | +## Token Generation |
| 97 | + |
| 98 | +**Before (stream-chat-java):** |
| 99 | + |
| 100 | +```java |
| 101 | +import io.getstream.chat.java.models.User; |
| 102 | +import java.util.Date; |
| 103 | +import java.util.Calendar; |
| 104 | + |
| 105 | +// Token with no expiry |
| 106 | +String token = User.createToken("user-id", null, null); |
| 107 | + |
| 108 | +// Token with expiry |
| 109 | +Calendar cal = Calendar.getInstance(); |
| 110 | +cal.add(Calendar.HOUR, 24); |
| 111 | +String tokenWithExpiry = User.createToken("user-id", cal.getTime(), null); |
| 112 | +``` |
| 113 | + |
| 114 | +**After (stream-sdk-java):** |
| 115 | + |
| 116 | +```java |
| 117 | +import io.getstream.services.framework.StreamSDKClient; |
| 118 | + |
| 119 | +StreamSDKClient client = new StreamSDKClient("your-api-key", "your-api-secret"); |
| 120 | + |
| 121 | +// Token with no expiry |
| 122 | +String token = client.tokenBuilder().createToken("user-id"); |
| 123 | + |
| 124 | +// Token with expiry (validity in seconds) |
| 125 | +String tokenWithExpiry = client.tokenBuilder().createToken("user-id", 24 * 60 * 60); |
| 126 | +``` |
| 127 | + |
| 128 | +**Key changes:** |
| 129 | +- Token creation moves from static `User.createToken()` to `client.tokenBuilder().createToken()` |
| 130 | +- Expiry is specified as seconds (integer) instead of a `Date` object |
| 131 | +- No need to pass `issuedAt` separately |
| 132 | + |
| 133 | +## Sub-clients |
| 134 | + |
| 135 | +**Before (stream-chat-java):** |
| 136 | + |
| 137 | +```java |
| 138 | +import io.getstream.chat.java.models.User; |
| 139 | +import io.getstream.chat.java.models.Channel; |
| 140 | +import io.getstream.chat.java.models.Message; |
| 141 | + |
| 142 | +// All operations are static methods on model classes |
| 143 | +User.upsert().user(...).request(); |
| 144 | +Channel.getOrCreate("messaging", "general").request(); |
| 145 | +Message.send("messaging", "general").message(...).request(); |
| 146 | +``` |
| 147 | + |
| 148 | +**After (stream-sdk-java):** |
| 149 | + |
| 150 | +```java |
| 151 | +import io.getstream.services.framework.StreamSDKClient; |
| 152 | + |
| 153 | +StreamSDKClient client = new StreamSDKClient("your-api-key", "your-api-secret"); |
| 154 | + |
| 155 | +// Operations are on sub-client interfaces |
| 156 | +client.updateUsers(...).execute(); // Common (user operations) |
| 157 | +client.chat().getOrCreateChannel(...).execute(); // Chat |
| 158 | +client.chat().sendMessage(...).execute(); // Chat |
| 159 | +client.moderation().ban(...).execute(); // Moderation |
| 160 | +client.video().getOrCreateCall(...).execute(); // Video |
| 161 | +``` |
| 162 | + |
| 163 | +**Key changes:** |
| 164 | +- Static methods on model classes (`User.upsert()`, `Channel.getOrCreate()`) become instance methods on sub-clients (`client.chat()`, `client.moderation()`, `client.video()`) |
| 165 | +- User and device operations are on the root client (Common interface) |
| 166 | +- `.request()` becomes `.execute()` to run the API call |
0 commit comments