صكّ التوكن من الباكإند
الطريقة المعتمدة لتوليد توكن الدخول — وحقلٌ واحد لو سقط، تتعطّل الجلسة الواحدة في صمت.
الصكّ بمفتاح التطبيق العلني اتقفل
صكّ توكن بهوية مستخدم بمفتاح التطبيق (App Key) العلني اتقفل. أي طلب بيعمل كده بيرجع 403 ومعاه code: appkey_identity_mint_disabled. اصكّ من الباكإند بتاعك بسرّ السيرفر (X-App-Id + X-App-Secret)، وخد هوية المستخدم من جلسته المسجّل دخوله عندك.
بعض المشاريع القديمة لسه عندها استثناء مؤقت. المشاريع الجديدة مش بتاخده، والمسار المدعوم هو توكن موقّع من السيرفر (server-signed token).
ليه من الباكإند؟
السرّ بتاعك ما ينزلش في التطبيق أبدًا. أي مفتاح يتشحن مع الـAPK ينفع يتفكّ ويُنتحل بيه أي مستخدم.
مرّر حقائق الجهاز
سيرفرك ما بيشوفش الجهاز. التطبيق هو اللي يبعتها لسيرفرك، وسيرفرك يمرّرها لنا في نفس الطلب.
السقوط صامت
من غير device_id التوكن بينجح برضه، بس المحرّك مش بيعرف يفرّق بين إعادة اتصال وتبديل جهاز: الجلسة الأحدث بتحل محل القديمة، لكن الجهاز القديم مش بيتشال من الغرفة ومفيش مهلة تبديل. مفيش خطأ بيظهر فمحدّش بياخد باله.
اللي لازم الباكإند يمرّره
الباكإند بتاعك واقف بين المحرّك والموبايل، فالحقول دي مش بتوصلنا إلا لو حطّيتها في جسم طلب التوكن.
| الحقل | إيه هو | لو سبته |
|---|---|---|
device_id | A stable id per app install. It lets the engine tell a reconnect from a takeover. | The newest session still replaces the old one, but the old device is not removed from the room and there is no 10-second takeover cooldown. The token rate-limit key falls back to your server's IP. Not rejected today; strongly recommended. |
client_ip | The end user's public IP, sent in the request body, only on a Server-Secret request. | Sets the participant's country and, with geo-routing, the nearest media node. A missing, private or malformed value is ignored silently and your server's address is used. Never rely on X-Forwarded-For. |
device_model, os, os_version, app_version | Optional device facts the engine cannot see through your backend. | Nothing breaks; per-handset quality analysis simply has less to work with. |
حقول طلب التوكن
POST إلى /api/v1/token بسرّ السيرفر في الترويسة.
| الحقل | المستوى | المعنى |
|---|---|---|
user_idstring | مطلوب | Who the token is for. Your own user id. (Previously `identity` — still accepted.) |
room_idstring | مطلوب | Which room they are joining. (Previously `room_name` — still accepted.) |
device_idstring | موصى به | A stable id for the PHYSICAL DEVICE (max 200 chars) — not the user, and not the session. With it, a second device taking over inside 10 seconds is refused with 429 (session_cooldown) and the same device reconnecting reuses its session. Without it the request still succeeds, but the engine cannot tell a reconnect from a takeover: the newest session replaces the old one (the old session's user_token then gets 401 session_superseded), yet the old device is not removed from the room and there is no cooldown. The token rate-limit key also falls back to the caller's IP — from a backend, one address for all its users. Not required today; strongly recommended. |
client_ipstring | موصى به | The END USER's public IP address, forwarded from your server. We see the address of whoever calls this endpoint — which, once you mint from your backend, is your data centre for every one of your users. That address decides the country we stamp on the participant AND which media node a new room opens on, so leaving it out can place a room as if all your users sat in your own data centre instead of where they are. Only honoured on a server-authenticated request (never app_key, where the handset's own address is already correct), and a private or malformed value is ignored rather than rejected. |
device_modelstring | موصى به | e.g. SM-A175F. Feeds per-handset quality analysis — which models have audio or video trouble. |
osstring | موصى به | android | ios. |
os_versionstring | موصى به | e.g. 14. |
app_versionstring | موصى به | Your app's version, so a regression can be traced to a release. |
namestring | اختياري | The participant's display name, shown to other participants. |
display_namestring | اختياري | The ROOM's display name, used when the room is created. It does not name the participant — use name for that. |
rolestring | اختياري | host | admin | guest | audience | visitor (default audience). A request, not a grant: an admin claim from a client is ignored (you get audience). Appoint moderators from your backend with PUT /rooms/:room/participants/:id/role. |
typestring | اختياري | audio_room | live_stream. Legacy kits send `service` (+ `kind`) instead and the type is derived. |
على سيرفرك
السرّ هنا وبس. الحقول المعلّمة بالأحمر جاية من التطبيق — سيرفرك ما يقدرش يعرفها لوحده.
// Your backend — the app never sees the server secret.
const res = await fetch("https://udt-stream.com/api/v1/token", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-App-Id": process.env.UTD_APP_ID,
"X-App-Secret": process.env.UTD_SERVER_SECRET, // never ship this in the app
},
body: JSON.stringify({
// The user comes from YOUR logged-in session, never from the request body the app sends.
user_id: session.userId,
room_id: roomId,
type: "audio_room", // or "live_stream"
// 🔴 The user's own public IP, not your server's. Without it every user of yours
// is placed and geo-located as if they sat in your data centre.
// Behind ONE trusted proxy set app.set("trust proxy", 1) and use req.ip. Do not read
// X-Forwarded-For yourself: a client can send its own value.
client_ip: req.ip,
// 🔴 Forwarded FROM THE APP. Your server cannot know these on its own,
// and without device_id the engine cannot tell a reconnect from a takeover.
device_id: body.device_id,
device_model: body.device_model,
os: body.os,
os_version: body.os_version,
app_version: body.app_version,
}),
});
const { token, url, user_token, ws_url } = await res.json(); // hand these to the appالأسماء القديمة `identity` و`room_name` لسه شغالة بنفس المعنى.
في تطبيقك
ابعت حقائق الجهاز لسيرفرك أنت، وهو يمرّرها. معرّف الجهاز لازم يفضل ثابت بعد إعادة تشغيل التطبيق.
// Your app — send the device facts to YOUR backend, which forwards them to us.
final deviceId = await MyDeviceIdentity.stableId(); // persisted, survives app restarts
await myApi.post("/rooms/$roomId/token", body: {
"device_id": deviceId,
"device_model": deviceInfo.model,
"os": Platform.isAndroid ? "android" : "ios",
"os_version": deviceInfo.version,
"app_version": packageInfo.version,
});أكواد الرفض (403)
كل رفض بيحمل code. اقرأ الكود — ما تعرضش «اتشالت من الغرفة» إلا على الأول منهم.
| الكود | المعنى | اعمل إيه |
|---|---|---|
user_banned | This user is banned from this room. | Show them they were removed. This is the ONLY code that should produce that message. |
room_type_disabled | The project does not have this room type enabled. | A configuration problem, not a user problem. Never show a removal notice. |
streaming_disabled | The streaming service is not enabled for this project. | Same — configuration, not the user. |
appkey_identity_mint_disabled | You tried to mint an identity-bearing token with the publishable app_key. | Mint from your backend with your Server Secret (X-App-Id + X-App-Secret) instead, taking the user's identity from your own logged-in session. This is the path this page describes. Some older projects still carry a temporary exception; new projects do not get it. |
أكواد تانية هتقابلها
اتصرّف على حالة HTTP وحقل code، مش على نص الرسالة.
| الحالة | الكود | المعنى |
|---|---|---|
| 401 | token_expired | The user token's lifetime ended. Mint a new one. |
| 401 | session_superseded | A newer session exists for the same user. Do not retry with this token. |
| 429 | token_rate_limited | 30 token requests a minute per project + user + device. Back off with jitter. |
| 429 | identity_rate_limited | Token requests for one user_id across all its devices. Back off. |
| 429 | session_cooldown | A different device tried to take over a session set up in the last 10 seconds. Wait a few seconds. |
| 429 | project_rate_limited / user_rate_limited | REST budget of the whole project / of one user. Back off. |
أخطاء التوكن؟ شوف حقل code في الرد والجداول اللي فوق. تواصل مع الدعم ومعاك app_id ووقت الطلب.
إصدارات الكِتات
اعتبارًا من 2026-11-29. أول إصدار منشور من كل كِت بيبعت معرّف الجهاز، وأول إصدار بيقبل توكن مصكوك من الباكإند بتاعك (tokenProvider). الأحدث هو الموصى به: راجع pub.dev لآخر إصدار.
| الحزمة | يبعت device_id | tokenProvider |
|---|---|---|
utd_live_room_kit | 1.0.0 | 1.2.0 |
utd_audio_room_kit | 1.1.0 | 1.3.0 |
مع tokenProvider الباكإند هو اللي بيصكّ التوكن، فـdevice_id مش بيوصل للمحرّك إلا لو الباكإند مرّره في طلب التوكن.
أحدث الإصدارات
| الحزمة | أحدث إصدار |
|---|---|
utd_stream_sdk | 0.8.0 |
utd_audio_room_kit | 4.2.1 |
utd_live_room_kit | 4.0.4 |
utd_media_client | 2.12.1 |
utd_signaling | 0.4.0 |
utd_calls_kit | 0.10.0 |
utd_chat_kit | 0.10.0 |
utd_video_effects_kit | 0.16.2 |
أوضاع المصادقة
المحرّك بيسجّل وضع المصادقة على كل دخول، فتقدر تتأكد أنت على أي مسار فعلاً.
secret / signature / bearerYour backend, authenticated with your server secret. The recommended path.
app_keyThe device, using the publishable app key. Closed by default; some older projects still carry a temporary exception, new projects do not get it.