Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="section">
  <div class="container">
		<article class="message is-info">
			<div class="message-header">
				<p>Jellyfin SDK TypeScript Example</p>
			</div>
			<div class="message-body">
				This is a basic demo of the TypeScript SDK for Jellyfin. Additional information can be found on the <a href="https://github.com/thornbill/jellyfin-sdk-typescript">GitHub repository</a>.
			</div>
		</article>
		
		<div class="columns">
			
			<div class="column">
				<div class="box">
					<p class="title">Server Information</p>
					<div class="table-container">
						<table class="table is-fullwidth">
						<tbody>
							<tr>
								<th>Address</th>
								<td id="server-info-address">https://demo.jellyfin.org/stable</td>
							</tr>
							<tr>
								<th>Name</th>
								<td id="server-info-name">
									<i class="fas fa-spinner fa-pulse"></i>
								</td>
							</tr>
							<tr>
								<th>Version</th>
								<td id="server-info-version">
									<span class="icon">
										<i class="fas fa-spinner fa-pulse"></i>
									</span>
								</td>
							</tr>
						</tbody>
					</table>
					</div>
				</div>
			</div>
			
			<div class="column">
				<div class="box">
					<p class="title">Public Users</p>
					<div id="public-users" class="tags are-medium">
						<span class="icon">
							<i class="fas fa-spinner fa-pulse"></i>
						</span>
					</div>
				</div>
			</div>
			
		</div>
		<div class="columns is-centered">
			
			<div class="column is-half">
				<div class="box">
					<p class="title">User Login</p>
					<form id="user-login-form">
						<div class="field">
							<p class="control has-icons-left">
								<input id="user-login-username" class="input" type="text" placeholder="Username">
								<span class="icon is-small is-left">
									<i class="fas fa-user"></i>
								</span>
							</p>
						</div>
						<div class="field">
							<p class="control has-icons-left">
								<input id="user-login-password" class="input" type="password" placeholder="Password">
								<span class="icon is-small is-left">
									<i class="fas fa-lock"></i>
								</span>
							</p>
						</div>
						<div class="field">
							<p class="control">
								<button type="submit" id="user-login-submit" class="button is-success">
									Login
								</button>
							</p>
						</div>
					</form>
				</div>
			</div>
			
		</div>
		
	</div>
	
	<div id="user-libraries" class="container is-hidden">
		<p class="title">Libraries</p>
	</div>
	
</section>
              
            
!

CSS

              
                
              
            
!

JS

              
                import { Jellyfin } from "https://cdn.skypack.dev/@thornbill/jellyfin-sdk@0.2.0";
import { v4 as uuidv4 } from "https://cdn.skypack.dev/uuid@8.3.2";

// Change this to connect to a different server
const SERVER_URL = 'https://demo.jellyfin.org/stable';

// Update the Address displayed in the Server Information
document.addEventListener('DOMContentLoaded', async () => {
	document.getElementById('server-info-address').innerText = SERVER_URL;
});

const jellyfin = new Jellyfin({
	clientInfo: {
		name: 'CodePen SDK Test',
		version: '1.0.0'
	},
	deviceInfo: {
		// NOTE: This is not always accurate, but should be good enough for demo purposes
		name: window.navigator.appName,
		id: uuidv4()
	}
});

const api = jellyfin.createApi(SERVER_URL);

(async () => {
	const info = await api.systemApi.getPublicSystemInfo();
	// console.log('info', info.data);
	
	document.getElementById('server-info-name').innerText = info.data.ServerName;
	document.getElementById('server-info-version').innerText = info.data.Version;
	
	const publicUsers = await api.userApi.getPublicUsers();
	// console.log('users', publicUsers);
	const publicUsersElem = document.getElementById('public-users');
	if (publicUsers.data.length === 0) {
		publicUsersElem.innerText = 'No public users.';
	} else {
		// Remove the spinner
		publicUsersElem.innerText = '';
		// Add user tags
		publicUsers.data.forEach(user => {
			publicUsersElem.append(createUserTag(user.Name));
		});
	}
})();

// Handle user login form
document.addEventListener('DOMContentLoaded', () => {
	document.getElementById('user-login-form').addEventListener('submit', async e => {
		e.preventDefault();
		document.getElementById('user-login-submit').disabled = true;
		
		const username = document.getElementById('user-login-username').value;
		const password = document.getElementById('user-login-password').value;
		
		try {
			const user = await api.authenticateUserByName(username, password);
			// console.log(user.data);
			document.getElementById('user-login-form').innerText = `Logged in as user ${user.data.User.Name}`;
			
			fetchLibraries();
		} catch (err) {
			console.error(err);
			document.getElementById('user-login-submit').disabled = false;
		}
	});
});

async function fetchLibraries() {
	const libraries = await api.libraryApi.getMediaFolders();
	console.log('libraries', libraries.data);
	const librariesElem = document.getElementById('user-libraries');
	
	libraries.data.Items.forEach(library => {
		const libraryCard = createLibraryCard(library);
		librariesElem.append(libraryCard);
	});
	
	librariesElem.classList.remove('is-hidden');
}

// Helper function to create a user tag
function createUserTag(name: string) {
	const elem = document.createElement('span');
	elem.className = 'tag';
	elem.innerText = name;
	return elem;
}

// Helper function to create a library card
function createLibraryCard(library) {
	const title = document.createElement('p');
	title.className = 'title is-4';
	title.innerText = library.Name;
	
	const content = document.createElement('div');
	content.className = 'card-content';
	content.append(title);
	
	const card = document.createElement('div');
	card.className = 'card';
	card.append(content);
	return card;
}

              
            
!
999px

Console